本文共 2628 字,大约阅读时间需要 8 分钟。
实现二进制数字调制与解调信号的仿真是我的MATLAB课程设计的一部分,我参考了网上的一些资料,并加入了一些自己的想法,代码已在本地MATLAB编译通过且能正常运行
2FSK——二进制频移键控
i=10;%基带信号码元数j=5000;t=linspace(0,5,j);%0-5之间产生5000个点行矢量,即将[0,5]分成5000份f1=10;%载波1频率f2=5;%载波2频率fm=i/5;%基带信号频率 码元数是10,而时域长度是5,也就是一个单位2个码元a=round(rand(1,i));%产生随机序列%产生基带信号st1=t;for n=1:10 if a(n)<1 for m=j/i*(n-1)+1:j/i*n st1(m)=0; end else for m=j/i*(n-1)+1:j/i*n st1(m)=1; end endendfigure(1);subplot(411);plot(t,st1);title('基带信号st1');axis([0,5,-1,2]);%基带信号求反st2=t;for n=1:j if st1(n)==1 st2(n)=0; else st2(n)=1; endendsubplot(412);plot(t,st2);title('基带信号反码st2');axis([0,5,-1,2]);%载波信号s1=cos(2*pi*f1*t);s2=cos(2*pi*f2*t);subplot(413),plot(s1);title('载波信号s1');subplot(414),plot(s2);title('载波信号s2');%调制F1=st1.*s1;%加入载波1F2=st2.*s2;%加入载波2figure(2);subplot(411);plot(t,F1);title('F1=s1*st1');subplot(412);plot(t,F2);title('F2=s2*st2');e_fsk=F1+F2;subplot(413);plot(t,e_fsk);title('2FSK信号');%键控法产生的信号在相邻码元之间相位不一定连续%加噪nosie=rand(1,j);fsk=e_fsk+nosie;subplot(414);plot(t,fsk);title('加噪声后信号')%相干解调st1=fsk.*s1; %与载波1相乘[f,sf1] = T2F(t,st1);%傅里叶变换[t,st1] = lpf(f,sf1,2*fm);%通过低通滤波器figure(3);subplot(311);plot(t,st1);title('加噪后的信号与s1相乘后波形');st2=fsk.*s2;%与载波2相乘[f,sf2] = T2F(t,st2);%通过低通滤波器[t,st2] = lpf(f,sf2,2*fm);subplot(312);plot(t,st2);title('加噪后的信号与s2相乘后波形');%抽样判决for m=0:i-1 if st1(1,m*500+250)>st2(1,m*500+250) for j=m*500+1:(m+1)*500 at(1,j)=1; end else for j=m*500+1:(m+1)*500 at(1,j)=0; end endendsubplot(313);plot(t,at);axis([0,5,-1,2]);title('抽样判决后波形')
用到的函数
①T2F.m
function [f,sf]= T2F(t,st)%利用FFT计算信号的频谱并与信号的真实频谱的抽样比较。%脚本文件T2F.m定义了函数T2F,计算信号的傅立叶变换。%Input is the time and the signal vectors,the length of time must greater%than 2%Output is the frequency and the signal spectrumdt = 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);②F2T.m
function [t,st]=F2T(f,sf)%脚本文件F2T.m定义了函数F2T,计算信号的反傅立叶变换。%This function calculate the time signal using ifft function for the inputdf = f(2)-f(1);Fmx = ( f(end)-f(1) +df);dt = 1/Fmx;N = length(sf);T = dt*N;%t=-T/2:dt:T/2-dt;t = 0:dt:T-dt;sff = fftshift(sf);st = Fmx*ifft(sff);③lpf.m
function [t,st]=lpf(f,sf,B)%This function filter an input data using a lowpass filter%Inputs: f: frequency samples% sf: input data spectrum samples% B: lowpass bandwidth with a rectangle lowpass%Outputs: t: time samples% st: output data time samplesdf = f(2)-f(1);T = 1/df;hf = zeros(1,length(f));%全零矩阵bf = [-floor( B/df ): floor( B/df )] + floor( length(f)/2 );hf(bf)=1;yf=hf.*sf;[t,st]=F2T(f,yf);st = real(st);
转载地址:http://vwfgf.baihongyu.com/