Seth on Simulink

September 30th, 2008

Challenge: Metronome Synchronization

My good friend Doug, formerly of Pick of the Week fame, sent me an e-mail last week with the subject “Model this.”  The message contained nothing more than a link to a video.  Doug started a new video blog, and for this reason, I have decided to incorporate some video into this post.

What is happening?

The video shows five metronomes sitting on a board, and when they start, the timing is initially out of phase.  The board is placed on top of empty soda cans on their side, allowing the board to slide back and forth with very little friction.  The board couples the dynamics of the metronomes and, in time, their phases synchronize.  The synchronization of periodic systems is a fascinating concept, and fun to watch.  This effect was first observed by Huygens in the 17th century. You can find many related videos on YouTube, like this presentation of metronomes with different frequencies and this experiment with five metronomes.

The Challenge

In honor of Doug’s latest venture, here is a challenge:
Can you model this in Simulink?
You can take many different approaches in modeling this system.  I hope to see implementations using base blocks as well as SimMechanics.

Hints

To get you started, I have built a simple pendulum and cart model.  Download:

metronome.mdl
metronomeAnimation.m

Simulink model of a metronome

The solution I have explored only shows synchronization when the pendulum angle of deflection is small.  I recommend initial deflections of around pi/8 or smaller for the angle of the pendulum.

I have even built a “metronome scope” which will display a crude pendulum given the angle of deflection in radians.

Animation of an inverted pendulum S-function

How to submit a solution

Post your solution by October 15th to the File Exchange with the keyword metronome.  I will give out some prizes like T-shirts and other stuff I find in the MATLAB Central prize closet.  Please post a comment if you have submitted a model to the file exchange, or if you have questions about the challenge.  Good luck!

2 Responses to “Challenge: Metronome Synchronization”

  1. Guy Rouleau replied on :

    Hello Seth,

    That was a good challenge.

    At first I thought this challenge was going to be easy, I assembled a SimMechanics model, clicked play… but the pendulums are not synchronizing, as mentioned by Parasar in his post.

    Then I thought, let’s try with Simulink. I implemented in a vector form the equations provided and then face two choices:

    - By default, the coupling of the equations results in an algebraic loop. I never like to have an algebraic loop in a model, but tried to let the solver resolving the algebraic loop. The results are similar to the ones from Simemchanics. It looks like the Simulink algebraic loop solver is doing a job similar to the SimMechanics solver. I cannot explain the exact reason, but my guess is that the algebraic loop solver removes the non-linearity that makes the pendulums synchronize in real life.

    - My standard way to remove algebraic loops is to introduce a delay in the feedback path. In that case, the pendulums synchronize but the model becomes instable. The maximum sample time of the Simulink solver must be adjusted to an appropriate value to obtain an acceptable tradeoff between synchronization and stability.

    I implemented the model using a vector approach. It allows easily changing the number of pendulums and modifying the algorithm.

    I hope you will provide explanations on why no one has been able to obtain the synchronization using SimMechanics or with an algebraic loop.

    Guy

  2. Thomas Steffen replied on :

    Guy:

    > I hope you will provide explanations on why no one has been able to obtain the synchronization using SimMechanics or with an algebraic loop.

    Synchronisation cannot happen in a linear framework, that is a long known fact from electrical oscillators. Coupling them leads to several modes with slightly different resonance frequencies (”off tune”), and increasing the coupling separates the frequencies further.

    So the key is nonlinearity. My guess is that it is the driving force, but I did not study other options.

    How you model it should have no influence: SimMechanics, SimScape or plain Simulink, they all show the same behaviour.

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Seth Popinchalk is an Application Engineer for The MathWorks. He writes here about Simulink and other MathWorks tools used in Model-Based Design.
  • wei: @Ashish, I agree with your observation on compiler optimization but fail to see why Han’s code would be...
  • Ashish Sadanandan: Han, Sorry for butting in with a reply, but the modification to the for-loop you’ve...
  • arun kumar: dear seth i have been involved in developing and simulating asynchronous systems for my VLSI lab. in...
  • Han Geerligs: Hi Aarti, thanks for providing the example! I was just wondering why the lines model_YDim = model_XDim;...
  • Seth: @Han - Aarti’s response is in a post titled Generated Code for Variable Size Signals.
  • garla: what is advantage of exporting the bus object with the format as “cell” and “object” ....
  • J.r: @ Guy - Example sent to your account. Thank you.
  • Guy: @ J.r - The ability for atomic subsystems and Model Reference to remove the “fake algebraic loop”...
  • J.r: Sorry to hit an old thread, but this seems like the best place to solicit help on this topic. Is there supposed...
  • Bindu: please tell me how can i get the sampling time used in simulation

These postings are the author's and don't necessarily represent the opinions of The MathWorks.