%%%%%%%%%%%%%%%%%%%%%%%%%%%
%AM调制解调系统
%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;
clf;
close all
Fs=800000;%采样频率800k
fz=80000;%载波频率80k
fj=1000;%基波频率1k
i=5000;%采样点数
t=(1:i)/Fs;%时间
B=1;%基波的幅度
A=1;%直流分量
%%%%%%%%%%%%%%%%%%%
%产生基波
%%%%%%%%%%%%%%%%%%%
Mod_Sig=B*sin(2*pi*fj/Fs*(1:i));%基波 subplot(311);plot(t,Mod_Sig);grid on;title('基波');xlabel('时间(S)');ylabel('幅度(V)');
%%%%%%%%%%%%%%%%%%%
%产生载波
%%%%%%%%%%%%%%%%%%%
Carrier=cos(2*pi*fz/Fs*(1:i)+1/3*pi);%载波1/3*pi为初相
subplot(312);plot(t(1:200),Carrier(1:200));grid on;title('载波');xlabel('时间(S)');ylabel('幅度(V)');
%%%%%%%%%%%%%%%%%%%
%产生AM调制信号
%%%%%%%%%%%%%%%%%%%
Dsb_am=Carrier.*(A+Mod_Sig);%am调制其中1表示调制深度为100% subplot(313);plot(t,Dsb_am);grid on;title('调制信号');xlabel('时间(S)');ylabel('幅度(V)');
%%%%%%%%%%%%%%%%%%%
%本地载波恢复
%%%%%%%%%%%%%%%%%%%
Q_Carrier=sin(2*pi*fz/Fs*(1:i));%本地载波
I_Carrier=cos(2*pi*fz/Fs*(1:i));%本地载波
%%%%%%%%%%%%%%%%%%%
%与载波相乘
%%%%%%%%%%%%%%%%%%%
I_sig=Dsb_am.*I_Carrier;%I_s(n)信号
Q_sig=Dsb_am.*Q_Carrier;%Q_s(n)信号
%%%%%%%%%%%%%%%%%%%
%50K的低通滤波器的参数(FIR),在50k处衰减3dB
%%%%%%%%%%%%%%%%%%%
b2=[ -0.00106922746866,-0.006075550546223,-0.007384066670327, ...
-0.01052472923662, -0.01204471419927, -0.01133837646302,-0.007173132971803, ...
0.00124885770863, 0.01421859098232, 0.03131749663963, 0.05136128801581, 0.07250241184686, ...
0.09245525890349, 0.1088536253853, 0.1196360034084, 0.1233945655916, 0.1196360034084,...
0.1088536253853, 0.09245525890349, 0.07250241184686, 0.05136128801581, 0.03131749663963, ...
0.01421859098232, 0.00124885770863, -0.007173132971803, -0.01133837646302, -0.01204471419927,...
-0.01052472923662, -0.007384066670327,-0.006075550546223, -0.00106922746866];
%%%%%%%%%%%%%%%%%%%
%得到滤波后的IQ信号
%%%%%%%%%%%%%%%%%%%
sI1 = filter(b2,1,I_sig);%I(n)
sQ1 = filter(b2,1,Q_sig);%Q(n)
%%%%%%%%%%%%%%%%%%%
%解调算法
%%%%%%%%%%%%%%%%%%%
demo=2*sqrt(sI1.*sI1+sQ1.*sQ1);
%%%%%%%%%%%%%%%%%%%
%解调输出
%%%%%%%%%%%%%%%%%%%
figure;
plot(t,Mod_Sig,t,Dsb_am,t,demo);
grid on;title('基带信号,am调制信号,解调信号');xlabel('时间(S)');ylabel('幅度(V)');grid on;legend('基带','调制信号','解调信号');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%FM调制解调系统
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;
clf;
close all
Fs=800000;%采样频率800k
fz=80000;%载波频率80k
fj=1000;%基波频率1k
i=4096;%采样点数
A=1;%幅度
Kf=0.2;%调频灵敏度
t=(1:i)/Fs;%时间
tf=(1:i-1)/Fs;%时间
f=((1:i)-1)*Fs/i; %换算成实际的频率值
tz=1; %时间向量精度
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%产生信号(基波)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Mod_Sig_c=A*cos(2*pi*fj/Fs*(1:i));%基波cos,[M(t)]
%画图基带信号
subplot(311);plot(t,Mod_Sig_c);title('基带信号');xlabel('时间(S)');ylabel('幅度(V)');grid on;legend('基带');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%载波信号(载波)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Carrier_c=cos(2*pi*fz/Fs*(1:i));%载波cos
%画载波
subplot(312);plot(t(1:300),Carrier_c(1:300));title('载波信号');xlabel('时间(S)');ylabel('幅度(V)');grid on;legend('载波');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%对基波积分
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
int_m(1)=0; %对m_fun积分
for p=1:length(1:i)-1
int_m(p+1)=int_m(p)+Mod_Sig_c(p)*tz;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%产生FM调制信号
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SFm_c=A*cos(2*pi*fz/Fs*(1:i)+int_m*Kf+1/2*pi);%FM调制信号 ,1/2*pi为频偏,但实际意义不大
SFm=awgn(SFm_c,0.00000022);
%画调制信号
subplot(313);plot(t,SFm);title('调制信号');xlabel('时间(S)');ylabel('幅度(V)');grid on;legend('调制信号');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%对调制信号做FFT,FFT的频率和幅值的计算,并画图显示
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ff_SFm=fft(SFm);%快速傅里叶变换
ff_SFm_abs=abs(ff_SFm);%取模值
ff_SFm_range=ff_SFm_abs/(i/2); %换算成实际的幅度
ff_SFm_range(1)=ff_SFm_abs(1)/i;%换算直流分量
figure;plot(f(1:i/2),ff_SFm_range(1:i/2));title('FM的频谱');xlabel('频率(Hz)');ylabel('幅度(V)');grid on;legend('FM的频谱');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%解调过程
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Q_Carrier=sin(2*pi*fz/Fs*(1:i));%本地载波恢复
I_Carrier=cos(2*pi*fz/Fs*(1:i));%本地载波恢复
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%得到IQ信号
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SigI=SFm.*I_Carrier;%I_s(n)信号
SigQ=SFm.*Q_Carrier;%Q_s(n)信号
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%低通滤波器50k衰减3db的系数
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
lpf50k=[ -0.00106922746866,-0.006075550546223,-0.007384066670327, -0.01052472923662, -0.01204471419927,...
-0.01133837646302,-0.007173132971803, 0.00124885770863, 0.01421859098232, 0.03131749663963, 0.05136128801581,...
0.07250241184686, 0.09245525890349, 0.1088536253853, 0.1196360034084, 0.1233945655916, 0.1196360034084, ...
0.1088536253853, 0.09245525890349, 0.07250241184686, 0.05136128801581, 0.03131749663963, 0.01421859098232, ...
0.00124885770863, -0.007173132971803, -0.01133837646302, -0.01204471419927, -0.01052472923662, ...
-0.007384066670327,-0.006075550546223, -0.00106922746866];
%IQ信号分别通过低通滤波器
FsigI=filter(lpf50k,1,SigI);%I(n)
FsigQ=filter(lpf50k,1,SigQ);%Q(n)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%解调算法%Q(n)I(n-1)-I(n)Q(n-1)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for w=1:i-1
demo(w)=FsigI(w+1).*FsigQ(w)-FsigI(w).*FsigQ(w+1);
end
% demo=atan2(FsigQ,FsigI);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%幅度调整由公式1-12可知,因为A=1,Kf=0.2,所以1/C=20
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
demod=20*(demo); figure;plot(t,Mod_Sig_c,tf,demod);grid on;title('FM的解调');xlabel('时间(s)');ylabel('幅度(V)');grid on;legend('基带信号','解调信号');