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');

3 Comments

Please, Janet, explain what error you see. Do you get an error message (if so, post it completely) or do the results differ from your expectations?
My Ber curve is not decaying..It has errors upto 10^2

Answers (1)

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 Comments

Can u pls say me how to do it? I really don't know how to proceed
i don't get a straight line now...rather it is growing
Have you considered zeroing "errors" for each snr, so that your error count does not accumulate between different SNR?
@walter : I am new to this sir and I tried my best to bring out this project...I really don't get what u say...
I actually need a decaying ber with low error rate...but i am getting a growing ber
for snr=0:1:35
errors = 0; %HERE HERE HERE HERE HERE
for i=1:1:128
<etc>
so what should i give in this line?
Janet, please read again Walter's comments. Carefully this time.
actually,I want to decrease my ber in my project
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
ber(k)=errors/M;
Q=sort(ber,'descend');
end
figure(1)
semilogy(smooth(snr),smooth(Q));
title('BER vs SNR');
ylabel('BER');
xlabel('SNR');
is this correct?
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.
how should i change my est_sgl acc to current snr
i get very high ber..how can i bring it down?

This question is closed.

Tags

Asked:

on 21 Mar 2012

Closed:

on 20 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!