📄 fig1_4.m
字号:
% animation for Figure 1.4
%
% BM Dec97
clear
clf
colordef(1,'black')
% decaying or growing phasor
M = 128; % no of samples
step = 360/M; % angular step (degrees)
f = 4; % fequency (Hz)
dt = 1/M; % time step (seconds)
ph = 0; % initial phase shift
t = 0:dt:1; % time axis
A = 1.0; % initial amplitude
sign = -1; % decaying (-1) or growing (+1)
tau = 100; % time constant (seconds)
x = A*exp(sign*t/tau) .* exp( j*2*pi*f*t - j*ph/180*pi );
xr = real(x);
xi = imag(x);
xmax = max([xr xi ])*1.1;
tmin = min(t);
tmax = max(t);
% set up phasor plot
axh1 = subplot(1,2,1);
l1(1)= line('Xdata',xr(1),'Ydata',xi(1));
set(l1(1),'Marker','o');
set(l1(1),'Color','w');
set(l1(1),'EraseMode','xor');
xx = [ 0 xr(1) ];
yy = [ 0 xi(1) ];
l1(2)= line('Xdata',xx,'Ydata',yy);
set(l1(2),'LineStyle','-');
set(l1(2),'Color','y');
set(l1(2),'EraseMode','xor');
%axis( [-1.1 1.1 -1.1 1.1 ]);
axis( [ -xmax xmax -xmax xmax ]);
axis('square')
v1 = axis;
xx = [ xr(1) v1(2) ];
yy = [ xi(1) xi(1) ];
l1(3)= line('Xdata',xx,'Ydata',yy);
set(l1(3),'LineStyle','-');
set(l1(3),'Color','b');
set(l1(3),'EraseMode','xor');
xx = [ xr(1) xr(1) ];
yy = [ xi(1) xi(1) ];
l1(4)= line('Xdata',xx,'Ydata',yy);
set(l1(4),'LineStyle','-');
set(l1(4),'Color','r');
set(l1(4),'EraseMode','none');
title('phasor');
xlabel('real part');
ylabel('imag part');
hold on
% set up signal plot
axh2 = subplot(1,2,2);
l2(1) = line('Xdata',t(1),'Ydata',xi(1));
set(l2(1),'Marker','o');
set(l2(1),'Color','w');
set(l2(1),'EraseMode','xor');
tt = [ t(1) t(1) ];
yy = [ xi(1) xi(1) ];
l2(2) = line('Xdata',tt,'Ydata',yy);
set(l2(2),'LineStyle','-');
set(l2(2),'Color','y');
set(l2(2),'EraseMode','none');
%axis( [ 0 1 -1.1 1.1 ]);
axis( [ tmin tmax -xmax xmax ] );
v2 = axis;
xx = [ t(1) v2(1) ];
yy = [ xi(1) xi(1) ];
l2(3)= line('Xdata',xx,'Ydata',yy);
set(l2(3),'LineStyle','-');
set(l2(3),'Color','b');
set(l2(3),'EraseMode','xor');
axis('square')
xlabel('time');
ylabel('imag part');
title('signal');
hold on
fprintf(1,'Figure 1.4: press return to start\n')
pause
for ii =1:M+1,
% timer
t0 = clock;
te = 0;
% phasor plot
subplot(1,2,1)
set(l1(1),'Xdata',xr(ii),'Ydata',xi(ii));
xx = [ 0 xr(ii) ];
yy = [ 0 xi(ii) ];
set(l1(2),'Xdata',xx,'Ydata',yy);
xx = [ xr(ii) v1(2) ];
yy = [ xi(ii) xi(ii) ];
set(l1(3),'Xdata',xx,'Ydata',yy);
if ii==1,
xx = [ xr(ii) xr(ii) ];
yy = [ xi(ii) xi(ii) ];
else
xx = xr(ii-1:ii);
yy = xi(ii-1:ii);
end
set(l1(4),'Xdata',xx,'Ydata',yy);
% signal plot
subplot(1,2,2)
set(l2(1),'Xdata',t(ii),'Ydata',xi(ii));
if ii==1,
tt = [ t(1) t(1) ];
yy = [ xi(1) xi(1) ];
else
tt = t(ii-1:ii);
yy = xi(ii-1:ii);
end;
set(l2(2),'Xdata',tt,'Ydata',yy);
xx = [ t(ii) v2(1) ];
yy = [ xi(ii) xi(ii) ];
set(l2(3),'Xdata',xx,'Ydata',yy);
% constant frame rate
while te < 0.2
te = (clock - t0) * [0 0 86400 3600 60 1]';
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -