This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/Matlab/sig_sys/lab2_ref.m

129 lines
2.2 KiB
Matlab

figure(1);
syms t n T;
f1=4/T*t+1;
f2=-4/T*t+1;
a0=(int(f1,-T/2,0)+int(f2,0,T/2))/T;
ya1=f1*cos(n*2*pi/T*t);
ya2=f2*cos(n*2*pi/T*t);
yb1=f1*sin(n*2*pi/T*t);
yb2=f2*sin(n*2*pi/T*t);
an=(int(ya1,-T/2,0)+int(ya2,0,T/2))/T*2;
bn=(int(yb1,-T/2,0)+int(yb2,0,T/2))/T*2;
cn=(an^2+bn^2)^(1/2);
n=1:10;
cn1=subs(cn);
cn2=[0,cn1];
h=stem([0,n],cn2);
plot([0,n],cn2)
title('幅度频谱')
xlabel('\omega');
ylabel('c_n');
figure(2);
syms t;
ft=exp(-3*t)*heaviside(t);
subplot(3,1,1);
ezplot(ft);
title('时域波形');
xlabel('t');
ylabel('f(t)');
F=fourier(ft);
w=-3:0.01:3;
F1=subs(F);
subplot(3,1,2);
plot(w,abs(F1));
title('幅度谱');
xlabel('角频率');
ylabel('幅度');
subplot(3,1,3);
plot(w,angle(F1)*pi/180);
title('相位谱');
xlabel('角频率');
ylabel('相位');
figure(3);
syms t w;
tao=3;
F=tao*sin(tao*w/2)/(tao*w/2);
ft=ifourier(F,t);
subplot(2,2,1);
ezplot(ft,[-2,2]);
title('时域波形');
xlabel('t');
ylabel('f(t)');
subplot(2,2,2);
ezplot(F,[-10,10]);
title('频谱图');
xlabel('\omega');
subplot(2,2,3);
ezplot(abs(F),[-10,10]);
title('幅度谱');
xlabel('角频率');
ylabel('幅度');
subplot(2,2,4);
ezplot(angle(F),[-10,10]);
title('相位谱');
xlabel('\omega');
ylabel('相位');
figure(4);
syms w t;
F=(1-j*w)/(1+j*w);
w=-5:0.01:5;
F1=subs(F);
subplot(2,1,1);
plot(w,abs(F1));
title('幅度谱');
xlabel('角频率(\omega)');
ylabel('幅度|H(j\omega)|');
subplot(2,1,2);
plot(w,angle(F1)*pi/180);
xlabel('角频率(\omega)');
ylabel('相位\phi');
figure(5);
syms w t;
Hw=(1-j*w)/(1+j*w);
ht=ifourier(Hw,t);
subplot(2,2,1);
ezplot(ht);
title('冲激响应');
xlabel('t');
ylabel('h(t)');
ft=exp(-2*t)*heaviside(t);
subplot(2,2,2);
ezplot(ft);
title('输入信号');
xlabel('t');
ylabel('f(t)');grid on;
F=fourier(ft);
Yw=F*Hw;
yt=ifourier(Yw,t);
subplot(2,2,3);
ezplot(yt,[-1,4,-1,0.5]);
title('零状态响应');
xlabel('t');
ylabel('y_f(t)');
figure(6);
syms w t;
ft=exp(-2*t)*heaviside(t);
subplot(1,2,1);
ezplot(ft);
title('F');
xlabel('t');
ylabel('f(t)');grid on;
F=fourier(ft);
Yw=F*Hw;
yt=ifourier(Yw,t);
subplot(1,2,2);
ezplot(yt,[-1,4,-1,0.5]);
title('零状态响应');
xlabel('t');
ylabel('y_f(t)');