Pls help me spot errors in the code..I don't get a decaying BER
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
clc;
clear all;
close all;
%input
M=1024;
nt=2;
nr=1;
L=65;
%Generate random data
m=4;
msg1=randint(M,1,m);
msg2=randint(M,1,m);
msg=vertcat(msg1,msg2);
% QPSK modulation
qpsk_modulated_data1=pskmod(msg1,m);
qpsk_modulated_data2=pskmod(msg2,m);
%IFFT
x1=ifft(qpsk_modulated_data1);
x2=ifft(qpsk_modulated_data2);
x=vertcat(x1,x2);
%channel
temp=randsrc(1,L-1);
temp=[temp zeros(1,960)];
temp1=transpose(temp);
h1=gallery('circul',temp1);
h1=h1';
temp2=randsrc(1,L-1);
temp2=[temp2 zeros(1,960)];
temp3=transpose(temp2);
h2=gallery('circul',temp3);
h2=h2';
h=horzcat(h1,h2);
%r
r=h*x;
%--- Joint estimation of channel response and I/Q imbalance
%ek
e=eye(M);
%y due to cfo
y=e*r;
y1=conj(y);
%z due to cfo and i/q
u=(1+exp(-j*10))/2;
u1=conj(u);
v=(1-exp(j*10))/2;
z=(u*y)+(v*y1);
z1=conj(z);
%a
a=(v/u1);
%ur
a1=abs(a)^2;
e1=conj(e);
ur=(e1*(z-(a*z1))/(1-a1));
%p
p=M/nt;
%MIMO channel response
a1=randn(M,L);
a2=randn(M,L);
A=horzcat(a1,a2);
a11=randn(M,p-L);
a22=randn(M,p-L);
B=horzcat(a1,a11,a2,a22);
B1=inv(B);
ud=B1*ur;
%CRE
q = M-(L*nt);
P = zeros(q,M);
P(:,2:2:end) = (p-L)*eye(q,M/2);
cre=norm(P*ud)^2;
CRE =norm(P*B1*(z-(a*z1)))^2;
%I/Q_imbalance
o=ctranspose(P*B1*z1); %traspose_conj of p*B1*z1
aopt=(o*(P*B1*z))/(norm(P*B1*z1))^2;
%channel response
aopt1=abs(aopt)^2;
cha_res=B1*(z-(aopt*z1))/(1-aopt1);
%--------------------------------------------------
%fft
fft_recdata=fft(r);
%Demodulate the data
qpsk_demodulated_data = pskdemod(fft_recdata,M);
%estimated signal
est_sgl=r*cha_res';
%calculating BER
errors=0;
snr=0:1:35;
for k=1:length(snr)
for i=1:M
if est_sgl(i) ~= msg(i)
errors=errors+1;
end
end
ber(k)=errors/M;
Q=sort(ber,'descend');
end
figure(1)
semilogy(smooth(snr),smooth(Q));
title('BER vs SNR');
ylabel('BER');
xlabel('SNR');
답변 (1개)
Walter Roberson
2012년 3월 22일
0 개 추천
The problem is the same as I told you before more than once: you are not recalculating your noise signal as you change your snr, so your number of errors is coming out constant for each snr.
댓글 수: 12
Janet
2012년 3월 22일
Janet
2012년 3월 22일
Walter Roberson
2012년 3월 22일
Have you considered zeroing "errors" for each snr, so that your error count does not accumulate between different SNR?
Janet
2012년 3월 22일
Walter Roberson
2012년 3월 22일
for snr=0:1:35
errors = 0; %HERE HERE HERE HERE HERE
for i=1:1:128
<etc>
Janet
2012년 3월 22일
Oleg Komarov
2012년 3월 22일
Janet, please read again Walter's comments. Carefully this time.
Janet
2012년 3월 22일
Janet
2012년 3월 22일
Walter Roberson
2012년 3월 22일
Fixing *only* the most immediate problem:
snr = 0:1:35
for k = 1:length(snr)
errors = 0; %THIS GOES HERE
for i = 1 : M
if est_sig(i) ~= msg(i)
errors = errors + 1;
end
ber(k)=errors/M;
%GET RID OF Q HERE
end
figure(1)
semilogy(smooth(snr),smooth(ber)); %NO NOT Q
title('BER vs SNR');
ylabel('BER');
xlabel('SNR');
Do *not* go around sorting your BER: the results you produce will be near meaningless.
But the key point for now is that errors has to be initialized to 0 for *each* snr value.
WARNING: This will only take you as far as showing you that you are getting a completely flat BER graph. The above corrections do not attempt to fix your fundamental problem with your BER calculation that you are failing to change your est_sgl according to the "current" snr.
Janet
2012년 3월 23일
Janet
2012년 3월 26일
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!