n=1024;fs=n; %设取样频率fs=1024Hz
s=320*pi; %产生调制信号m(t)
i=0:1:n-1;
t=i/n;
t1=(t-1/7).^2;t3=(t-3/7).^2;t4=(t-4/7).^2;
t6=(t-6/7).^2;
m=exp(-s*t1)+exp(-s*t3)+exp(-s*t4)+exp(-s*t6); %产生调制信号
c=cos(2*pi*100*t); %产生载波信号 载波频率fc=100Hz
x=m.*c; %正弦波幅度调制(DSB)
y=x.*c; %解调
wp=0.1*pi;ws=0.12*pi;Rp=1;As=15; %设计巴特沃思数字低通滤波器
[N,wn]=buttord(wp/pi,ws/pi,Rp,As);
[b,a]=butter(N,wn);
m1=filter(b,a,y); %滤波
m1=2*m1;
M=fft(m,n); %求上述各信号及滤波器的频率特性
C=fft(c,n);
X=fft(x,n);
Y=fft(y,n);
[H,w]=freqz(b,a,n,'whole');
f=(-n/2:1:n/2-1); %绘图
figure(1);
subplot(341),plot(t,m);,axis([0,1,-0.25,1.25]);
title('调制信号的波形')
subplot(342),plot(f,abs(fftshift(M)));axis([-300,300,0,250]);
title('调制信号的频谱')
subplot(343),plot(t,c);axis([0,0.2,-1.2,1.2]);
title('载波的波形')
subplot(344),plot(f,abs(fftshift(C)));axis([-300,300,0,600]);
title('载波的频谱')
subplot(345),plot(t,x);axis([0,1,-1.2,1.2]);
title('已调信号的波形')
subplot(346),plot(f,abs(fftshift(X)));axis([-300,300,0,120]);
title('已调信号的频谱')
subplot(347),plot(t,y); axis([0,1,0,1.2]);
title('解调信号的波形')
subplot(348),plot(f,abs(fftshift(Y)));axis([-300,300,0,120]);
title('解调信号的频谱')
subplot(3,4,10),plot(f,abs(fftshift(H)));axis([-300,300,0,1.25]);
title('滤波器传输特性')
subplot(3,4,11),plot(t,m1),axis([0,1,-0.25,1.25]);
title('解调滤波后的信号')