f1=100;
f2=200;
f3=300;
t=0:0.001:2;
figure(1);
a1=input(‘输入y1的幅度:’);
a2=input(‘输入y2的幅度:’);
a3=input(‘输入y3的幅度:’)
y1=a1sin(2*pi*f1*t);
Y=fft(y1,40000);
Y1=abs(Y);
subplot(3,2,1);
plot(t,y1)
axis([0,0.09,-1,1]);
Title('时域100HZ正弦信号波形图');
xlabel('T');
ylabel('A');
grid on;
subplot(3,2,2);
stem(Y1,'-y');
Title('频域100HZ正弦信号幅度特性');
xlabel('F');
ylabel('A');
axis([0,310,0,40000]);
grid on;
y2=a2sin(2*pi*f2*t);
Y=fft(y2,40000);
Y1=abs(Y);
subplot(3,2,3);
plot(t,y2);
Title('时域200HZ正弦信号波形');
xlabel('T');
ylabel('A');
axis([0,0.09,-1,1]);
grid on;
subplot(3,2,4);
stem(Y1,'-y');
Title('频域200HZ正弦信号幅度特性');
xlabel('F');
ylabel('A');
axis([0,310,0,40000]);
grid on;
y3=a3sin(2*pi*f3*t);
Y=fft(y3,40000);
Y1=abs(Y);
subplot(3,2,5);
plot(t,y3);
Title('时域300HZ正弦信号波形');
xlabel('T');
ylabel('A');
axis([0,0.09,-1,1]);
grid on;
subplot(3,2,6);
stem(Y1,'-y');
Title('频域300HZ正弦信号幅度特性');
xlabel('F');
ylabel('A');
axis([0,310,0,40000]);
grid on;
%带通滤波器的程序代码
figure(2);
f_N=40000;
f_P=[150,250];
f_S=[100,300];
R_p=3;R_s=25;
Ws=f_S/(f_N/2);Wp=f_P/(f_N/2);
[n,Wn]=buttord(Wp,Ws,R_p,R_s);
[b,a]=butter(n,Wn);
freqz(b,a,1000,40000);
subplot(2,1,1);
axis([0,500,-40,2]);
%合成信号的波形图
figure(3);
y=y1+y2+y3;
Y=fft(y,40000);
subplot(2,2,1);
plot(t,y);
Title('合并信号后合并信号的时域波形');
xlabel('T');
ylabel('A');
axis([0,0.09,-1,1]);
grid on;
subplot(2,2,2);
stem(Y,'-y');
Title('合并信号后合并信号幅域特性');
xlabel('F');
ylabel('A');
axis([0,310,0,40000]);
grid on;
%合并信号经过带通滤波器后的时域和频域波形图
y1=filter(b,a,y);
y2=fft(y1,40000);
subplot(2,2,3);
plot(t,y1);
Title('合并信号经过滤波器后的时域波形');
xlabel('T');
ylabel('A');
axis([0,0.09,-1,1]);
grid on;
subplot(2,2,4);
stem(y2,'-y');
Title('合并的正弦信号经过带通滤波器后幅域特性');
xlabel('F');
ylabel('A');
axis([0,310,0,40000]);
grid on;
点击下载数字信号处理课程设计.rar