我想算毫米波环境下的单天线,2multipath的Ber。
由于每次generate的矩阵不一样(传输效果浮动),我希望多算几次再取ber得平均值。
下面是算两次的程序(cycleNum = 2;),算第二遍时,数据就不对了,ber=50%,等于是 完全错误。
可以保证ber的算法没有错,感觉错误是第二遍时有的数据没有被覆盖,仍然是第一遍的数据导致最后结果错误。
但是找不到错在哪里。。。
请大神指导下
clear all ;
close all ;
N = 10^4; % number of bits or symbols
M = 1; % number of users
K = 1; % number of channels
L = 2; % number of multipath components
% Transmitter
% generating 0,1 with equal probability
input = rand(1,N)>0.5;
% 0 -> -1; 1 -> 1
s = 2*input-1;
s1 = squeeze(reshape(s,[2,1,N/2])); % grouping
cycleNum = 2;
% multiple Eb/N0 values
SNR = 0:20;
k=zeros(length(SNR),cycleNum);
for ii = 1:cycleNum
%% ********* Call the mmWave/Saleh-Valenzula Channel Subroutine ******** %%
[t,h,Tbar,Tba,RMS] = cs_802154UWB_MSV_main(M,K,L);
% ***** TAP & Normalize h so that the sum of the elements in each column = 1.0 **** %%
for i3 = 1:L
h_tap(i3,:) = h(i3,:);
end
SUM = sum(h_tap,1);
for i4 = 1:K*M
h_tap(:,i4) = h_tap(:,i4)/SUM(i4);
end
% white gaussian noise, 0dB variance
n = 1/sqrt(2)*(randn(3,2*N/3) + j*randn(3,2*N/3));
% mmw channel matrix
H = [h_tap(1,1),0;
h_tap(2,1),h_tap(1,1);
0,h_tap(2,1)];
% W
W = H;
for i = 1:length(SNR)
Err1 = 0;
Err2 = 0;
for j = 1:N/2
% Noise addition
y = H*s1(:,j) + 10^(-SNR(i)/20)*n(:,j);
% receiver
yhat = real((W')*y);
yout1 = 2*(yhat(1,:)>0)-1;
yout2 = 2*(yhat(2,:)>0)-1;
% counting the errors
if [s1(1,j) - yout1] ~= 0 ;
Err1 = Err1 + 1;
end
if [s1(2,j) - yout2] ~= 0 ;
Err2 = Err2 + 1;
end
end
% simulated ber
Ber1(i) = (Err1+Err2)/N;
end
k(:,ii)=[Ber1];
end
Ber = sum(k,2)/cycleNum;
% plot
semilogy(SNR,Ber,'rd-');
grid on
legend('simulation');
xlabel('Eb/No, dB');
ylabel('Bit Error Rate');
title('BER');