phasordemo.m
1.41 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
% Phasor demo
%
% Tobin Fricke <tobin.fricke@ligo.org> 2011-06-08
% modulation depth
%m = pi/4;
m = 1;
% vector of (normalized) frequencies to include
%freqs = [0 1 -1 2 -2 3 -3 4 -4];
freqs = [0 1 -1 2 -2];
% initial amplitudes of the phasors
amp = besselj(freqs, m);
set(0, 'defaultlinelinewidth', 5);
% Set up the axes
cla reset;
axis equal;
xlim([-1 1.5]);
ylim([-1 1]);
% Draw the unit circle
rectangle('Position', [-1 -1 2 2], 'Curvature', [1 1])
% make some lines
L = [];
L(1) = line([0], [0]);
L(2) = line([0], [0], 'color', 'red');
save_to_disk = 0;
% how many frames to render?
if save_to_disk,
n_frames = 200;
else
n_frames = inf;
end
% how much the 1-Omega should rotate in one frame of the animation?
if isinf(n_frames)
dphi = m/20;
else
dphi = (2*pi)/(n_frames + 1);
end
frameno = 0;
ret_amp = [];
while (frameno < n_frames),
frameno = frameno + 1;
% Add up the phasors cumulatively
seg = cumsum([0 amp]);
% Draw both the collection of phasors and the resultant
set(L(1), 'xdata', real(seg), 'ydata', imag(seg));
set(L(2), 'xdata', real(seg([1,end])), 'ydata', imag(seg([1,end])));
ret_amp = [ret_amp, abs(seg([end]))];
% Update the display
drawnow;
if (save_to_disk),
print('-dpng', '-r72', sprintf('pm%03d.png', frameno));
else
pause(0.02);
end
% Advance the phasors for the next frame
amp = amp .* exp(1i * dphi * freqs);
end