以下是老师提供的代码:
dt=0.005; %设定步长
t=0:dt:3;
%% 需要同学生成调制信号、载波信号以及已调信号
fm = 5; fc = 25; kf = 10;
A = 5; A_c = 1;
mt = A * cos(2 * pi * fm * t);
ct = cos(2 * pi * fc * t);
sFM = A_c * cos(2 * pi * fc * t + kf * cumsum(mt) * dt);
sft = sFM;
%% 绘制三类信号的时域图
figure(1) %绘制图形
subplot(311);
plot(t, mt);
% axis([0 1 -5.1 5.1])
xlabel('t');
title('调制信号时域图');
subplot(312);
plot(t, ct);
% axis([0 1 -1.1 1.1])
xlabel('t');
title('载波时域图');
subplot(313);
plot(t,sft);
% axis([0 1 -1.1 1.1])
xlabel('t')
title('已调信号时域图');
%% 绘制调制信号与已调信号的频域图
[f1,fmm]=T2F(t,mt);
[f2,Fm]=T2F(t,sft);%傅里叶变换得到频谱
figure(2) %绘制已调信号时频域图
subplot(211);
plot(f1,abs(fmm)) ;
axis([-40 40 0 max(abs(fmm))]);
xlabel('f')
title('调制信号频谱');
subplot(212)
plot(f2,abs(Fm));
axis([-40 40 0 max(abs(Fm))]);
title('已调信号频谱');
xlabel('f')
%**************figure(3)无噪声解调信号的时域图******************
figure(3)
subplot(2,1,1);plot(t,mt); %绘制调制信号的时域图
xlabel('时间t');
title('调制信号的时域图');
sft = sFM;
subplot(2,1,2);plot(t,sft); %绘制已调信号的时域图
xlabel('时间t');
title('无噪声条件下已调信号的时域图');
%% 需要同学完成:若小信噪比为10dB,绘制已调信号时域图和小信噪比条件下含高斯白噪声的已调信号时域图
figure(4)
subplot(2,1,1);plot(t,mt); %绘制调制信号的时域图
xlabel('时间t');
title('调制信号的时域图');
SNR = 10;
sigma = sqrt(A^2 / (2 * 10^(SNR / 10)));
noise = sigma * rand(1, length(mt));
sft = sFM + noise;
subplot(2,1,2);plot(t,sft); %绘制已调信号的时域图
xlabel('时间t');
title('含小信噪比高斯白噪声已调信号的时域图');
%% 需要同学完成:若小信噪比为40dB,绘制已调信号时域图和大信噪比条件下含高斯白噪声的已调信号时域图
figure(5)
subplot(2,1,1);plot(t,mt); %绘制调制信号的时域图
xlabel('时间t');
title('调制信号的时域图');
SNR = 40;
sigma = sqrt(A^2 / (2 * 10^(SNR / 10)));
noise = sigma * rand(1, length(mt));
sft = sFM + noise;
subplot(2,1,2);plot(t,sft); %绘制已调信号的时域图
xlabel('时间t');
title('含大信噪比高斯白噪声已调信号的时域图');
以下是老师没有提供的代码:
% 实验扩展1、根据实验结果验证卡森公式,说明卡森公式在评估FM带宽方面的意义。
% 卡森公式:B = 2 (Δf + fH)
% 频偏直接影响频谱的形状与带宽,频偏比越小,带宽越小,频偏比越大,带宽越大。
% 实验扩展2、评价加噪对信号造成的影响。
% 加性噪声加在信号上,如果信噪比过小,即噪声过大,信号淹没在噪声中
% 3、基带信号承载真实语音信号,分析时频域特性
clc, clear, clf;
[xn, fs] = audioread('motherland.wav');
T = 1 / fs;
t = (0:10000-1) * T;
A = 5;
fm = 5;
wm = 2 * pi * fm;
% mt = A * cos(wm * t); % 调制信号
mt = xn(1:10000); % 调制信号
mt = reshape(mt, [1, length(mt)]);
fc = 25;
wc = 2 * pi * fc;
ct = cos(wc * t); % 载波信号
A_c = 5;
K_F = 10;
sFM = A_c * cos(wc * t + K_F * cumsum(mt) * T); % 已调信号
figure(1);
subplot(321);
plot(t, mt);
xlabel('t(s)');
title('调制信号时域图');
subplot(322);
[f, sfm] = T2F(t, mt);
plot(f, abs(sfm));
xlabel('f/Hz');
title('调制信号频谱');
subplot(323);
plot(t, ct);
xlabel('t(s)');
title('载波信号时域图');
subplot(324);
[f, sfc] = T2F(t, ct);
plot(f, abs(sfc));
xlabel('f/Hz');
xlim([-100, 100]);
title('载波信号频谱');
subplot(325);
plot(t, sFM);
xlabel('t(s)');
title('已调信号时域图');
subplot(326);
[f, sfFM] = T2F(t, sFM);
plot(f, abs(sfFM));
xlabel('f/Hz');
xlim([-100, 100]);
title('FM 已调信号频谱');