模拟信号调制解调AM与相干解调
AM调制与相干解调
AM.m主程序,
F2T.m傅里叶变换,T2F傅里叶逆变换函数
lowp.m切比雪夫低通滤波器函数
showSign2.m格式化绘图函数
%AM.m
clear all
close all
T = 2;%采样时间
N_sample=20000;%每秒采样点数
dt=1/N_sample;%抽样频率
t=0:dt:(T*N_sample-1)*dt;%时间轴
omg1 = 300*2*pi; A1 = 1;
omg2 = 1000*2*pi; A2 = 2;
%基带信号
sign = A1*cos(omg1*t)+A2*cos(omg2*t);
showSign2( t,sign,N_sample );
%基带信号带噪声20dB 信噪比
signNoise = awgn(sign,20);
showSign2( t,signNoise,N_sample );
%调制
A0 = 4; omgc= 5000*2*pi;
Sam = (A0+signNoise).*cos(omgc*t);
showSign2( t,Sam,N_sample );
%相干解调
Sp = Sam.*cos(omgc*t);
showSign2( t,Sp,N_sample );
%低通滤波
SpRe =lowp(Sp,1500,2000,0.1,30,N_sample);
SpRe = SpRe-mean(SpRe);%去直流
showSign2( t,SpRe,N_sample );
%F2T.m
function [t st] = F2T(f,sf)
%calculate the time signal using ifft for the input signal's spectrum
df = f(2)-f(1);
Fmx = (f(end)-f(1)+df);
dt = 1/Fmx;
N = length(sf);
T = dt*N;
t = 0:dt:T-dt;
sff = fftshift(sf);
st = Fmx*ifft(sff);
%T2F.m
function [f,sf] = T2F(t,st)
%%This?is?a?function?using?the?FFT?function?to?calculate?a?signal's?Fourier?%Translation?
%Input?is?the?time?and?the?signal?vectors,the?length?of?time?must?greater?%than?2?
%Output?is?the?frequency?and?the?signal?spectrum
dt = t(2)-t(1);
T =t(end);
df = 1/T;
N = length(st);
f = -N/2*df:df:N/2*df-df;
sf = fft(st);
sf = T/N*fftshift(sf);
%lowp.m
function y=lowp(x,f1,f3,rp,rs,Fs)
%低通滤波
%使用注意事项:通带或阻带的截止频率的选取范围是不能超过采样率的一半
%即,f1,f3的值都要小于 Fs/2
%x:需要带通滤波的序列
% f 1:通带截止频率
% f 3:阻带截止频率
%rp:边带区衰减DB数设置
%rs:截止区衰减DB数设置
%FS:序列x的采样频率
% rp=0.1;rs=30;%通带边衰减DB值和阻带边衰减DB值
% Fs=2000;%采样率
%
wp=2*pi*f1/Fs;
ws=2*pi*f3/Fs;
% 设计切比雪夫滤波器;
[n,wn]=cheb1ord(wp/pi,ws/pi,rp,rs);
[bz1,az1]=cheby1(n,rp,wp/pi);
%查看设计滤波器的曲线
[h,w]=freqz(bz1,az1,256,Fs);
h=20*log10(abs(h));
figure;plot(w,h);title('所设计滤波器的通带曲线');grid on;
%
y=filter(bz1,az1,x);%对序列x滤波后得到的序列y
end
%showSign2.m
function [ ] = showSign2( t,sign,N_sample )
%显示所给信号的,时域图,频谱,估计功率谱
% 此处显示详细说明
[f,signf]= T2F(t,[sign(1:length(t))]);
T = t(2)*length(t);
N = length(t)/N_sample;
figure
subplot(1,3,1)
plot(t,[sign(1:length(t))]);grid on
title('时域波形');
axis([0 0.01 -10 10]);
subplot(1,3,2)
plot(f,10*log10(abs(signf).^2/T));grid on
title('频谱');
ylim([-70,10]);
subplot(1,3,3)
Hs=spectrum.welch;
psd(Hs,sign,'Fs',N_sample)
end
数字基带信号 频谱,功率谱,眼图
baseBand.m主程序,
F2T.m傅里叶变换,T2F傅里叶逆变换函数
sigexpand.m信号采样扩展
showSign.m格式化绘图函数
这里Ts=1,每个码元采样点数为64
%baseBand.m
clear all;
close all;
Ts=1;%码元间隔
N_sample=64;%每个码元的抽样点数
dt=Ts/N_sample;%抽样时间间隔
N=1000;%码元数
t=0:dt:(N*N_sample-1)*dt;%时间轴
T=N*N_sample*dt;%总时间
aBase = ones(1,N_sample);%单极性不归零码(NRZ)
d=(sign(randn(1,N))+1)/2;%生成的随机码元0,1序列
data=sigexpand(d,N_sample);%对序列间隔插入N_sample-1个0
%单极性归零波形
NRZ=conv(data,aBase);
showSign(t,NRZ,N_sample);
d = d*2-1;
data = sigexpand(d,N_sample);
%理想低通
lowPassBase=sinc((t-5*Ts)/Ts);
lowPassBase=lowPassBase(1:10*N_sample);%取理想低通的左右各5个过零点作为冲激波形
lowPass = conv(data,lowPassBase);
showSign(t,lowPass,N_sample);
%滚降
gunJiangBase=sinc((t-5*Ts)/Ts) .* (cos(pi*(t-5*Ts)/Ts)./(1-4*(t-5*Ts).*(t-5*Ts)/Ts^2));
gunJiangBase(289) = (gunJiangBase(288)+gunJiangBase(290))/2;%处理除0点
gunJiangBase(353) = gunJiangBase(289) ;
gunJiangBase=gunJiangBase(1:10*N_sample);%取理想低通的左右各5个过零点作为冲激波形
gunJiang = conv(data,gunJiangBase);
showSign(t,gunJiang,N_sample);
%理想低通带噪声
lowPassNoise = awgn(lowPass,20,'measured');%信噪比20dB
showSign(t,lowPassNoise,N_sample);
%滚降带噪声
gunJiangNoise = awgn(gunJiang,20,'measured');
showSign(t,gunJiangNoise,N_sample);
%showSign.m
function [ ] = showSign( t,sign,N_sample )
%显示所给信号的,时域图,频谱,估计功率谱与眼图
% 此处显示详细说明
[f,signf]= T2F(t,[sign(1:length(t))]);
T = t(2)*length(t);
N = length(t)/N_sample;
figure
subplot(2,2,1)
plot(t,[sign(1:length(t))]);grid on
title('时域波形');
axis([0 20 -1.5 1.5]);
subplot(2,2,2)
plot(f,10*log10(abs(signf).^2/T));grid on
title('频谱');
axis([-5 5 -40 10]);
subplot(2,2,3)
Hs=spectrum.welch;
psd(Hs,sign,'Fs',N_sample)
subplot(2,2,4)
picNumber = 2;
for k = 10:100
plot(sign(k*N_sample+1-floor(N_sample/2):(k+picNumber)*N_sample-floor(N_sample/2)));
hold on;
end
title('眼图')
end
et/stackedit