%Function:(7,4)Hamming Code and 4FSK Modulation
%Author:HarryChing
%Date:2012/11/03
%Testbench:Matlab R2008a
function main
N=1200;%Set data bits of random binary number
K=7*N/4;%The data bits after(7,4)Hamming Code
M = 4;%4FSK
SNRpBit=0:2:20;%Signal to Noise Ratio per bit
SNR=SNRpBit./log2(M);%Signal to Noise Ratio per symbol
x=randint(1,N,2);%Generate N bits binary number
x1=hammingcode(x);%Hamming Code
x2=reshape(x1,K/2,2);%1*K array to 2*K/2 array
x3=bi2de(x2);%Change 2 to 4 scale
x4=reshape(x3,1,K/2);%Reshape to 1*K/2 array
figure(1)
bar(x4);
axis([0 4.5 0 3])
title('随机产生的数字信息','FontName','楷体','FontSize',20)
y = fsk4mod(x4);%4FSK modulation
y1 = raychannel(y);%4FSK pass Rayleigh Channel
y11 = raymultipathchannel(y);%4FSK pass Rayleigh Multi-path Channel
%%%%%%The BER of two channel models is as follows%%%%%%
for i = 1:length(SNR)
if i==1
y2=awgnchannel(y1,SNR(i));%Pass Gaussian noise Channel
Fs=1280;%Sampling Frequency
numPlot=4;%Set plot number
numModPlot=numPlot*Fs;
t=[0:numModPlot-1]./Fs;
figure(5)
plot(t,y2(1:length(t)));
title('瑞利信道下加入高斯白噪声后的4FSK信号','FontSize',20)
xlabel('Time','FontSize',15);
ylabel('Amplitude','FontSize',15);
y3=fsk4demod(y2);
y4=reshape(y3,K/2,1);
y5=de2bi(y4);
y6=reshape(y5,1,K);
y7=decode(y6,7,4,'hamming');
[errorSym ratioSym]=symerr(x,y7);
Pe1(i)=ratioSym;
else
y2=awgnchannel(y1,SNR(i));%Pass Gaussian noise Channel
y3=fsk4demod(y2);
y4=reshape(y3,K/2,1);
y5=de2bi(y4);
y6=reshape(y5,1,K);
y7=decode(y6,7,4,'hamming');
[errorSym ratioSym]=symerr(x,y7);
Pe1(i)=ratioSym;
end
end
for i = 1:length(SNR)
if i==1
y22=awgnchannel(y11,SNR(i));%Pass Gaussian noise Channel
Fs=1280;%Sampling Frequency
numPlot=4;%Set plot number
numModPlot=numPlot*Fs;
t=[0:numModPlot-1]./Fs;
figure(6)
plot(t,y2(1:length(t)));
title('多径信道下加入高斯白噪声后的4FSK信号','FontSize',20)
xlabel('Time','FontSize',15);
ylabel('Amplitude','FontSize',15);
y33=fsk4demod(y22);
y44=reshape(y33,K/2,1);
y55=de2bi(y44);
y66=reshape(y55,1,K);
y77=decode(y66,7,4,'hamming');
[errorSym ratioSym]=symerr(x,y77);
Pe11(i)=ratioSym;
else
y22=awgnchannel(y11,SNR(i));%Pass Gaussian noise Channel
y33=fsk4demod(y22);
y44=reshape(y33,K/2,1);
y55=de2bi(y44);
y66=reshape(y55,1,K);
y77=decode(y66,7,4,'hamming');
[errorSym ratioSym]=symerr(x,y77);
Pe11(i)=ratioSym;
end
end
figure(7)
semilogy(SNR,Pe1,'o-b',SNR,Pe11,'*-r','LineWidth',3);
xlabel('SNR','FontSize',15);
ylabel('Pe','FontSize',15);
legend('瑞利信道','多径信道')
title('不同信道下误码率-信噪比曲线','FontName','楷体','FontSize',20)
grid on
- 1
- 2
前往页