📄 cpfsk1rect.m
字号:
%2-CPM,1_rect
%采用最优的ML相干接收机 未调通
clear
clc
L=1;%full response
Rb=2400;%bit rate
Tb=1/Rb;
Fs=8*Rb;%sample rate
h=1/2;%modulation index
Fc=0.5*Rb;%carrier frequency
N_sample=Fs/Rb;
N_observe=3;
N=5000;%Data number
N_back=N;
Ik=round(rand(1,N));%Data
Ik_back=Ik;%back up the Data
Ik=[Ik,zeros(1,N_observe-1)];
Ik_temp=2*Ik-1;
% t=0:1/Fs:(N*Tb-1/Fs);
Num=length(Ik);
faik_temp=0;%original phase
faik=zeros(1,N*Fs/Rb);
for i=1:Num
for k=0:(Fs/Rb-1)
faik((i-1)*(Fs/Rb)+k+1)=faik_temp+Ik_temp(i)*2*pi*h*(k/(2*N_sample));
% faik_bak=faik((i-1)*(Fs/Rb)+k+1);
end
% faik_temp=faik_bak+Ik_temp(i)*2*pi*h*(Rb/(2*Fs));
faik_temp=faik_temp+pi*h*Ik(i);
end
modu_out=exp(j*faik);%baseband output
% Modu=cos(2*pi*Fc*t+faik);%RF output
% plot(Modu);
snr=10;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Channel
sigma=sqrt(0.5*(Fs/Rb)*10^(-snr/10));
N=length(modu_out);
r_real=real(modu_out)+sigma*randn(1,N);
r_imag=imag(modu_out)+sigma*randn(1,N);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Detection
I_10=[1 -1 -1];
I_11=[1 -1 1];
I_12=[1 1 -1];
I_13=[1 1 1];
I_20=[-1 -1 -1];
I_21=[-1 -1 1];
I_22=[-1 1 -1];
I_23=[-1 1 1];
Ik_possible=[I_10;I_11;I_12;I_13;I_20;I_21;I_22;I_23];
Num_temp=2^N_observe;%the number of the metrics to calculate
result=[];
faik_temp=0;
for i=1:N_back
r_real_temp=r_real((i-1)*N_sample+1:(i-1+N_observe)*N_sample);
r_imag_temp=r_imag((i-1)*N_sample+1:(i-1+N_observe)*N_sample);
lemda=[];
for k=1:Num_temp
faik_back=faik_temp;
Ik_temp=Ik_possible(k,:);
% faik_temp=0;
faik=zeros(1,N_observe*Fs/Rb);
for i_temp=1:N_observe
for k_temp=0:(Fs/Rb-1)
faik((i_temp-1)*N_sample+k_temp+1)=faik_temp+Ik_temp(i_temp)*2*pi*h*(k_temp/(2*N_sample));
% faik_bak=faik((i_temp-1)*N_sample+k_temp+1);
end
% faik_temp=faik_bak+Ik_temp(i)*2*pi*h*(Rb/(2*Fs));
faik_temp=faik_temp+pi*h*Ik_temp(i_temp);
end
modu_temp=exp(j*faik);
Real_modu=real(modu_temp);
Imag_modu=imag(modu_temp);
lemda_temp=abs(sum(r_real_temp.*Real_modu+r_imag_temp.*Imag_modu));
lemda=[lemda,lemda_temp];%save the metrics
end
lemda1=max(lemda(1:(Num_temp/2)));
lemda2=max(lemda((Num_temp/2+1):Num_temp));
if lemda1>lemda2
result=[result,1];
faik_temp=rem(faik_back+pi*h,2*pi);
else
result=[result,-1];
faik_temp=rem(faik_back-pi*h,2*pi);
end
end
result=(result+1)/2;
[Num_error error_ratio]=biterr(result,Ik_back)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -