基于MATLAB的数字调制.docx
《基于MATLAB的数字调制.docx》由会员分享,可在线阅读,更多相关《基于MATLAB的数字调制.docx(26页珍藏版)》请在冰豆网上搜索。
![基于MATLAB的数字调制.docx](https://file1.bdocx.com/fileroot1/2023-1/31/31e86a1c-c071-412b-9211-2c3b6e962891/31e86a1c-c071-412b-9211-2c3b6e9628911.gif)
基于MATLAB的数字调制
2ASK、2FSK、2PSK数字调制系统的Matlab实现及性能分析与比较
引言:
数字带通传输系统为了进行长距离传输,克服传输失真,传输损耗,同时保证带内特性。
必须对数字信号进行载波调制,将信号频谱搬移到高频段才能在信道中传输,因而现代通信系统采取数字调制技术。
通过数字基带信号对载波某些参量进行控制,使之随机带信号的变化而变化。
根据控制载波参量大的不同,数字调制有调幅(ASK),调频(FSK),调相(PSK)三种基本形式。
Matlab用于仿真,分析和修改,还可以应用图形界面功能GUI能为仿真系统生成一个人机交互界面,便于仿真系统的操作,因此采用matlab对数字系统进行仿真。
通过对系统的仿真,我们可以更加直观的了解数字调制系统的性能()及影响性能的因素,从而便于改进系统,获得更佳的传输性能。
关键词:
数字.系统.性能.ASK.FSK.PSK.Matlab.仿真.
一.数字调制与解调原理
1.12ASK
(1)2ASK
2ASK就是把频率、相位作为常量,而把振幅作为变量,信息比特是通过载波的幅度来传递的。
由于调制信号只有0或1两个电平,相乘的结果相当于将载频或者关断,或者接通,它的实际意义是当调制的数字信号"1时,传输载波;当调制的数字信号为"0"时,不传输载波。
公式为:
1.22FSK
2FSK可以看做是2个不同频率的2ASK的叠加,其调制与解调方法与2ASK差不多,主要频率F1和F2,不同的组合产生所要求的2FSK调制信号。
公式如下:
1.32PSK
2PSK以载波的相位变化为基准,载波的相位随数字基带序列信号的1或者0而改变,通常用已经调制完的载波的0或者π表示数据1或者0,每种相位与之一一对应。
二.数字调制技术的仿真实现
本课程设计需要借助MATLAB的M文件编程功能,对2ASK..2PSK.2FSK进行调制与解调的设计,并绘制出调制与解调后的波形,误码率的情况分析,软件仿真可在已有平台上实现。
1.2ASK代码主函数
closeall
clearall
n=16;
fc=1000000;bitRate=1000000;
N=50;
%noise=ti;
noise=10;
signal=source(n,N);%生成二进制代码
transmittedSignal=askModu(signal,bitRate,fc,N);%调制后信号
signal1=gussian(transmittedSignal,noise);%加噪声
configueSignal=demoASK(signal1,bitRate,fc,n,N);
source代码
functionsendSignal=source(n,N)
sendSignal=randint(1,n)
bit=[];
fori=1:
length(sendSignal)
ifsendSignal(i)==0
bit1=zeros(1,N);
else
bit1=ones(1,N);
end
bit=[bit,bit1];
end
figure
(1)
plot(1:
length(bit),bit),title('transmittingofbinary'),gridon;
axis([0,N*length(sendSignal),-2,2]);
end
askModu代码
functiontransmittedSignal=askModu(signal,bitRate,fc,N)%signal为输入信号,bitrate为bit速率,fc调制信号频率,N
%signal=[00101101];
%bitRate=1000000;
%fc=1000000;
%N=32;
t=linspace(0,1/bitRate,N);
c=sin(2*pi*t*fc);
transmittedSignal=[];
fori=1:
length(signal)
transmittedSignal=[transmittedSignal,signal(i)*c];
end
figure
(2)%画调制图
plot(1:
length(transmittedSignal),transmittedSignal);title('ModulationofASK');gridon;
figure(3)%画频谱实部
m=0:
length(transmittedSignal)-1;
F=fft(transmittedSignal);
plot(m,abs(real(F))),title('ASK_frequency-domainanalysisreal');
gridon;
%figure(4)画频谱虚部
%plot(m,imag(F));title('ASK_frequency-domainanalysisimag');
%gridon;
end
CheckRatePe代码
functionPeWrong=CheckRatePe(signal1,signal2,s)
rights=0;
wrongs=0;
forki=1:
s-2
if(signal1(ki)==signal2(ki))
rights=rights+1;
else
wrongs=wrongs+1;
end
end
PeWrong=wrongs/(wrongs+rights);
end
demoASK代码
functionbitstream=demoASK(receivedSignal,bitRate,fc,n,N)
loadnum
signal1=receivedSignal;
signal2=abs(signal1);%ÕûÁ÷
signal3=filter(num1,1,signal2);%LPF,°üÂç¼ì²¨
IN=fix(length(num1)/2);%ÑÓ³Ùʱ¼ä
bitstream=[];
LL=fc/bitRate*N;
i=IN+LL/2;
while(i<=length(signal3))%Åоö
bitstream=[bitstream,signal3(i)>=0.5];
i=i+LL;
end
figure(6)
subplot(3,1,1);%接收波形
plot(1:
length(signal1),signal1);title('Waveofreceivingterminal(includingnoise)');gridon;
subplot(3,1,2);%接收整流后波形
plot(1:
length(signal2),signal2);title('Waveofcommutate');gridon;
subplot(3,1,3);%包络检波波形
plot(1:
length(signal3),signal3);title('WaveofLPF');gridon;
bit=[];
fori=1:
length(bitstream)
ifbitstream(i)==0
bit1=zeros(1,N);
else
bit1=ones(1,N);
end
bit=[bit,bit1];
end
figure(7)%解调后的二进制波形
plot(bit),title('binaryofreceivingterminal'),gridon;
axis([0,N*length(bitstream),-2.5,2.5]);
end
gussian代码%加高斯白噪声
functionsignal=gussian(transmittedSignal,noise)
signal=sqrt
(2)*transmittedSignal;
signal=awgn(signal,noise);
figure(5)
plot(1:
length(signal),signal);
title('Waveincludingnoise'),gridon;
end
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////fsk主函数代码
closeall
clearall
n=16;%二进制代码长度
f1=18000000;%频率1
f2=6000000;%频率2
bitRate=1000000;%bit速率
N=50;%码元宽度
%noise=ti;
noise=10;%家性噪声大小
signal=source(n,N);%产生二进制代码
transmittedSignal=fskModu(signal,bitRate,f1,f2,N);%调制
signal1=gussian(transmittedSignal,noise);%加噪声
configueSignal=demoFSK(signal1,bitRate,f1,f2,N);%解调
source代码%二进制信号产生函数
functionsendSignal=source(n,N)
sendSignal=randint(1,n)
bit=[];
fori=1:
length(sendSignal)
ifsendSignal(i)==0
bit1=zeros(1,N);
else
bit1=ones(1,N);
end
bit=[bit,bit1];
end
figure
(1)
plot(bit),title('transmittingofbinary'),gridon;
axis([0,N*length(sendSignal),-2.5,2.5]);
end
fskModu代码%频率调制函数
functiontransmittedSignal=fskModu(signal,bitRate,f1,f2,N)
t=linspace(0,1/bitRate,N);
c1=sin(2*pi*t*f1);%调制信号1
c2=sin(2*pi*t*f2);%调制信号2
transmittedSignal=[];
fori=1:
length(signal)%调制
ifsignal(i)==1
transmittedSignal=[transmittedSignal,c1];
else
transmittedSignal=[transmittedSignal,c2];
end
end
figure
(2)%画调制后波形图
plot(1:
length(transmittedSignal),transmittedSignal);title('ModulationofFSK');gridon;
figure(3)%画调制后频谱图
m=0:
length(transmittedSignal)-1;
F=fft(transmittedSignal);
plot(m,abs(real(F))),title('ASK_frequency-domainanalysisreal');
gridon;
end
demoFSK代码
functionbitstream=demoFSK(receivedSignal,bitRate,f1,f2,N)
loadnum
signal1=receivedSignal;
signal2=filter(gaotong,1,signal1);%通过HPF,得到高通分量
signal3=abs(signal2);%整流
signal3=filter(lowpass,1,signal3);%通过低通,形成包络
bitstream=[];
IN1=fix(length(lowpass)/2)+fix(length(gaotong)/2);%延迟时间
bitstream1=[];
LL=N;%每个bit的抽样点数
i=IN1+LL/2;
while(i<=length(signal3))%判决
bitstream1=[bitstream1,signal3(i)>=0.5];
i=i+LL;
end
bitstream1
figure(5)
subplot(3,1,1);
plot(1:
length(signal1),signal1);title('Waveofreceivingterminal(includingnoise)');gridon;
subplot(3,1,2);
plot(1:
length(signal2),signal2);title('AfterPassingHPF');gridon;
subplot(3,1,3);
plot(1:
length(signal3),signal3);title('AfterPassingLPF');gridon;
signal4=filter(daitong,1,signal1);%通过BPF得到低频分量
signal5=abs(signal4);%整流
signal5=filter(lowpass,1,signal5);%通过LPF,形成包络
IN2=fix(length(lowpass)/2)+fix(length(daitong)/2);%延迟时间
bitstream2=[];
LL=N;%每个bit的的抽样点数
i=IN2+LL/2;
while(i<=length(signal5))%判决
bitstream2=[bitstream2,signal5(i)>=0.5];
i=i+LL;
end
bitstream2
figure(6)
subplot(3,1,1);
plot(1:
length(signal1),signal1);title('Waveofreceivingterminal(includingnoise)');gridon;
subplot(3,1,2);
plot(1:
length(signal4),signal4);title('AfterPassingBPF');gridon;
subplot(3,1,3);
plot(1:
length(signal5),signal5);title('AfterPassingLPF');gridon;
fori=1:
min(length(bitstream1),length(bitstream2))%判决
if(bitstream1(i)>bitstream2(i))
bitstream(i)=1;
else
bitstream(i)=0;
end
end
bitstream
bit=[];%接收端波形
fori=1:
length(bitstream)
ifbitstream(i)==0
bit1=zeros(1,N);
else
bit1=ones(1,N);
end
bit=[bit,bit1];
end
figure(7)
plot(bit),title('binaryofreceivingterminal'),gridon;
axis([0,N*length(bitstream),-2.5,2.5]);
end
CheckRatePe代码
functionPeWrong=CheckRatePe(signal1,signal2,s)
rights=0;
wrongs=0;
forki=1:
s-2
if(signal1(ki)==signal2(ki))
rights=rights+1;
else
wrongs=wrongs+1;
end
end
PeWrong=wrongs/(wrongs+rights);
end
gussian代码
functionsignal=gussian(transmittedSignal,noise)
signal=sqrt
(2)*transmittedSignal;
signal=awgn(signal,noise);
figure(4)
plot(1:
length(signal),signal),title('AddingNoise');
gridon;
end
2psk主函数代码
closeall
clearall
n=16;%二进制码长
fc=1000000;%载波频率
bitRate=1000000;%信息频率
N=50;%码宽
noise=10;%信道加性噪声大小
signal=source(n,N);%生成二进制代码
transmittedSignal=bpskModu(signal,bitRate,fc,N);%对信号进行调制并进行频
%谱分析
signal1=gussian(transmittedSignal,noise)%加信道噪声
configueSignal=demoBPSK(signal1,bitRate,fc,n,N);%信号解调
source代码
functionsendSignal=source(n,N)
sendSignal=randint(1,n)
bit=[];
fori=1:
length(sendSignal)
ifsendSignal(i)==0
bit1=zeros(1,N);
else
bit1=ones(1,N);
end
bit=[bit,bit1];
end
figure
(1)
plot(bit),title('transmittingofbinary'),gridon;
axis([0,N*length(sendSignal),-2.5,2.5]);
end
bpskModu代码
functiontransmittedSignal=bpskModu(signal,bitRate,fc,N)
t=linspace(0,1/bitRate,N);
c1=sin(2*pi*t*fc);
c2=sin(2*pi*t*fc+pi);
transmittedSignal=[];
fori=1:
length(signal)
ifsignal(i)==1
transmittedSignal=[transmittedSignal,c1];
else
transmittedSignal=[transmittedSignal,c2];
end
end
figure
(2)%画调制图
plot(1:
length(transmittedSignal),transmittedSignal);title('ModulationofBPSK');gridon;
figure(3)%画频谱图
m=0:
length(transmittedSignal)-1;
F=fft(transmittedSignal);
plot(m,abs(real(F))),title('BPSK_frequency-domainanalysisreal');
gridon;
end
CheckRatePe代码
functionPeWrong=CheckRatePe(signal1,signal2,s)
rights=0;
wrongs=0;
forki=1:
s-2
if(signal1(ki)==signal2(ki))
rights=rights+1;
else
wrongs=wrongs+1;
end
end
PeWrong=wrongs/(wrongs+rights);
end
demoBPSK代码
functionbitstream=demoBPSK(receivedSignal,bitRate,fc,n,N)
loadnum%读取num存储的低通滤波用的数据
signal1=receivedSignal;
t=linspace(0,1/bitRate,N);
c=sin(2*pi*t*fc);
signal=[];
fori=1:
n
signal=[signal,c];
end
signal2=signal1.*signal;%乘同频同相sin
signal3=filter(num1,1,signal2);%LPF,包络检波3
IN=fix(length(num1)/2);%Ñ延迟时间
bitstream=[];
LL=fc/bitRate*N;
i=IN+LL/2;
while(i<=length(signal3))%判决
bitstream=[bitstream,signal3(i)>=0];
i=i+LL;
end
figure(5)
subplot(3,1,1);%画接收的包含噪声的波形
plot(1:
length(signal1),signal1);title('Waveofreceivingterminal(includingnoise)');gridon;
subplot(3,1,2);%相干解调波形
plot(1:
length(signal2),signal2);title('AfterMultiplingsinFuction');gridon;
subplot(3,1,3);%包络检波波形
plot(1:
length(signal3),signal3);title('WaveofLPF');gridon;
bit=[];
fori=1:
length(bitstream)
ifbitstream(i)==0
bit1=zeros(1,N);
else
bit1=ones(1,N);
end
bit=[bit,bit1];
end
figure(6)二进制接收信号波形
plot(bit);title('binaryofreceivingterminal');gridon;
axis([0,N*length(bitstream),-2.5,2.5]);
end
gussian代码
functionsignal=gussian(transmittedSignal,noise)
signal=sqrt
(2)*transmittedSignal;
signal=awgn(signal,noise);
figure(4)
plot(1:
length(signal),signal),gridon;
title('Addingno