以下是老师提供的代码:
dt=0.005; %设定步长
t=0:dt:3;
am=5; %调制信号幅度
fm=5; %调制信号频率
mt=am*cos(2*pi*fm*t) ; %生成调制信号
j_mt(1)=0;
for i=1:length(t)-1
%对调制信号求积分
j_mt(i+1)=j_mt(i)+mt(i)*dt;
end
fc=25;
ct=cos(2*pi*fc*t) ; %生成载波
kf=10; %调频灵敏度
sft=cos(2*pi*fc*t+kf*j_mt) ; %生成已调信号
%*************添加高斯白噪声**************
sn1=10; %设定信躁比(小信噪比)
sn2=40; %设定信躁比(大信噪比)
%**************figure(3)无噪声解调信号的时域图******************
figure(1)
subplot(3,1,1);plot(t,mt); %绘制调制信号的时域图
xlabel('时间t');
title('调制信号的时域图');
subplot(3,1,2);plot(t,sft); %绘制已调信号的时域图
xlabel('时间t');
title('无噪声条件下已调信号的时域图');
%% 请同学编写解调方法
nsfm1=sft; %无噪声的已调信号
diff_nsfm1 = zeros(1, length(nsfm1) - 1);
for i=1:length(t)-1 %信号通过微分器处理
diff_nsfm1(i)=(nsfm1(i+1)-nsfm1(i))./dt;
end
diff_nsfmn=abs(hilbert(diff_nsfm1)); %hilbert变换,求绝对值得到瞬时幅度(包络检波)
zero=(max(diff_nsfmn)-min(diff_nsfmn))/2;
diff_nsfmn1=diff_nsfmn-zero;
subplot(3,1,3); %绘制无噪声条件下解调信号的时域图
plot((1:length(diff_nsfmn1))./2000,diff_nsfmn1./400-30,'r');
xlabel('时间t');
title('无噪声条件下解调信号的时域图');
%**************figure(4)小信噪比******************
figure(2)
subplot(3,1,1);plot(t,mt); %绘制调制信号的时域图
xlabel('时间t');
title('调制信号的时域图');
db1=am^2/(2*(10^(sn1/10))); %计算对应的小信噪比高斯白躁声的方差
n1=sqrt(db1)*randn(size(t)); %生成高斯白躁声
nsfm1=n1+sft; %生成含高斯白躁声的已调信号(信号通过信道传输)
subplot(3,1,2);
plot(t,nsfm1); %含小信噪比高斯白噪声已调信号时域图
xlabel('时间t');
title('含小信噪比高斯白噪声已调信号的时域图');
%% 请同学编写解调方法
diff_nsfm1 = zeros(1, length(nsfm1) - 1);
for i=1:length(t)-1 %信号通过微分器处理
diff_nsfm1(i)=(nsfm1(i+1)-nsfm1(i))./dt;
end
diff_nsfmn=abs(hilbert(diff_nsfm1)); %hilbert变换,求绝对值得到瞬时幅度(包络检波)
zero=(max(diff_nsfmn)-min(diff_nsfmn))/2;
diff_nsfmn1=diff_nsfmn-zero;
subplot(3,1,3); %含小信噪比高斯白噪声解调信号时域图
plot((1:length(diff_nsfmn1))./2000,diff_nsfmn1./400-30,'r');
xlabel('时间t');
title('含小信噪比高斯白噪声解调信号的时域图');
%**************figure(5)大信噪比******************
figure(3)
subplot(3,1,1);
plot(t,mt); %绘制调制信号的时域图
xlabel('时间t');
title('调制信号的时域图');
db1=am^2/(2*(10^(sn2/10))); %计算对应的大信噪比高斯白躁声的方差
n1=sqrt(db1)*randn(size(t)); %生成高斯白躁声
nsfm1=n1+sft; %生成含高斯白躁声的已调信号(信号通过信道传输)
subplot(3,1,2);
plot(t,nsfm1); %绘制含大信噪比高斯白噪声已调信号的时域图
xlabel('时间t');
title('含大信噪比高斯白噪声已调信号的时域图');
%% 请同学编写解调方法
diff_nsfm1 = zeros(1, length(nsfm1) - 1);
for i=1:length(t)-1 %信号通过微分器处理
diff_nsfm1(i)=(nsfm1(i+1)-nsfm1(i))./dt;
end
diff_nsfmn=abs(hilbert(diff_nsfm1)); %hilbert变换,求绝对值得到瞬时幅度(包络检波)
zero=(max(diff_nsfmn)-min(diff_nsfmn))/2;
diff_nsfmn1=diff_nsfmn-zero;
subplot(3,1,3); %绘制含大信噪比高斯白噪声解调信号的时域图
plot((1:length(diff_nsfmn))./2000,diff_nsfmn1./400-30,'r');
xlabel('时间t');
title('含大信噪比高斯白噪声解调信号的时域图');
以下代码老师没有提供:
% 调频指数为10
clc, clear, clf;
T = 1;
dt = 0.0005;
t = 0: dt: T - dt;
A = 5;
fm = 5;
wm = 2 * pi * fm;
mt = A * cos(wm * t); % 调制信号
fc = 25;
wc = 2 * pi * fc;
ct = cos(wc * t); % 载波信号
A_c = 1;
K_F = 10; % 调频指数
sFM = A_c * cos(wc * t + K_F * cumsum(mt) * dt); % 已调信号
% 无噪声
figure;
sdt = [0 diff(sFM)];
rt = abs(hilbert(sdt)); % 非相干解调信号
subplot(311);
plot(mt);
xlabel('时间t');
xlabel('调制信号的时域图');
subplot(312);
plot(sFM);
xlabel('时间t');
title('无噪声条件下己调信号的时域图');
subplot(313);
plot(rt, 'r');
xlabel('时间t');
title('无噪声条件下解调信号的时域图');
% 小信噪比
figure;
SNR = 10;
sigma = sqrt(A^2 / (2 * 10^(SNR / 10)));
noise = sigma * rand(1, length(mt));
rt1 = sFM + noise;
sdt = [0 diff(rt1)];
rt = abs(hilbert(sdt)); % 非相干解调信号
subplot(311);
plot(mt);
xlabel('时间t');
xlabel('调制信号的时域图');
subplot(312);
plot(rt1);
xlabel('时间t');
title('含小信噪比高斯白噪声己调信号的时域图');
subplot(313);
plot(rt, 'r');
xlabel('时间t');
title('含小信噪比高斯白噪声解调信号的时域图');
% 大信噪比
figure;
SNR = 40;
sigma = sqrt(A^2 / (2 * 10^(SNR / 10)));
noise = sigma * rand(1, length(mt));
rt1 = sFM + noise;
sdt = [0 diff(rt1)];
rt = abs(hilbert(sdt)); % 非相干解调信号
subplot(311);
plot(mt);
xlabel('时间t');
xlabel('调制信号的时域图');
subplot(312);
plot(rt1);
xlabel('时间t');
title('含大信噪比高斯白噪声己调信号的时域图');
subplot(313);
plot(rt, 'r');
xlabel('时间t');
title('含大信噪比高斯白噪声解调信号的时域图');
% 调频指数为20
clc, clear, clf;
T = 1;
dt = 0.0005;
t = 0: dt: T - dt;
A = 5;
fm = 5;
wm = 2 * pi * fm;
mt = A * cos(wm * t); % 调制信号
fc = 25;
wc = 2 * pi * fc;
ct = cos(wc * t); % 载波信号
A_c = 1;
K_F = 20; % 调频指数
sFM = A_c * cos(wc * t + K_F * cumsum(mt) * dt); % 已调信号
% 无噪声
figure;
sdt = [0 diff(sFM)];
rt = abs(hilbert(sdt)); % 非相干解调信号
subplot(311);
plot(mt);
xlabel('时间t');
xlabel('调制信号的时域图');
subplot(312);
plot(sFM);
xlabel('时间t');
title('无噪声条件下己调信号的时域图');
subplot(313);
plot(rt, 'r');
xlabel('时间t');
title('无噪声条件下解调信号的时域图');
% 小信噪比
figure;
SNR = 10;
sigma = sqrt(A^2 / (2 * 10^(SNR / 10)));
noise = sigma * rand(1, length(mt));
rt1 = sFM + noise;
sdt = [0 diff(rt1)];
rt = abs(hilbert(sdt)); % 非相干解调信号
subplot(311);
plot(mt);
xlabel('时间t');
xlabel('调制信号的时域图');
subplot(312);
plot(rt1);
xlabel('时间t');
title('含小信噪比高斯白噪声己调信号的时域图');
subplot(313);
plot(rt, 'r');
xlabel('时间t');
title('含小信噪比高斯白噪声解调信号的时域图');
% 大信噪比
figure;
SNR = 40;
sigma = sqrt(A^2 / (2 * 10^(SNR / 10)));
noise = sigma * rand(1, length(mt));
rt1 = sFM + noise;
sdt = [0 diff(rt1)];
rt = abs(hilbert(sdt)); % 非相干解调信号
subplot(311);
plot(mt);
xlabel('时间t');
xlabel('调制信号的时域图');
subplot(312);
plot(rt1);
xlabel('时间t');
title('含大信噪比高斯白噪声己调信号的时域图');
subplot(313);
plot(rt, 'r');
xlabel('时间t');
title('含大信噪比高斯白噪声解调信号的时域图');
% 先做扩展2再做扩展1(扩展1在后面)
% 实验扩展2、试从频域上分析无噪声、小信噪比噪声、大信噪比噪声三种情况下信号的解调。
figure;
% 无噪声
sdt = [0 diff(sFM)];
rt = abs(hilbert(sdt)); % 非相干解调信号
[s, fs] = T2F(t, rt); % 傅里叶变换
subplot(321);
plot(rt);
xlabel('时间t');
title('无噪声条件下解调信号的时域图');
subplot(322);
plot(s, abs(fs));
xlabel('f(kHz)');
title('无噪声条件下解调信号的频率特性');
% 小信噪比
SNR = 10;
sigma = sqrt(A^2 / (2 * 10^(SNR / 10)));
noise = sigma * rand(1, length(mt));
rt1 = sFM + noise;
sdt = [0 diff(rt1)];
rt = abs(hilbert(sdt)); % 非相干解调信号
[s, fs] = T2F(t, rt); % 傅里叶变换
subplot(323);
plot(rt);
xlabel('时间t');
title('含小信噪比高斯白噪声解调信号的时域图');
subplot(324);
plot(s, abs(fs));
xlabel('f(kHz)');
title('含小信噪比高斯白噪声解调信号的频率特性');
% 大信噪比
SNR = 40;
sigma = sqrt(A^2 / (2 * 10^(SNR / 10)));
noise = sigma * rand(1, length(mt));
rt1 = sFM + noise;
sdt = [0 diff(rt1)];
rt = abs(hilbert(sdt)); % 非相干解调信号
[s, fs] = T2F(t, rt); % 傅里叶变换
subplot(325);
plot(rt);
xlabel('时间t');
title('含大信噪比高斯白噪声解调信号的时域图');
subplot(326);
plot(s, abs(fs));
xlabel('f(kHz)');
title('含大信噪比高斯白噪声解调信号的频率特性');
% 实验扩展1、试使用另一种解调算法来实现解调
clc, clear all, close all;
Fs = 40000;
Ts = 1 / Fs;
T = 10000;
t = (0 : T - 1) * Ts;
%% 频率调制(FM)
kf = 1000;
fm = 500;
fc = 10000;
mt = cos(2 * pi * fm * t);
st = sin(2 * pi * fc * t + 2 * pi * kf * cumsum(mt) * Ts);
subplot(311);
plot(t,mt);
title('基带信号时域图');
xlabel('时间t');
xlim([0 0.05]);
%% 非相干解调(包络检波法)
sdt = [0 diff(st)];
rt = abs(hilbert(sdt));
subplot(312);
plot(t,rt);
title('相干解调信号');
xlabel('时间t');
xlim([0 0.05]);
%% 相干解调法(同步解调)
vco_phase = zeros(1,T);
rt = zeros(1,T);
et = zeros(1,T);
vt = zeros(1,T);
Av = 1;
kv = 40000;
km = 1;
k0 = 1;
rt(1) = Av * cos(vco_phase(1));
et(1) = km * rt(1) * st(1);
b0 = 0.073;
b1 = 0.073;
a1 = -0.854;
vt(1) = k0 * (b0 * et(1));
for n = 2 : T
vco_phase_change = 2 * pi * fc * Ts + kv * vt(n - 1) * Ts;
vco_phase(n) = vco_phase(n - 1) + vco_phase_change;
rt(n) = Av * cos(vco_phase(n));
et(n) = km * rt(n) * st(n);
vt(n) = k0 * (b0 * et(n) + b1 * et(n - 1) - a1 * vt(n - 1));
end
subplot(313);
plot(t,vt);
xlabel('时间t');
title('非相干解调信号');
xlim([0 0.05]);
% 实验扩展3、根据仿真结果,说明不同调频指数对解调结果的影响,谈谈你对解调增益的看法。
% 调频指数越大,已调信号抗噪声能力越强,解调出来的信号越接近基带信号,
% 调频系统的信噪比增益与调频指数的三次方成正比。