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代码
时间: 2023-09-06 12:09:59 浏览: 439
这段MATLAB代码实现了一个通信系统的模拟。首先设置了一些参数,包括使用的编码方式、噪声选项、帧数、信噪比等。然后进入一个主循环,循环中对于每一帧数据,进行编码、交织、调制、信道传输、解调、反交织、译码等操作,并计算误比特率(BER)。如果达到预设的误比特率目标或帧数目标,则退出循环。最后输出信噪比和误比特率,并保存数据。注释中对于每个操作都有详细的说明。
相关问题
clear all; close all; clc;tic its_option =2; hoise_option=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 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 encoding_bits= convolution_encoder(bits);interleaved=[]; for i=l:interleaving_mum interleaved=[interleavedencoding_bits([i:interleaving_mum:end])];解释一下上述代码中构造sq05的原因
在通信系统中,常常需要对信号进行归一化处理,以保证信号的功率被限制在一个合适的范围内,同时可以简化计算。其中,一种常用的归一化方法是将信号除以其均方根值(RMS,即Root Mean Square),也就是信号的标准差。
在代码中,sq05=sqrt(0.5)的作用是构造一个标准差为1的正态分布随机变量的系数,这个系数在接收端解调时会用到。由于标准差为1的正态分布随机变量的方差为1,因此其均方根值也为1。而由于sq05=sqrt(0.5),因此sq05的平方等于0.5,即标准差为1的正态分布随机变量的方差为0.5,因此在使用sq05作为系数时,需要将接收信号乘以sqrt(2)来还原出原始信号的功率。
总之,sq05的作用是用于构造标准差为1的正态分布随机变量的系数,以便在接收端解调时将接收信号还原为原始信号。
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
阅读全文