clc;
close all;
clear all;
dt=0.001;%采样周期
fm=1;%信源最高频率
fc=10;%载波中心频率
T=5;%信号时长
t=0:dt:T+dt;
a=1;
mt=a.*cos(2*pi*fm*t);%信源
N0=0.10;%白噪声单边功率谱密度
A=2;
s_am=(A+mt).*cos(2*pi*fc*t);
B=2*fm;%带通滤波器带宽
noise=noise_nb(fc,B,N0,t);%窄带高斯白噪声的产生
s_am1=s_am+noise;%加性噪声
figure(1);
subplot(311);
plot(t,s_am);hold on;
plot(t,A+mt,'r--');plot(t,-(A+mt),'r--');%标识AM包络
title('AM调制信号及其包络');
xlabel('t');axis([0 T -A-a A+a]);
figure(2);subplot(211);
plot(t,s_am);hold on;
plot(t,s_am1,'r');%加噪声的AM信号
title('AM信号有/无加高斯白噪声');legend('理想AM信号','加窄带白噪的AM信号');
xlabel('t');axis([0 T -A-a-1 A+a+1]);
rt=s_am.*cos(2*pi*fc*t);%相干解调
rt=rt-mean(rt);
[f,rf]=T2F(t,rt);
[t,rt]=lpf(f,rf,B);%低通滤波器
figure(1);subplot(312);
plot(t,rt);hold on;grid on;
plot(t,mt/2,'r--');
title('相干解调的信号波形与输入信号比较');
xlabel('t');axis([0 T -a a]);
rt1=s_am1.*cos(2*pi*fc*t);%相干解调
rt1=rt1-mean(rt1);
[f,rf1]=T2F(t,rt1);
[t,rt1]=lpf(f,rf1,B);%低通滤波器
figure(2);subplot(212);
plot(t,rt);hold on;grid on;
plot(t,rt1,'r');
title('理想AM与含噪声AM解调后的波形比较');
xlabel('t');axis([0 T -a-1 a+1]);legend('理想AM解调信号','加窄带白噪的AM解调信号');
figure(1);subplot(313);
[f,sf]=T2F(t,s_am);%调制信号频谱
psf=(abs(sf).^2)/T;%调制信号功率谱
plot(f,sf);
axis([-2*fc 2*fc 0 max(psf)]);
title('AM信号功率谱');
xlabel('f');