Is my BER curve right?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
clc;
clear all;
close all;
%input
M=128;
nt=2;
nr=1;
L=16;
%Generate random data
m=4;
msg1=randint(M/2,1,m);
figure(1)
stem(msg1)
grid on
xlabel('data points')
ylabel('transmitted data phase representation')
title('Transmitted Data "O"')
msg2=randint(M/2,1,m);
figure(2)
stem(msg2)
grid on
xlabel('data points')
ylabel('transmitted data phase representation')
title('Transmitted Data "O"')
msg=vertcat(msg1,msg2);
% QPSK modulation
qpsk_modulated_data1=pskmod(msg1,m);
qpsk_modulated_data2=pskmod(msg2,m);
%scatterplot(qpsk_modulated_data1);
%title('qpsk modulated transmitted data1');
%scatterplot(qpsk_modulated_data2);
%title('qpsk modulated transmitted data2');
%IFFT
x1=ifft(qpsk_modulated_data1);
x2=ifft(qpsk_modulated_data2);
%scatterplot(x1)
%scatterplot(x2)
x=vertcat(x1,x2);
%channel
h1=gallery('circul',M:M);
h2=gallery('circul',M:M);
e=horzcat(h1,h2);
f=vertcat(h1,h2);
h=e*f;
%r
r=h*x;
%fft
fft_recdata=fft(r);
%Demodulate the data
qpsk_demodulated_data = pskdemod(fft_recdata,M);
%ek
e=eye(M);
%y due to cfo
y=e*r;
%z due to cfo and i/q
u=(1+exp(-j*10))/2;
v=(1-exp(j*10))/2;
y1=conj(y);
z=(u*y)+(v*y1);
%a
u1=conj(u);
a=(v/u1);
%ur
z1=conj(z);
a1=abs(a)^2;
e1=conj(e);
ur=(e1*(z-(a*z1))/(1-a1));
%p
p=M/nt;
%ud
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 = 96; %p-L
P = zeros(q,M);
P(:,2:2:end) = (48)*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*z1))/(norm(P*B1*z1))^2;
scatterplot(aopt)
title('I/Q imbalance')
%channel response
aopt1=abs(aopt)^2;
cha_res=B1*(z-(aopt*z1))/(1-aopt1);
scatterplot(cha_res)
title('Channel Response')
%Recovering signal
est_sgl= r*cha_res'
%calculating BER
errors=0;
count=1;
for snr=0:1:35
ber(count) = mean(est_sgl(1:M) ~= msg(1:M));
count=count+1;
end
semilogy(0:1:snr,smooth(ber));
title('BER vs SNR');
ylabel('BER');
xlabel('SNR (dB)');
grid on
Antworten (2)
Walter Roberson
am 12 Mär. 2012
You assign M=128 in the Input section and reassign it in the CR section. Why?
In your BER section, you "for i=1:1:128", but you do not divide by 128, you divide by M. Why?
Why do you use the "for i" loop at all?
ber(count) = mean(qpsk_demodulated_data(1:M) ~= msg(1:M));
Why does your demodulated data not depend upon the value of the "snr" that you are looping over?
7 Kommentare
rao raghavendra
am 25 Mär. 2015
sir, i m doing project on non binary ldpc codes.i wrote the code for ldpc ber vs snr,but i m not getting correct result.plz check my code.
clc; clear all;
% LDPC matrix size, rate must be 1/2 % Warning: encoding - decoding can be very long for large LDPC matrix! rows = 4; cols =8;
% Method for creating LDPC matrix (0 = Evencol; 1 = Evenboth) method = 1;
% Eliminate length-4 cycle noCycle = 1;
% Number of 1s per column for LDPC matrix onePerCol = 3;
% LDPC matrix reorder strategy (0 = First; 1 = Mincol; 2 = Minprod) strategy = 2;
% EbN0 in dB EbN0 = [ 5 10 15 20]; % Number of iteration; iter = 5;
% Number of frame (N bits per frame) frame = 1;
% Make the LDPC matrix H = makeLdpc(rows, cols, 1, 1, onePerCol);
for i = 1:length(EbN0)
ber1(i) = 0;
ber2(i) = 0;
% Make random data (0/1)
dSource = round(rand(rows, frame));
for j = 1:frame
fprintf('Frame : %d\n', j);
% Encoding message [c, newH] = makeParityChk(dSource(:, j), H, strategy); u = [c; dSource(:, j)];
%%%%%%%%%%%%%%% reorder u¢to get the CW u %%%%%%%%%%%%%%%%%%%
% BPSK modulation
bpskMod = 2*u - 1;
% Additional white gaussian noise
N0 = 1;
tx = bpskMod + sqrt(N0/2)*randn(size(bpskMod));
% Decoding (select decoding method)
%vhat = decodeProbDomain(tx, H, newN0, iter);
% Uncoded
%a=sort(rand(1,8).*[0.1 0.07 0.05 0.02 0.01 0.005 0.001 0.0001],'descend');
EbN0_uncoded = [ 1:0.5:4.5 ];
ber_uncoded = [ 0.1241 0.11 0.0974 0.0850 0.0730 0.0618 0.0514 0.0420 ];
vhat1 = decodeLogDomain(tx, H, N0, iter);
[num1, rat1] = biterr(vhat1', u);
ber1(i) = (ber1(i) + rat1);
ber1(i) = ber1(i)/frame;
ber1(i) = ber1(i)/frame;
% Get bit error rate (for brevity, BER calculation includes parity bits)
vhat = decodeBitFlip(tx, H, iter);
[num2, rat2] = biterr(vhat', u);
ber2(i) = (ber2(i) + rat2);
ber2(i) =ber2(i)/frame;
end % for j
% Get average of BER
end % for i
figure
semilogy(EbN0_uncoded,ber_uncoded,'r')
hold on
semilogy(EbN0,ber1, 's-')
hold on semilogy(EbN0,ber2 , 'g-') hold on
legend('Uncoded', 'log domain','bit flipping') xlabel('EbN0') ylabel('ber')
%title('(3,6)-regular code, 1000 bits') grid on hold off
results
0 Kommentare
Siehe auch
Kategorien
Mehr zu ASK finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!