forked from burakbayramli/books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sintwavemov.m
29 lines (25 loc) · 942 Bytes
/
sintwavemov.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function m = sintwavemov(k,w,z,l,n)
% m = sintwavemov(k,w,z,l,n) Build a movie of sin travelling wave interference
% For a pair of opposite-moving sinusoidal travelling waves of
% temporal frequency w and spatial frequency k where the ratio
% of forward to backward waves at *l* is z (complex), make n
% plots of l points of the wave, both forward, backward, sum and
% difference. Record each plot in a movie, returned in m.
% 2001-02-02 [email protected] e6820 acous
fwd = zeros(1,l);
bck = zeros(1,l);
% Since we know travelling waves are just the sinusoids, rewrite them
% from scratch every time
m = moviein(n);
x = 0:l;
modz = abs(z);
phaz = angle(z) - 2*k*l;
for t = 0:(n-1);
fwd = cos(k*x - w*t);
bck = modz*cos(k*x + w*t + phaz);
plot(x, fwd, 'g--', x, bck, 'c--', x, fwd+bck, 'b', x, fwd-bck, 'r');
grid
title(['t = ', num2str(t)]);
axis([0 l -(1+modz) (1+modz)]);
m(:,t+1) = getframe;
end