基于MATLAB的数字调制Word下载.docx
《基于MATLAB的数字调制Word下载.docx》由会员分享,可在线阅读,更多相关《基于MATLAB的数字调制Word下载.docx(27页珍藏版)》请在冰豆网上搜索。
本课程设计需要借助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];
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];
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));
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);
%接收整流后波形
length(signal2),signal2);
Waveofcommutate'
subplot(3,1,3);
%包络检波波形
length(signal3),signal3);
WaveofLPF'
length(bitstream)
ifbitstream(i)==0
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'
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////fsk主函数代码
%二进制代码长度
f1=18000000;
%频率1
f2=6000000;
%频率2
bitRate=1000000;
%bit速率
%码元宽度
%家性噪声大小
%产生二进制代码
transmittedSignal=fskModu(signal,bitRate,f1,f2,N);
%调制
configueSignal=demoFSK(signal1,bitRate,f1,f2,N);
%解调
source代码%二进制信号产生函数
length(sendSignal)
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
length(signal)%调制
ifsignal(i)==1
transmittedSignal=[transmittedSignal,c1];
transmittedSignal=[transmittedSignal,c2];
figure
(2)%画调制后波形图
ModulationofFSK'
figure(3)%画调制后频谱图
demoFSK代码
functionbitstream=demoFSK(receivedSignal,bitRate,f1,f2,N)
signal2=filter(gaotong,1,signal1);
%通过HPF,得到高通分量
signal3=abs(signal2);
%整流
signal3=filter(lowpass,1,signal3);
%通过低通,形成包络
IN1=fix(length(lowpass)/2)+fix(length(gaotong)/2);
%延迟时间
bitstream1=[];
LL=N;
%每个bit的抽样点数
i=IN1+LL/2;
=length(signal3))%判决
bitstream1=[bitstream1,signal3(i)>
bitstream1
figure(5)
AfterPassingHPF'
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=[];
%每个bit的的抽样点数
i=IN2+LL/2;
=length(signal5))%判决
bitstream2=[bitstream2,signal5(i)>
bitstream2
figure(6)
length(signal4),signal4);
AfterPassingBPF'
subplot(3,1,3);
length(signal5),signal5);
min(length(bitstream1),length(bitstream2))%判决
if(bitstream1(i)>
bitstream2(i))
bitstream(i)=1;
bitstream(i)=0;
bitstream
%接收端波形
end
figure(7)
gussian代码
figure(4)
plot(1:
length(signal),signal),title('
AddingNoise'
gridon;
2psk主函数代码
%二进制码长
%载波频率
%信息频率
%码宽
%信道加性噪声大小
%生成二进制代码
transmittedSignal=bpskModu(signal,bitRate,fc,N);
%对信号进行调制并进行频
%谱分析
signal1=gussian(transmittedSignal,noise)%加信道噪声
configueSignal=demoBPSK(signal1,bitRate,fc,n,N);
%信号解调
bpskModu代码
functiontransmittedSignal=bpskModu(signal,bitRate,fc,N)
c1=sin(2*pi*t*fc);
c2=sin(2*pi*t*fc+pi);
figure
(2)%画调制图
ModulationofBPSK'
figure(3)%画频谱图
BPSK_frequency-domainanalysisreal'
demoBPSK代码
functionbitstream=demoBPSK(receivedSignal,bitRate,fc,n,N)
loadnum%读取num存储的低通滤波用的数据
signal=[];
n
signal=[signal,c];
signal2=signal1.*signal;
%乘同频同相sin
%LPF,包络检波3
延迟时间
=0];
%画接收的包含噪声的波形
%相干解调波形
AfterMultiplingsinFuction'
figure(6)二进制接收信号波形
plot(bit);
length(signal),signal),gridon;
tit