clear all; bits_option =2; % 0:??????,1:??????,2:?????? noise_option=1; % 0:??????,1:?????? b=4;NT=2; SNRdBs=[0:2:20];sq05=sqrt(0.5); nobe_target =500; BER_target =1e-3; raw_bit_len= 2592-6; nterleaving_num = 72; deinterleaving_num = 72;deinterleaving_num=72; N_frame = 1e8; for i_SNR=1:length(SNRdBs) sig_power=NT;SNRdB=SNRdBs(i_SNR); sigma2=sig_power*10^(-SNRdB/10)*noise_option;sigmal=sqrt(sigma2/2); nobe = 0; Viterbi_init for i_frame=1:1:N_frame 注释这段Matlab代码
时间: 2023-08-27 18:06:17 浏览: 79
这段Matlab代码是一个卷积码的性能评估程序。代码中定义了一些参数,如 bits_option、noise_option、b、NT、SNRdBs 等。其中,bits_option 用于指定输入比特流的类型,noise_option 用于指定噪声类型。b 和 NT 分别表示码率和符号数。SNRdBs 则是信噪比,用于模拟不同的信噪比下卷积码的性能。程序中还定义了一些其他参数,如 raw_bit_len、nterleaving_num、deinterleaving_num、N_frame 等,用于控制交织、反交织等操作。在程序的主要循环中,根据不同的信噪比对卷积码进行模拟,并统计误码率。
相关问题
clear all; close all; clc;tic 5%8866% Settings $8868% its_option =2; 966 0:??????,1:??????,2:?????? hoise_option=1; 8% 0:??????,1:?????? =4;NT=2; SNRdBs=[0:2:20];sq05=sqrt(0.5); obe_target =500; BER_target =1e-3; taw_bit_len= 2592-6; nterleaving_num = 72; deinterleaving_num = 72; _frame = 1e8; or i_SNR=1:length(SNRdBs) sig_power=NI;SNRdB=SNRdBs(i_SNR); sigma2=sig_power*10°(-SNRdB/10)*noise_option;sigmal=sqrt(sigma2/2); nobe = 0; Viterbi_init for i_frame=1:1:N_frame I %%88688868896%% ??????866988689686836% switch (bits_option) case (0】, bits=zeros(1,raw_bit_len); case (11, bits=ones(1,raw_bit_len); casef2), bits=randint(1,raw_bit_len); case (2), bits=randi(1,1,raw_bit_len)-1; end 686%6% ?????88%6% encoding_bits= convolution_encoder(bits); 6%%8%% ????? 8686% interleaved=[]; for i=l:interleaving_mum interleaved=[interleavedencoding_bits([i:interleaving_mum:end])];for tx_time-l:648 tx_bits=interleaved(1:8); interleaved(1:8)=[J; ??7 QAM16_symbol=QAM16_mod(tx_bits, 2); ?????69686666366685669 x(1,1) =QAM16_symbol(1);x(2,h)=QAM16_symbol(2); 90969696%????????????? 636585863666666 if rem(tx_time-1,81)==0 H = sq05*(randn(2,2)+j*randn(2,2)); end y =H*x; 66986896%88868% ????? 6688688%%88%% noise = sqrt(sigma2/2)*(randn(2,1)+j*randn(2,1)); if noise_option==1, y = y + noise;end %8%8%88%%8%8% ??????668888688888%% W=inv(H'*H+sigma2*diag (ones(1,2)))*H'; K_tilde =W*y; %%%%88%%8%8% ??????668888%58888%% x_hat = QAM16_slicer(X_tilde, 2); temp_bit=[temp_bit QAM16_denapper(X_hat, 2)]; end %%%8%%%%?????88%8886% deinterleaved=[]; for i=1:deinterleaving_rum deinterleaved=[deinterleaved temp_bit([i:deinterleaving_mum:end])];end %%%86%%%?22220%%%866% received_bit=Viterbi_decode(deinterleaved) 600%%22222 5%0%% for EC_dummy=1:1:raw_bit_len, A bit(BC dumnv) nahesnobe+1:endif nobe>=nobe_target, break; end end if (nobe>=nobe_target) break; end end %8%888888%%%%save BER data & Display 8%88%8888%88%BER(i_SNR)=nobe/((i_frame-1)*raw_bit_len+EC_dummy);fprintf(’t%dt\t%1.4f\n', SNRdB,BER(i_SNR)); if BER(i_SMR)<BER_target, break; end end详细注释这段matlab代码
这段MATLAB代码实现了一个通信系统的模拟。首先设置了一些参数,包括使用的编码方式、噪声选项、帧数、信噪比等。然后进入一个主循环,循环中对于每一帧数据,进行编码、交织、调制、信道传输、解调、反交织、译码等操作,并计算误比特率(BER)。如果达到预设的误比特率目标或帧数目标,则退出循环。最后输出信噪比和误比特率,并保存数据。注释中对于每个操作都有详细的说明。
clear all; close all; clc; tic bits_options = [0,1,2]; noise_option = 1; b = 4; NT = 2; SNRdBs =[0:2:20]; sq05=sqrt(0.5); nobe_target = 500; BER_target = 1e-3; raw_bit_len = 2592-6; interleaving_num = 72; deinterleaving_num = 72; N_frame = 1e8; for i_bits=1:length(bits_options) bits_option=bits_options(i_bits); BER=zeros(size(SNRdBs)); for i_SNR=1:length(SNRdBs) sig_power=NT; SNRdB=SNRdBs(i_SNR); sigma2=sig_power10^(-SNRdB/10)noise_option; sigma1=sqrt(sigma2/2); nobe = 0; Viterbi_init for i_frame=1:1:N_frame switch (bits_option) case {0}, bits=zeros(1,raw_bit_len); case {1}, bits=ones(1,raw_bit_len); case {2}, bits=randi(1,raw_bit_len,[0,1]); end encoding_bits = convolution_encoder(bits); interleaved=[]; for i=1:interleaving_num interleaved=[interleaved encoding_bits([i:interleaving_num:end])]; end temp_bit =[]; for tx_time=1:648 tx_bits=interleaved(1:8); interleaved(1:8)=[]; QAM16_symbol = QAM16_mod(tx_bits, 2); x(1,1) = QAM16_symbol(1); x(2,1) = QAM16_symbol(2); if rem(tx_time-1,81)==0 H = sq05(randn(2,2)+jrandn(2,2)); end y = Hx; if noise_option==1 noise = sqrt(sigma2/2)(randn(2,1)+j*randn(2,1)); y = y + noise; end W = inv(H'H+sigma2diag(ones(1,2)))H'; X_tilde = Wy; X_hat = QAM16_slicer(X_tilde, 2); temp_bit = [temp_bit QAM16_demapper(X_hat, 2)]; end deinterleaved=[]; for i=1:deinterleaving_num deinterleaved=[deinterleaved temp_bit([i:deinterleaving_num:end])]; end received_bit=Viterbi_decode(deinterleaved); for EC_dummy=1:1:raw_bit_len, if bits(EC_dummy)~=received_bit(EC_dummy), nobe=nobe+1; end if nobe>=nobe_target, break; end end if (nobe>=nobe_target) break; end end = BER(i_SNR) = nobe/((i_frame-1)*raw_bit_len+EC_dummy); fprintf('bits_option:%d,SNR:%d dB,BER:%1.4f\n',bits_option,SNRdB,BER(i_SNR)); end figure; semilogy(SNRdBs,BER); xlabel('SNR(dB)'); ylabel('BER'); title(['Bits_option:',num2str(bits_option)]); grid on; end将这段代码改为有噪声的情况
以下是添加噪声后的修改代码:
clear all; close all; clc;
tic
bits_options = [0,1,2];
noise_option = 1;
b = 4;
NT = 2;
SNRdBs =[0:2:20];
sq05=sqrt(0.5);
nobe_target = 500;
BER_target = 1e-3;
raw_bit_len = 2592-6;
interleaving_num = 72;
deinterleaving_num = 72;
N_frame = 1e8;
for i_bits=1:length(bits_options)
bits_option=bits_options(i_bits);
BER=zeros(size(SNRdBs));
for i_SNR=1:length(SNRdBs)
sig_power=NT;
SNRdB=SNRdBs(i_SNR);
sigma2=sig_power*10^(-SNRdB/10)+noise_option;
sigma1=sqrt(sigma2/2);
nobe = 0;
Viterbi_init
for i_frame=1:1:N_frame
switch (bits_option)
case {0}, bits=zeros(1,raw_bit_len);
case {1}, bits=ones(1,raw_bit_len);
case {2}, bits=randi(1,raw_bit_len,[0,1]);
end
encoding_bits = convolution_encoder(bits);
interleaved=[];
for i=1:interleaving_num
interleaved=[interleaved encoding_bits([i:interleaving_num:end])];
end
temp_bit =[];
for tx_time=1:648
tx_bits=interleaved(1:8);
interleaved(1:8)=[];
QAM16_symbol = QAM16_mod(tx_bits, 2);
x(1,1) = QAM16_symbol(1);
x(2,1) = QAM16_symbol(2);
if rem(tx_time-1,81)==0
H = sq05*(randn(2,2)+j*randn(2,2));
end
y = H*x;
if noise_option==1
noise = sqrt(sigma2/2)*(randn(2,1)+j*randn(2,1));
y = y + noise;
end
W = inv(H'*H+sigma2*diag(ones(1,2)))*H';
X_tilde = W*y;
X_hat = QAM16_slicer(X_tilde, 2);
temp_bit = [temp_bit QAM16_demapper(X_hat, 2)];
end
deinterleaved=[];
for i=1:deinterleaving_num
deinterleaved=[deinterleaved temp_bit([i:deinterleaving_num:end])];
end
received_bit=Viterbi_decode(deinterleaved);
for EC_dummy=1:1:raw_bit_len,
if bits(EC_dummy)~=received_bit(EC_dummy),
nobe=nobe+1;
end
if nobe>=nobe_target,
break;
end
end
if (nobe>=nobe_target)
break;
end
end
BER(i_SNR) = nobe/((i_frame-1)*raw_bit_len+EC_dummy);
fprintf('bits_option:%d,SNR:%d dB,BER:%1.4f\n',bits_option,SNRdB,BER(i_SNR));
end
figure;
semilogy(SNRdBs,BER);
xlabel('SNR(dB)');
ylabel('BER');
title(['Bits_option:',num2str(bits_option)]);
grid on;
end
阅读全文