内容发布更新时间 : 2024/11/17 15:33:58星期一 下面是文章的全部内容请认真阅读。
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(1:length(bit),bit),title('transmitting of binary'),grid on; axis([0,N*length(sendSignal),-2,2]); end
askModu代码
function transmittedSignal=askModu(signal,bitRate,fc,N)%signal为输入信
号,bitrate为bit速率,fc调制信号频率,N %signal=[0 0 1 0 1 1 0 1]; % bitRate=1000000; % fc=1000000;
t=linspace(0,1/bitRate,N); c=sin(2*pi*t*fc); transmittedSignal=[]; for i=1:length(signal)
transmittedSignal=[transmittedSignal,signal(i)*c]; end
figure(2) %画调制图
plot(1:length(transmittedSignal),transmittedSignal);title('Modulation of ASK');grid on;
figure(3)%画频谱实部
m=0:length(transmittedSignal)-1; F=fft(transmittedSignal);
plot(m,abs(real(F))),title('ASK_frequency-domain analysis real'); grid on;
%figure(4) 画频谱虚部
%plot(m,imag(F));title('ASK_frequency-domain analysis imag'); %grid on; end
% N=32;
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
demoASK代码
function bitstream=demoASK(receivedSignal,bitRate,fc,n,N) load num
signal1=receivedSignal;
signal2=abs(signal1); %??á÷
signal3=filter(num1,1,signal2); %LPF,°ü???ì2¨ IN=fix(length(num1)/2); %?ó3ùê±?? bitstream=[]; LL=fc/bitRate*N; i=IN+LL/2;
while (i<=length(signal3)) %?D?? bitstream=[bitstream,signal3(i)>=0.5]; i=i+LL; end
figure(6)
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('Wave of commutate');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(7)%解调后的二进制波形
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(5)
plot(1:length(signal),signal);
title('Wave including noise'),grid on; end
fsk主函数代码
close all clear all
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代码%二进制信号产生函数
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
fskModu代码%频率调制函数
function transmittedSignal=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=[]; 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 FSK');grid on;
figure(3) %画调制后频谱图
m=0:length(transmittedSignal)-1; F=fft(transmittedSignal);
plot(m,abs(real(F))),title('ASK_frequency-domain analysis real'); grid on; end
demoFSK代码
function bitstream=demoFSK(receivedSignal,bitRate,f1,f2,N) load num
signal1=receivedSignal;
signal2=filter(gaotong,1,signal1); %通过HPF,得到高通分量 signal3=abs(signal2); %整流
signal3=filter(lowpass,1,signal3); %通过低通,形成包络 bitstream=[];