How do I animate a block (say an image) to vibrate at a particular frequency?

3 views (last 30 days)
I want to show how a spring vibrates at its natural frequency. Without using any other models (quarter car or other response based models), I want to show the animation of a spring at a particular frequency, just as a vertical motion. Can I use MATLAB to do this?
For example, assume a car has a front natural frequency of 1.5 Hz and a rear natural frequency of 1.7 Hz. I want to show two springs going up and down at these frequencies so that the user gets an idea of the system. Please let me know if I can write a code for this.

Answers (1)

Jan
Jan on 20 Oct 2016
Yes, you can write code for it. Do you want to obtain the vibration trajectories by a simulation or do you just want an animation?
  4 Comments
Jan
Jan on 26 Oct 2016
Compute the positions for a time vector in the wanted resolution. Most likely some simple sin() commands will do this.
Open a figure, then an axes. Create the graphical objects you want in 2D or 3D, e.g. by surf, line, cyclinder etc. Then write a loop and modify the 'XData', 'YData', 'ZData' properties of the created object accoring to the calculated positions.
Search in teh net for examples: Look for "Matlab animation".
Harikrishna Devarajan
Harikrishna Devarajan on 2 Nov 2016
Edited: Harikrishna Devarajan on 5 Nov 2016
Hi!
I now have a code to generate a helical coil spring.
time = 0:pi/50:25*pi; % Time array
radius = 2; % Radius of the coil spring
height = 2; % Height of the coil spring
x = sin(time) * radius; % Compute x and y
y = cos(time) * radius;
z = height/(2*pi) * time; %Compute z which will be used later to animate
plot3(x,y,z);
And the plot looks like this:
Let's assume an amplitude of 1, with the frequency at say 1.5 Hz.
To compute the positions of the time vector and to continuously update and redraw the plot, I have written a small piece of code.
h = plot3(x,y,z);
while 1
t=0;
for t= 0:1000
zadd = sind(1.5*2*pi*t);
znew = z + zadd;
set(h,'ZData',znew)
t = t + 1;
drawnow
pause(0.1);
end
end
I am able to animate the graph, but I am not sure about the following.
1. Is it vibrating at the right frequency?
2. Have I factored in the resolution here? (I wrote the code based on a few help files)
3. Can I stretch/compress the spring a bit instead of bouncing it up and down?
I would love to hear your views on this. Thanks.

Sign in to comment.

Categories

Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!