Message Boards Message Boards

0 Replies
3 Total Likes
View groups...
Share this post:

Simple Pendulum Experiment using Mathematica's Image Processing Capability

Posted 11 years ago
We can use the pin notebook to capture the position and time in space of the pendulum.
pics = {}; Pause[10]; Do[AppendTo[pics, {AbsoluteTime[], CurrentImage[]}];
Pause[0.1], {i, 120}];

All we need is the section of interest of the frames for the experiment, so using the ImageTrim functionality we can just keep the part of the frame that captures the movement of the golf ball.Using image processing functions, we can reduce the image to the components that will be key to obtaining the centroid of the ball.
pics2 = ImageTrim[pics[[#, 2]], {{50., 0.}, {305., 85.}}] & /@
Manipulate[DeleteSmallComponents@ChanVeseBinarize[Dilation[Blur[pics2[[i]], 5.5], 2],"TargetColor" -> Yellow], {i, 1, Length@pics, 1}]

Show[pics2[[i]], Graphics[{Red, PointSize[Large], Point[Mean@ComponentMeasurements[DeleteSmallComponents@ChanVeseBinarize[Dilation[Blur[pics2[[i]], 5.5], 2],"TargetColor" -> Yellow], "Centroid"][[All, 2]]]}]], {i, 1,Length@pics, 1}]

times will be used to hold the amounts of seconds that have passed sinced we captured the first frame, positions will be holds the centroid location in pixels.
firstFrame = pics[[1, 1]];
times =
pics[[All, 1]] - firstFrame;
positions = Mean@ComponentMeasurements[DeleteSmallComponents@ChanVeseBinarize[pics2[[#]], "TargetColor" -> Yellow], "Centroid"][[All, 2]] & /@ Range[Length@pics];
Let's graph the horizontal position of the ball based on the lapsed time.
ListPlot[Transpose[{times, positions[[All, 1]]}], Joined -> True,

AxesLabel -> {"Seconds", "Horizontal Distance\n(pxls)"}]

Clearly a periodic function. There are 5 peaks between 0 and 6.3 seconds (2 Pi). The period of the function is around 5.
Let find an equation that fits the calculation.
sol = FindFit[Transpose[{times, positions[[All, 1]]}],

  a Cos[b x + c] + d, {{a, 100}, {b, 5}, c, d}, x, MaxIterations -> 1000]
(*{a -> 99.7899, b -> 5.19945, c -> -0.239585, d -> 127.879}*)
Show[ListPlot[Transpose[{times, positions[[All, 1]]}],
AxesLabel -> {"Seconds", "Horizontal Distance\n(pxls)"},
PlotStyle -> Red, Joined -> False],
Plot[a Cos[b x + c] + d /. sol, {x, 0, 17}]]

The equation that fits the bill and the period of the function are:
(a Cos[b x + c] + d) /. sol
(*127.879 + 99.7899 Cos[0.239585 - 5.19945 x]*)
T = 2 \[Pi]/b /. sol

Wikipedia has all the details on the modelling of the simple pendulum experiment. which shows that the equation that relates the period with the length of the pendulum is given by.

Solve[Period == 2 \[Pi] Sqrt[L/g], g]
(*{{g -> (4 L \[Pi]^2)/Period^2}}*)

Our measurement of the length was as follows.

If we plug the numbers in then we get.
g = 4 \[Pi]^2  0.364/T^2

Checking WolframAlpha

which is 0.5% error.
POSTED BY: Diego Zviovich
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract