我想创建一个图表,为不同的信噪比生成BER和Eb/N0。尝试创建一个for循环,但它不工作,你能帮助我吗?我对这个Matlab还很陌生,不知道哪里出了问题。
figure(1)
for j = 1:length(SIR)
for i = 1:10
BER = [];
BER_az = [];
Pj = 2*Lc / (10^(SIR(j)/10));
jammer = sqrt(Pj/2)*jam_mod.*exp(1i*2*pi*0.12*(1:Ldata*Lc)).';
[P,x] = pwelch(jammer+x_in,[],[],[4096], Lc,'twoside');
%clear jam_mod;
EB2N(i) = (i-1);
EB2N_num = 10^(EB2N(i)/10);
Var_n = Lc/(2*EB2N_num); %variance
signois = sqrt(Var_n); %standard deviation
awgnois = signois*noise;
y_out = x_in+awgnois+jammer;
Y_out = reshape(y_out,Lc,Ldata).';
clear y_out awgnois;
z_out = Y_out*Pcode;
%decision based on the sign of the samPles
dec1 = sign(real(z_out))+j*sign(imag(z_out));
%comPare against the original data to calcuate BER
BER = [BER;sum([real(data_sym)~=real(dec1);...
imag(data_sym)~=imag(dec1)])/(2*Ldata)];
BER_az = [BER_az;0.5*erfc(sqrt(EB2N_num))];
end
if (j == 1)
figber = semilogy(EB2N,BER_az, 'k-');
hold on;
end
figber = semilogy(EB2N,BER);
clear BER;
clear BER_az;
legend('No jamming','SNR:-5 dB', 'SNR:-8 dB', 'SNR:-10 dB', 'SNR:-20 dB');
set(figber,'Linewidth',2);
xfont = xlabel('E_b/N in dB');
yfont = ylabel('bit error rate');
title('DSSS with sPreading gain 11');
end 发布于 2020-12-16 17:16:19
您必须首先在循环开始之前初始化SIR变量。还要在for循环之前指定SIR值。
SIR = [0:1:10]; % For example for a SIR from 0 to 10 in steps of 1.在程序中,指定以下值:Lc、Jam_mod、Ldata、X_in、noise和data_sym。
这个post还会给你提供其他的机会。
https://stackoverflow.com/questions/65315196
复制相似问题