📄 ip_7_11.m
字号:
echo on
ts=1/80; % sampling interval
fc=50; % carrier frequency
fs=1/ts; % sampling frequency
T=2;
t=[0:ts:2.0]; % time vector
df=0.2; % desired frequency resolution
% message signal
m=zeros(size(t));
m(8:80)=t(8:80);
m(81:152)=-t(81:152)+2;
c=cos(2*pi*fc.*t); % carrier signal
u=m.*c; % modulated signal
y1=u.*c; % mixing
[M,m,df1]=fftseq(m,ts,df); % Fourier transform
M=M/fs; % scaling
[U,u,df1]=fftseq(u,ts,df); % Fourier transform
U=U/fs; % scaling
[C,c,df1]=fftseq(c,ts,df);
C=C/fs;
f=[0:df1:df1*(length(m)-1)]-fs/2;
[Y1,y1,df1]=fftseq(y1,ts,df); % Fourier transform
Y1=Y1/fs; % scaling
A=[1/0.001 1/0.01 1/0.05 1/0.1 1/0.3];
for i=1:5
snr=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; % 给调制信号加入噪声
y2=r.*c; % 对调制信号加噪声混频
[R,r,df1]=fftseq(r,ts,df); % 信号加噪声的频谱
R=R/fs; % 缩放
[Y2,y2,df1]=fftseq(y2,ts,df); % Fourier transform
Y2=Y2/fs; % scaling
f_cutoff=1;
n_cutoff=floor(1/df1);
f=[0:df1:df1*(length(y2)-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);
DEM1=H.*Y1; % spectrum of the filter output
dem1=real(ifft(DEM1))*fs; % filter output
DEM2=H.*Y2;
dem2=real(ifft(DEM2))*fs;
pause % Press a key to see the effct of mixing
clf
subplot(2,2,1)
plot(f,fftshift(abs(M)))
title('Spectrum of the Message Signal')
xlabel('Frequency')
subplot(2,2,2)
plot(f,fftshift(abs(U)))
title('Spectrum of the Modulated Signal')
xlabel('Frequency')
subplot(2,2,3)
plot(f,fftshift(abs(Y1)))
title('没有加噪声的混频输出')
xlabel('Frequency')
subplot(2,2,4)
plot(f,fftshift(abs(Y2)))
title('加入噪声的混频输出')
xlabel('Frequency')
pause
subplot(1,1,1);
plot(f,fftshift(abs(R)));
title('加入噪声的信号频谱');
xlabel('Frequency');
pause % Press a key to see the effect of filtering on the mixer output
clf
subplot(2,2,1)
plot(f,fftshift(abs(Y1)))
title('Spectrum of the Mixer output')
xlabel('Frequency')
subplot(2,2,2)
plot(f,fftshift(abs(H)))
title('Lowpass Filter Characteristics')
xlabel('Frequency')
subplot(2,2,3)
plot(f,fftshift(abs(DEM1)))
title('Spectrum of the Demodulator Output')
xlabel('Frequency')
subplot(2,2,4)
plot(f,fftshift(abs(DEM2)))
title('Spectrum of the Demodulator Output')
xlabel('Frequency')
pause % Press a key to compare the spectra of the message and received signal
clf
subplot(3,1,1)
plot(f,fftshift(abs(M)))
title('Spectrum of the Message Signal')
xlabel('Frequency')
subplot(3,1,2)
plot(f,fftshift(abs(DEM1)))
title('Spectrum of the Demodulatur Output')
xlabel('Frequency')
subplot(3,1,3)
plot(f,fftshift(abs(DEM2)))
title('Spectrum of the Demodulatur Output')
xlabel('Frequency')
pause % Press a key to see massage and the demodulator output signals
subplot(3,1,1)
plot(t,m(1:length(t)))
axis([0 2.0 0 1.0])
title('The Message Signal')
xlabel('Time')
subplot(3,1,2)
plot(t,dem1(1:length(t)))
axis([0 2.0 0 2.0])
title('The Demodulator Output')
xlabel('Time')
subplot(3,1,3)
plot(t,dem2(1:length(t)))
axis([0 2.0 0 2.0])
title('The Demodulator signal in the presence of noise')
xlabel('Time')
end
snr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -