MATLAB实现的Reed-Muller(RM码,里德-马勒编码)编码解码纠错以及BER分析
MATLAB實(shí)現(xiàn)的Reed-Muller編碼解碼糾錯(cuò)以及BER分析
- 背景
- 代碼
- 計(jì)算BER
- 計(jì)算不使用RM編碼情況時(shí)的BER(模擬環(huán)境與理論情況)
- 與漢明編碼做對(duì)比
- 總結(jié)
背景
本科時(shí)信息論與編碼的作業(yè),RM(2,4)編碼
課程為
Information Theory & Coding Vaibhav Kumar, PhD School of Electrical & Electronic Engineering University College Dublin – The Republic of Ireland下述作業(yè)也是老師布置的,如果涉及到版權(quán)問題我會(huì)刪掉該博客。流程邏輯如下:
數(shù)據(jù)->RM編碼->BPSK調(diào)制->加入AWGN(模擬傳輸時(shí)的噪聲)->BPSK解調(diào)->解碼(Majority-Logic解碼)->輸出數(shù)據(jù)
給定生成矩陣為
v0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v4 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 v3 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 v2 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 v1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 v3v4 = 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 v2v4 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 v1v4 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 v2v3 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 v1v3 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1 v1v2 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1接收到的數(shù)據(jù)可以寫成r=v+e的格式
代碼
clc,clear Eb_N0_log=0:0.5:10; %dB Eb_N0=10.^(Eb_N0_log/10); R_coded=11/16; %R BER_coded=zeros(1,21); %store BER in different Eb/N0 G=[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1; %v00 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1; %v40 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1; %v30 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1; %v20 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1; %v10 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1; %v3v40 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1; %v2v40 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1; %v1v40 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1; %v2v30 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1; %v1v30 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1; %v1v2]; %generator matrix for i=1:21 %calculate BER in different Eb/N0SNR_coded=2*R_coded*Eb_N0(i); %calculate SNRmessage=round(rand(1,1980000)); %generate original data u = (a0 a4 a3 a2 a1 a34 a24 a14 a23 a13 a12),px_w=1; %signal's powerpn_w=px_w/SNR_coded; %noise's powererror_number=0; %error bit numberfor index=1:180000 %90000 blocksm=message(1,11*index-10:11*index);%m=[message(11*index-10),message(11*index-9),message(11*index-8),message(11*index-7),message(11*index-6),message(11*index-5),message(11*index-4),message(11*index-3),message(11*index-2),message(11*index-1),message(11*index)]; %one blobk datav=mod(m*G,2); %generate vmessage_modul=1-v*2; %0->1,1->-1 modulationr=message_modul+sqrt(pn_w)*randn(1,16); %add white Gaussian noiser=r<0; %demodulationa12=sum([mod(r(1)+r(2)+r(3)+r(4),2),mod(r(5)+r(6)+r(7)+r(8),2),mod(r(9)+r(10)+r(11)+r(12),2),mod(r(13)+r(14)+r(15)+r(16),2)]==1);if a12>2a12=1;elseif a12<2a12=0;elsea12=round(rand());end %check-sums for a12a13=sum([mod(r(1)+r(2)+r(5)+r(6),2),mod(r(3)+r(4)+r(7)+r(8),2),mod(r(9)+r(10)+r(13)+r(14),2),mod(r(11)+r(12)+r(15)+r(16),2)]==1);if a13>2a13=1;elseif a13<2a13=0;elsea13=round(rand());end %check-sums for a13a23=sum([mod(r(1)+r(3)+r(5)+r(7),2),mod(r(2)+r(4)+r(6)+r(8),2),mod(r(9)+r(11)+r(13)+r(15),2),mod(r(10)+r(12)+r(14)+r(16),2)]==1);if a23>2a23=1;elseif a23<2a23=0;elsea23=round(rand());end %check-sums for a23a14=sum([mod(r(1)+r(2)+r(9)+r(10),2),mod(r(3)+r(4)+r(11)+r(12),2),mod(r(5)+r(6)+r(13)+r(14),2),mod(r(7)+r(8)+r(15)+r(16),2)]==1);if a14>2a14=1;elseif a14<2a14=0;elsea14=round(rand());end %check-sums for a14a24=sum([mod(r(1)+r(3)+r(9)+r(11),2),mod(r(2)+r(4)+r(10)+r(12),2),mod(r(5)+r(7)+r(13)+r(15),2),mod(r(6)+r(8)+r(14)+r(16),2)]==1);if a24>2a24=1;elseif a24<2a24=0;elsea24=round(rand());end %check-sums for a24a34=sum([mod(r(1)+r(5)+r(9)+r(13),2),mod(r(2)+r(6)+r(10)+r(14),2),mod(r(3)+r(7)+r(11)+r(15),2),mod(r(4)+r(8)+r(12)+r(16),2)]==1);if a34>2a34=1;elseif a34<2a34=0;elsea34=round(rand());end %check-sums for a34r=mod(r-a12*G(11,:)-a13*G(10,:)-a23*G(9,:)-a14*G(8,:)-a24*G(7,:)-a34*G(6,:),2);a1=sum([mod(r(1)+r(2),2),mod(r(3)+r(4),2),mod(r(5)+r(6),2),mod(r(7)+r(8),2),mod(r(9)+r(10),2),mod(r(11)+r(12),2),mod(r(13)+r(14),2),mod(r(15)+r(16),2),]==1);if a1>4a1=1;elseif a1<4a1=0;elsea1=round(rand());end %check-sums for a1a2=sum([mod(r(1)+r(3),2),mod(r(2)+r(4),2),mod(r(5)+r(7),2),mod(r(6)+r(8),2),mod(r(9)+r(11),2),mod(r(10)+r(12),2),mod(r(13)+r(15),2),mod(r(14)+r(16),2),]==1);if a2>4a2=1;elseif a2<4a2=0;elsea2=round(rand());end %check-sums for a2a3=sum([mod(r(1)+r(5),2),mod(r(2)+r(6),2),mod(r(3)+r(7),2),mod(r(4)+r(8),2),mod(r(9)+r(13),2),mod(r(10)+r(14),2),mod(r(11)+r(15),2),mod(r(12)+r(16),2),]==1);if a3>4a3=1;elseif a3<4a3=0;elsea3=round(rand());end %check-sums for a3a4=sum([mod(r(1)+r(9),2),mod(r(2)+r(10),2),mod(r(3)+r(11),2),mod(r(4)+r(12),2),mod(r(5)+r(13),2),mod(r(6)+r(14),2),mod(r(7)+r(15),2),mod(r(8)+r(16),2),]==1);if a4>4a4=1;elseif a4<4a4=0;elsea4=round(rand());end %check-sums for a4r=mod(r-a1*G(5,:)-a2*G(4,:)-a3*G(3,:)-a4*G(2,:),2);a0=sum(r==1);if a0>8a0=1;elseif a0<8a0=0;elsea0=round(rand());end %check-sums for a0signal=[a0,a4,a3,a2,a1,a34,a24,a14,a23,a13,a12];error_number=error_number+sum(sum(signal~=m)); %find the number of error bitsendBER_coded(i)=error_number/1980000; end semilogy(Eb_N0_log,BER_coded); xlabel('Eb/N0 [dB]'); ylabel('BER'); title('BER versus Eb/N0');Eb_N0_log=0:0.5:10; %dB Eb_N0=10.^(Eb_N0_log/10); BER =0.5*erfc(sqrt(2*Eb_N0)/sqrt(2)); %Q function hold on; semilogy(Eb_N0_log,BER); xlabel('Eb/N0 [dB]'); ylabel('BER'); title('BER versus Eb/N0');R_uncoded=1; %R BER_uncoded=zeros(1,21); for i=1:21 %calculate BER in different Eb/N0SNR_uncoded=2*R_uncoded*Eb_N0(i); %SNRmessage=round(rand(1,1980000)); %generate original datamessage_modul=1-message.*2; %0->1,1->-1 modulationpx_w=1; %signal's powerpn_w=px_w/SNR_uncoded; %noise's powerr=message_modul+sqrt(pn_w)*randn(1,1980000); %add white Gaussian noiseerror_number=0;r=r<0; %demodulationerror_number=error_number+sum(sum(r~=message)); %find the number of error bitsBER_uncoded(i)=error_number/1980000; end hold on; semilogy(Eb_N0_log,BER_uncoded); xlabel('Eb/N0 [dB]'); ylabel('BER '); title('BER versus Eb/N0'); legend('RM-coded(simulation)','Uncoded(theory)','Uncoded(simulation)');%I extend the horizontal coordinate of Uncoded(theory) and Uncoded(simulation)% Eb_N0_log=0:0.5:11; %dB % Eb_N0=10.^(Eb_N0_log/10); % BER =0.5*erfc(sqrt(2*Eb_N0)/sqrt(2)); %Q function % hold on; % semilogy(Eb_N0_log,BER); % xlabel('Eb/N0 [dB]'); % ylabel('BER'); % title('BER versus Eb/N0'); % % R_uncoded=1; %R % BER_uncoded=zeros(1,23); % for i=1:23 %calculate BER in different Eb/N0 % SNR_uncoded=2*R_uncoded*Eb_N0(i); %SNR % message=round(rand(1,1980000)); %generate original data % message_modul=1-message.*2; %0->1,1->-1 modulation % px_w=1; %signal's power % pn_w=px_w/SNR_uncoded; %noise's power % r=message_modul+sqrt(pn_w)*randn(1,1980000); %add white Gaussian noise % error_number=0; % r=r<0; %demodulation % error_number=error_number+sum(sum(r~=message)); %find the number of error bits % BER_uncoded(i)=error_number/1980000; % end % hold on; % semilogy(Eb_N0_log,BER_uncoded); % xlabel('Eb/N0 [dB]'); % ylabel('BER '); % title('BER versus Eb/N0'); % legend('RM-coded(simulation)','Uncoded(theory)','Uncoded(simulation)');計(jì)算BER
1、隨機(jī)生成1980000比特,分為180000 block,每個(gè)block稱為m。
2、進(jìn)行RM編碼。
3、進(jìn)行BPSK調(diào)制。
4、添加高斯白噪聲
5、BPSK解碼。
6、Majority-Logic解碼。計(jì)算錯(cuò)誤比特的個(gè)數(shù)。
7、計(jì)算BER。
結(jié)果:
計(jì)算不使用RM編碼情況時(shí)的BER(模擬環(huán)境與理論情況)
1、隨機(jī)生成比特。
2、進(jìn)行BPSK調(diào)制。
3、添加高斯白噪聲
4、BPSK解碼。
5、計(jì)算錯(cuò)誤比特的個(gè)數(shù)。
6、利用第五部分結(jié)果計(jì)算模擬環(huán)境下的BER。
6、使用erfc函數(shù)計(jì)算理論情況下的BER。
結(jié)果:
與漢明編碼做對(duì)比
與https://blog.csdn.net/weixin_44480014/article/details/123203931實(shí)現(xiàn)的漢明編碼做對(duì)比。
結(jié)果:
總結(jié)
從BER的角度來看,如果Eb/N0小于7.152dB,未編碼系統(tǒng)優(yōu)于RM編碼系統(tǒng),如果Eb/N0大于7.152dB,RM編碼系統(tǒng)優(yōu)于未編碼系統(tǒng)。如果Eb/N0小于7.681dB,漢明編碼系統(tǒng)優(yōu)于RM編碼系統(tǒng),如果Eb/N0大于7.681dB,RM編碼系統(tǒng)優(yōu)于漢明編碼系統(tǒng)。
總結(jié)
以上是生活随笔為你收集整理的MATLAB实现的Reed-Muller(RM码,里德-马勒编码)编码解码纠错以及BER分析的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [vue-cli] vue-cli中你经
- 下一篇: [css] css中的选择器、属性、属