clc;clear
%%已知
%信道编码
G = [1 0 0 0 1 1 1;0 1 0 0 1 1 0;0 0 1 0 1 0 1;0 0 0 1 0 1 1]; %生成矩阵
H = [1 1 1 0 1 0 0;1 1 0 1 0 1 0;1 0 1 1 0 0 1]; %校验矩阵
Etab = [0 0 0 0 0 0 0;1 0 0 0 0 0 0;
0 1 0 0 0 0 0;0 0 1 0 0 0 0;
0 0 0 1 0 0 0;0 0 0 0 1 0 0;
0 0 0 0 0 1 0;0 0 0 0 0 0 1]; %错误图样
Smatrix = Etab*H'; %误码标志
%%调试
[A, Fs] = audioread('sunday_2.wav');
[l,M] = gener_audio(A);
x=l;
%%
% 系统main函数
% 已知发送信号
x=pcm_coding(x);%量化信息
bitcoded_PCM = channelcoding(x,G,4);
%调制信息
a=4;%1,2qpsk;3gsm;4tdma
if a==1
[ya,Phase,F] = QPSK_Modulation(bitcoded_PCM);
RF_before = RF_updispose800(ya);
elseif a==2
[ya,Phase,F] = QPSK_Modulation(bitcoded_PCM);
RF_before = RF_updispose900(ya);
elseif a==3
ya=qam16(bitcoded_PCM);
RF_before = RF_updispose1800(ya);
elseif a==4
[ya, L_pcm, t, long, Ms, n] = tdma_source(l,M,G);
RF_before = RF_updispose1900(ya);
end
%%发送信息
%上第一中频
%上第二中频
%高斯白信道
db=40;
%yawgn=awgn(RF_before,db);
yawgn=RF_before;
%%接收信号
%智能天线
%b=findf(yawgn)%b=1*矩阵,为1为有当前频率
b=[0 0 0 1];
%四种按频率从小到大依次为qpsk,8psk,16qam,qpsk
pb=zeros(1,4);
if b(1)==1
fc=882e6;
%处理第一种qpsk
%下变频
RF_after = RF_downdispose800(fc,yawgn);
%信号解调
yout = QPSK_Demodulation(RF_after,F,Phase);
bitdecoded = channeldecoding(yout,Etab,Smatrix,H,7,4);
bitdecoded_re = correct(bitdecoded);
Pb(1) = length(find(bitdecoded_re~=x))/length(x)
end
if b(2)==1
fc=948e6;
%处理第二种qpsk
%下变频
RF_after = RF_downdispose900(fc,yawgn);
%信号解调
yout= QPSK_Demodulation(RF_after,F,Phase);
bitdecoded = channeldecoding(yout,Etab,Smatrix,H,7,4);
bitdecoded_re = correct(bitdecoded);
Pb(2) = length(find(bitdecoded_re~=x))/length(x)
end
if b(3)==1
fc=1850e6;
%处理第三种16qam
%下变频
RF_after = RF_downdispose1800(fc,yawgn);
%信号解调
yout=qam16de(RF_after);
bitdecoded = channeldecoding(yout,Etab,Smatrix,H,7,4);
bitdecoded_re = correct(bitdecoded);
Pb(3) = length(find(bitdecoded_re~=x))/length(x)
end
if b(4)==1
fc=1960e6;
%下变频
RF_after = RF_downdispose1900(fc,yawgn);
[audio, cost, delta] = tdma_recover(RF_after, l, L_pcm, t, long, Ms, n, Etab, Smatrix, H);
%处理第四种8pam
% yout=audio;
% bitdecoded = channeldecoding(yout,Etab,Smatrix,H,7,4);
% bitdecoded_re = correct(bitdecoded);
% Pb(4) = length(find(bitdecoded_re~=x))/length(x)
end
max=1;
for i=1:length(pb)
if pb(i)==0
pb(i)=max;
end
end
c=min(pb);
aa=find(c==pb)
%接收信号
%还原信号