.
end end
PeWrong=wrongs/(wrongs+rights); end
gussian代码
function signal=gussian(transmittedSignal,noise) signal=sqrt(2)*transmittedSignal; signal=awgn(signal,noise); figure(4)
plot(1:length(signal),signal),title('Adding Noise'); grid on; end
2psk主函数代码
close all clear all 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代码
function sendSignal=source(n,N) sendSignal=randint(1,n) bit=[];
for i=1:length(sendSignal) if sendSignal(i)==0 bit1=zeros(1,N); else
bit1=ones(1,N); end
bit=[bit,bit1]; end figure(1)
plot(bit),title('transmitting of binary'),grid on;
'.
.
axis([0,N*length(sendSignal),-2.5,2.5]); end
bpskModu代码
function transmittedSignal=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=[]; for i=1:length(signal) if signal(i)==1
transmittedSignal=[transmittedSignal,c1]; else
transmittedSignal=[transmittedSignal,c2]; end end
figure(2) % 画调制图
plot(1:length(transmittedSignal),transmittedSignal);title('Modulation of BPSK');grid on;
figure(3)%画频谱图
m=0:length(transmittedSignal)-1; F=fft(transmittedSignal);
plot(m,abs(real(F))),title('BPSK_frequency-domain analysis real'); grid on; end
CheckRatePe代码
function PeWrong=CheckRatePe(signal1,signal2,s) rights=0; wrongs=0; for ki=1:s-2
if(signal1(ki)==signal2(ki)) rights=rights+1; else
wrongs=wrongs+1; end end
PeWrong=wrongs/(wrongs+rights);
'.
.
end
demoBPSK代码
function bitstream=demoBPSK(receivedSignal,bitRate,fc,n,N) load num %读取num存储的低通滤波用的数据 signal1=receivedSignal; t=linspace(0,1/bitRate,N); c=sin(2*pi*t*fc); signal=[]; for i=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('Wave of receiving terminal(including noise)');grid on;
subplot(3,1,2);%相干解调波形
plot(1:length(signal2),signal2);title('After Multipling sin Fuction');grid on;
subplot(3,1,3);%包络检波波形
plot(1:length(signal3),signal3);title('Wave of LPF');grid on; bit=[];
for i=1:length(bitstream) if bitstream(i)==0 bit1=zeros(1,N); else
bit1=ones(1,N); end
bit=[bit,bit1]; end
figure(6)二进制接收信号波形
'.
.
plot(bit);title('binary of receiving terminal');grid on; axis([0,N*length(bitstream),-2.5,2.5]); end
gussian代码
function signal=gussian(transmittedSignal,noise) signal=sqrt(2)*transmittedSignal; signal=awgn(signal,noise); figure(4)
plot(1:length(signal),signal),grid on; title('Adding noise') end
三种调制方式的性能比较:
load PeRate; load PeRatep; %补偿误差
fpeask(15)=1e-3; fpefsk(9)=1e-3; fpepsk(24)=0.002; fpepsk(26)=1e-3; figure(1)
semilogy(-6:length(fpeask)-7,fpeask,-6:length(fpefsk)-7,fpefsk,-30:length(fpepsk)-31,fpepsk),grid on; title('Analysis Of Bit Error Rate'); legend('ASK','FSK','PSK'); xlabel('r/dB'); ylabel('Pe');
figure(2)
semilogy(-6:length(fpefsk)-7,fpeask);grid on; title('Bit Error Rate Of ASK'); xlabel('r/dB'); ylabel('PeASK'); figure(3)
semilogy(-6:length(fpefsk)-7,fpefsk);grid on; title('Bit Error Rate Of FSK'); xlabel('r/dB'); ylabel('PeFSK'); figure(4)
semilogy(-16:length(fpepsk)-17,fpepsk);grid on; title('Bit Error Rate Of PSK'); axis([-16,10,1e-3,1]);
'.
.
xlabel('r/dB'); ylabel('PePSK');
三.程序与调制解调波形 3.1 2ASK波形 1随机信号产生
2ASK信号调制
'.