基于MATLAB仿真的2ASK2PSK2FSK性能比较和分析Word文件下载.docx
《基于MATLAB仿真的2ASK2PSK2FSK性能比较和分析Word文件下载.docx》由会员分享,可在线阅读,更多相关《基于MATLAB仿真的2ASK2PSK2FSK性能比较和分析Word文件下载.docx(28页珍藏版)》请在冰豆网上搜索。
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];
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=[];
length(signal)
transmittedSignal=[transmittedSignal,signal(i)*c];
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'
%figure(4)画频谱虚部
%plot(m,imag(F));
title('
ASK_frequency-domainanalysisimag'
%gridon;
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;
PeWrong=wrongs/(wrongs+rights);
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;
figure(6)
subplot(3,1,1);
%接收波形
length(signal1),signal1);
Waveofreceivingterminal(includingnoise)’);
subplot(3,1,2);
%接收整流后波形
plot(1:
length(signal2),signal2);
Waveofcommutate’);
gridon;
subplot(3,1,3);
%包络检波波形
length(signal3),signal3);
title(’WaveofLPF’);
bit=[];
fori=1:
length(bitstream)
ifbitstream(i)==0
bit1=zeros(1,N);
bit1=ones(1,N);
bit=[bit,bit1];
figure(7)%解调后的二进制波形
plot(bit),title(’binaryofreceivingterminal'
axis([0,N*length(bitstream),-2。
5,2.5]);
gussian代码%加高斯白噪声
functionsignal=gussian(transmittedSignal,noise)
signal=sqrt
(2)*transmittedSignal;
signal=awgn(signal,noise);
figure(5)
length(signal),signal);
title(’Waveincludingnoise’),gridon;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////fsk主函数代码
%二进制代码长度
f1=18000000;
%频率1
f2=6000000;
%频率2
bitRate=1000000;
%bit速率
%码元宽度
%noise=ti;
noise=10;
%家性噪声大小
signal=source(n,N);
%产生二进制代码
transmittedSignal=fskModu(signal,bitRate,f1,f2,N);
%调制
configueSignal=demoFSK(signal1,bitRate,f1,f2,N);
%解调
source代码%二进制信号产生函数
functionsendSignal=source(n,N)
sendSignal=randint(1,n)
length(sendSignal)
bit1=zeros(1,N);
bit1=ones(1,N);
bit=[bit,bit1];
plot(bit),title('
),gridon;
axis([0,N*length(sendSignal),—2。
5,2。
5]);
fskModu代码%频率调制函数
functiontransmittedSignal=fskModu(signal,bitRate,f1,f2,N)
c1=sin(2*pi*t*f1);
%调制信号1
c2=sin(2*pi*t*f2);
%调制信号2
transmittedSignal=[];
length(signal)%调制
ifsignal(i)==1
transmittedSignal=[transmittedSignal,c1];
transmittedSignal=[transmittedSignal,c2];
figure
(2)%画调制后波形图
length(transmittedSignal),transmittedSignal);
title(’ModulationofFSK’);
figure(3)%画调制后频谱图
m=0:
length(transmittedSignal)—1;
F=fft(transmittedSignal);
plot(m,abs(real(F))),title(’ASK_frequency—domainanalysisreal’);
demoFSK代码
functionbitstream=demoFSK(receivedSignal,bitRate,f1,f2,N)
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;
bitstream1
figure(5)
subplot(3,1,1);
length(signal1),signal1);
title(’Waveofreceivingterminal(includingnoise)'
);
subplot(3,1,2);
length(signal2),signal2);
title(’AfterPassingHPF’);
subplot(3,1,3);
title(’AfterPassingLPF’);
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];
bitstream2
figure(6)
subplot(3,1,1);
subplot(3,1,2);
length(signal4),signal4);
title(’AfterPassingBPF’);
length(signal5),signal5);
AfterPassingLPF'
min(length(bitstream1),length(bitstream2))%判决
if(bitstream1(i)>
bitstream2(i))
bitstream(i)=1;
bitstream(i)=0;
bitstream
%接收端波形
bit1=zeros(1,N);
bit=[bit,bit1];
figure(7)
plot(bit),title('
binaryofreceivingterminal'
),gridon;
axis([0,N*length(bitstream),-2。
5]);
functionPeWrong=CheckRatePe(signal1,signal2,s)
s-2
gussian代码
functionsignal=gussian(transmittedSignal,noise)
signal=sqrt
(2)*transmittedSignal;
signal=awgn(signal,noise);
figure(4)
length(signal),signal),title(’AddingNoise’);
gridon;
2psk主函数代码
%二进制码长
fc=1000000;
%载波频率
bitRate=1000000;
信息频率
N=50;
%码宽
%信道加性噪声大小
生成二进制代码
transmittedSignal=bpskModu(signal,bitRate,fc,N);
对信号进行调制并进行频谱分析
signal1=gussian(transmittedSignal,noise)%加信道噪声
configueSignal=demoBPSK(signal1,bitRate,fc,n,N);
%信号解调
bit=[];
plot(bit),title(’transmittingofbinary’),gridon;
axis([0,N*length(sendSignal),-2。
5,2.5]);
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=[];
transmittedSignal=[transmittedSignal,c1];
transmittedSignal=[transmittedSignal,c2];
figure
(2)%画调制图
length(transmittedSignal),transmittedSignal);
title(’ModulationofBPSK'
figure(3)%画频谱图
BPSK_frequency-domainanalysisreal'
rights=0;
wrongs=0;
wrongs=wrongs+1;
demoBPSK代码
functionbitstream=demoBPSK(receivedSignal,bitRate,fc,n,N)
loadnum%读取num存储的低通滤波用的数据
signal1=receivedSignal;
c=sin(2*pi*t*fc);
signal=[];
n
signal=[signal,c];
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;
bitstream=[bitstream,signal3(i)>
=0];
%画接收的包含噪声的波形
title(’Waveofreceivingterminal(includingnoise)’);
subplot(3,1,2);
%相干解调波形
title(’AfterMultiplingsinFuction'
subplot(3,1,3);
%包络检波波形
length(signal3),signal3);
title(’WaveofLPF'
figure(6)二进制接收信号波形
plot(bit);
title(’binaryofreceivingterminal’);
axis([0,N*length(bitstream),—2。
5]);