📄 ip_7_16.m
字号:
echo on
ts=1/120;
fc=50;
fs=1/ts;
t=[0:ts:2];
df=0.1;
m=zeros(1,length(t));
m(12:120)=t(12:120);
m(121:228)=-t(121:228)+2;
c=cos(2*pi*fc.*t);
u=m.*c;
[M,m,df1]=fftseq(m,ts,df);
M=M/fs;
[U,u,df1]=fftseq(u,ts,df);
U=U/fs;
[C,c,df1]=fftseq(c,ts,df);
f=[0:df1:df1*(length(m)-1)]-fs/2;
A=[0.001 0.01 0.05 0.1 0.3];
for i=1:5
snr=1/A(i)
signal_power=spower(u(1:length(t)));
noise_power=signal_power/snr;
noise_std=sqrt(noise_power);
noise=noise_std*randn(1,length(u));
r=u+noise;
y=r.*c;
[R,r,df1]=fftseq(r,ts,df);
R=R/fs;
[Y,y,df1]=fftseq(y,ts,df);
Y=Y/fs;
f_cutoff=1;
n_cutoff=floor(1/df1);
f=[0:df1:df1*(length(y)-1)]-fs/2;
H=zeros(size(f));
H(1:n_cutoff)=2*ones(1,n_cutoff);
H(length(f)-n_cutoff+1:length(f))=2*ones(1,n_cutoff);
DEM=H.*Y;
dem=real(ifft(DEM))*fs;
pause;
clf;
subplot(2,1,1);
plot(f,fftshift(abs(M)));
title('消息信号频谱');
xlabel('Frequency');
subplot(2,1,2);
plot(f,fftshift(abs(U)));
title('已调信号频谱');
xlabel('Frequency');
pause;
subplot(1,1,1);
plot(f,fftshift(abs(R)));
title('加噪声信号且n/s=0.001频谱');
xlabel('Frequency');
pause;
clf;
subplot(3,1,1);
plot(f,fftshift(abs(Y)));
title('混频器输出的频谱');
xlabel('Frequency');
subplot(3,1,2);
plot(f,fftshift(abs(H)));
title('低通滤波器特性');
xlabel('Frequency');
subplot(3,1,3);
plot(f,fftshift(abs(DEM)));
title('解调输出频谱');
xlabel('Frequency');
pause;
clf;
subplot(2,1,1);
plot(f,fftshift(abs(M)));
title('消息信号频谱');
xlabel('Frequency');
subplot(2,1,2);
plot(f,fftshift(abs(DEM)));
title('解调输出频谱');
xlabel('Frequency');
pause;
subplot(2,1,1);
plot(t,m(1:length(t)));
title('消息信号');
xlabel('Time');
subplot(2,1,2);
plot(t,dem(1:length(t)));
title('解调信号');
xlabel('Time');
end
snr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -