您好,欢迎访问三七文档
%---------------------------------------------------%初始化数据%---------------------------------------------------clc,clear,closeall;fs=30000;Time_Hold_On=0.1;Num_Unit=fs*Time_Hold_On;one_Level=zeros(1,Num_Unit);two_Level=ones(1,Num_Unit);three_Level=2*ones(1,Num_Unit);four_Level=3*ones(1,Num_Unit);A=1;%thedefaultampilitudeis1w1=300;%初始化载波频率w2=600;w3=900;w4=1200;%---------------------------------------------------%串并转换%---------------------------------------------------Sign_Set=[0,0,1,1,0,1,1,0,1,0,1,0,1,0,0,1]Lenth_Of_Sign_Set=length(Sign_Set);%计算信号长度j=1;forI=1:2:Lenth_Of_Sign_Set%信号分离成两路信号Sign_Set1(j)=Sign_Set(I);Sign_Set2(j)=Sign_Set(I+1);j=j+1;endLenth_Of_Sign=length(Sign_Set1);st=zeros(1,Num_Unit*Lenth_Of_Sign/2);sign_orign=zeros(1,Num_Unit*Lenth_Of_Sign/2);sign_result=zeros(1,Num_Unit*Lenth_Of_Sign/2);t=0:1/fs:Time_Hold_On*Lenth_Of_Sign-1/fs;%---------------------------------------------------%产生基带信号%---------------------------------------------------forI=1:Lenth_Of_Signif((Sign_Set1(I)==0)&(Sign_Set2(I)==0))%00为1电平sign_orign((I-1)*Num_Unit+1:I*Num_Unit)=one_Level;elseif((Sign_Set1(I)==0)&(Sign_Set2(I)==1))%01为2电平sign_orign((I-1)*Num_Unit+1:I*Num_Unit)=two_Level;elseif((Sign_Set1(I)==1)&(Sign_Set2(I)==1))%11为3电平sign_orign((I-1)*Num_Unit+1:I*Num_Unit)=three_Level;else%10为4电平sign_orign((I-1)*Num_Unit+1:I*Num_Unit)=four_Level;endend%---------------------------------------------------%产生频带信号%---------------------------------------------------forI=1:Lenth_Of_Signif((Sign_Set1(I)==0)&(Sign_Set2(I)==0))%00为载波w1st((I-1)*Num_Unit+1:I*Num_Unit)=A*cos(2*pi*w1*t((I-1)*Num_Unit+1:I*Num_Unit));elseif((Sign_Set1(I)==0)&(Sign_Set2(I)==1))%01为载波w2st((I-1)*Num_Unit+1:I*Num_Unit)=A*cos(2*pi*w2*t((I-1)*Num_Unit+1:I*Num_Unit));elseif((Sign_Set1(I)==1)&(Sign_Set2(I)==1))%11为载波w3st((I-1)*Num_Unit+1:I*Num_Unit)=A*cos(2*pi*w3*t((I-1)*Num_Unit+1:I*Num_Unit));else%10为载波w4st((I-1)*Num_Unit+1:I*Num_Unit)=A*cos(2*pi*w4*t((I-1)*Num_Unit+1:I*Num_Unit));endend%---------------------------------------------------%画初始信号图%---------------------------------------------------figuresubplot(2,1,1)plot(t,sign_orign);axis([0,Time_Hold_On*(Lenth_Of_Sign+1),-A/2,3*A+A/2]);title('TheoriginalSignal');grid;subplot(2,1,2)plot(t,st);%thesignalaftermodulationaxis([0,Time_Hold_On*(Lenth_Of_Sign+1),-A,A]);title('thesignalaftermodulation');grid;%---------------------------------------------------%带通滤波器%---------------------------------------------------%-designthebandpass[250250]wp=[2*pi*2502*pi*350];%通带ws=[2*pi*502*pi*500];%阻带[N,wn]=buttord(wp,ws,1,30,'s');[b,a]=butter(N,wn,'bandpass','s');[bz,az]=impinvar(b,a,fs);%映射为数字的dt1=filter(bz,az,st);%带通取出频率w1figuresubplot(2,2,1)plot(t,dt1);axis([0,Time_Hold_On*(Lenth_Of_Sign+1),-(A/2),A+(A/2)]);title('Theelementof300Hz');wp=[2*pi*5502*pi*650];ws=[2*pi*4002*pi*800];[N,wn]=buttord(wp,ws,1,30,'s');[b,a]=butter(N,wn,'bandpass','s');[bz,az]=impinvar(b,a,fs);dt2=filter(bz,az,st);%带通取出频率w2subplot(2,2,2)plot(t,dt2);axis([0,Time_Hold_On*(Lenth_Of_Sign+1),-(A/2),A+(A/2)]);title('Theelementof600Hz');grid;wp=[2*pi*8502*pi*950];ws=[2*pi*7002*pi*1100];[N,wn]=buttord(wp,ws,1,30,'s');[b,a]=butter(N,wn,'bandpass','s');[bz,az]=impinvar(b,a,fs);dt3=filter(bz,az,st);%带通取出频率w3subplot(2,2,3)plot(t,dt3);axis([0,Time_Hold_On*(Lenth_Of_Sign+1),-(A/2),A+(A/2)]);title('Theelementof900Hz');wp=[2*pi*11502*pi*1250];ws=[2*pi*10002*pi*1400];[N,wn]=buttord(wp,ws,1,30,'s');[b,a]=butter(N,wn,'bandpass','s');[bz,az]=impinvar(b,a,fs);dt4=filter(bz,az,st);subplot(2,2,4)plot(t,dt4);axis([0,Time_Hold_On*(Lenth_Of_Sign+1),-(A/2),A+(A/2)]);title('Theelementof1200Hz');%---------------------------------------------------%相干解调%---------------------------------------------------dt1=dt1.*cos(2*pi*w1*t);%解调载波1dt2=dt2.*cos(2*pi*w2*t);%解调载波2dt3=dt3.*cos(2*pi*w3*t);%解调载波3dt4=dt4.*cos(2*pi*w4*t);%解调载波4figuresubplot(2,2,1)plot(t,dt1);axis([0,Time_Hold_On*(Lenth_Of_Sign+1),-(A/2),A+(A/2)]);title('300Hz分量相干解调后的波形');gridsubplot(2,2,2)plot(t,dt2);axis([0,Time_Hold_On*(Lenth_Of_Sign+1),-(A/2),A+(A/2)]);title('600Hz分量相干解调后的波形');grid;subplot(2,2,3)plot(t,dt3);axis([0,Time_Hold_On*(Lenth_Of_Sign+1),-(A/2),A+(A/2)]);title('900Hz分量相干解调后的波形');gridsubplot(2,2,4)plot(t,dt4);axis([0,Time_Hold_On*(Lenth_Of_Sign+1),-(A/2),A+(A/2)]);title('1200Hz分量相干解调后的波形');grid%---------------------------------------------------%低通滤波器%---------------------------------------------------[N,Wn]=buttord(2*pi*50,2*pi*150,3,25,'s');%临界频率采用角频率表示[b,a]=butter(N,Wn,'s');[bz,az]=impinvar(b,a,fs);%映射为数字的dt1=filter(bz,az,dt1);dt2=filter(bz,az,dt2);dt3=filter(bz,az,dt3);dt4=filter(bz,az,dt4);figuresubplot(2,2,1)plot(t,dt1);axis([0,Time_Hold_On*(Lenth_Of_Sign+1),-(A/2),A+(A/2)]);title('300Hz分量低通滤波后的波形');gridsubplot(2,2,2)plot(t,dt2);axis([0,Time
本文标题:4FSK调制和解调
链接地址:https://www.777doc.com/doc-2724218 .html