DSPRelated.com
Forums

OFDM

Started by yashasri 7 years ago6 replieslatest reply 7 years ago408 views
i don't know what's wrong with this #ofdm code, it gets executed but i don't get any graph.
% OFDM_basic.m
clear all;
clf;
Target_neb=500;
PowerdB=[0 -8 -17 -21 -25]; % Channel tap power profile ’dB’
Delay=[0 3 5 6 8]; % Channel delay ’sample’
Power=10.^(PowerdB/10); % Channel tap power profile ’linear scale’
Ntap=length(PowerdB); % Chanel tap number
Lch=Delay(end)+1; % Channel length
Nbps=4; M=2^Nbps; % Modulation order=2/4/6 for QPSK/16QAM/64QAM
Nfft=64; % FFT size
Ng=Nfft/4; % GI (Guard Interval) length
Nsym=Nfft+Ng; % Symbol duration
Nvc=Nfft/4; % no VC (virtual carrier)
Nused=Nfft-Nvc;
EbN0=[0:5:30]; % EbN0
N_iter=1e5; % Number of iterations for each EbN0
Nframe=3; % Number of symbols per frame
sigPow=0; % Signal power initialization
norms= sqrt(42); % for 16-QAM
for i=0:length(EbN0)
randn('state',0); rand('state',0);
Neb=0; Ntb=0; % Initialize the number of error/total bits
avgerror=0;
Ber=0;
for m=1:N_iter
error=0;
% Tx______________________________________________________________
X= randint(1,Nused*Nframe,M); % bit: integer vector
Xmod=qammod(X,M,0,'gray')/norms;
x_GI=zeros(1,Nframe*Nsym);
kk1=[1:Nused/2]; kk2=[Nused/2+1:Nused]; kk3=1:Nfft; kk4=1:Nsym;
for k=1:Nframe
X_shift= [0 Xmod(kk2) zeros(1,Nvc-1) Xmod(kk1)];
x = ifft(X_shift);
x_GI(kk4)= [x(Nfft-Ng+1:Nfft) x(1:Nfft)];
kk1=kk1+Nused; kk2= kk2+Nused; kk3=kk3+Nfft; kk4=kk4+Nsym;
end
channel=(randn(1,Ntap)+j*randn(1,Ntap)).*sqrt(Power/2);
h=zeros(1,Lch); h(Delay+1)=channel; % cir: channel impulse response
y = conv(x_GI,h);
if i==0 % Only to measure the signal power for adding AWGN noise
y1=y(1:Nframe*Nsym); sigPow = sigPow + y1*y1'; continue;
end
% Add AWGN noise________________________________________________
snr = EbN0(i)+10*log10(Nbps*(Nused/Nfft)); % SNR vs. Eb/N0 by Eq.(4.28)
noise_mag = sqrt((10.^(-snr/10))*sigPow/2);
y_GI = y + noise_mag*(randn(size(y))+j*randn(size(y)));
% Rx_____________________________________________________________
kk1=1:Nsym; kk2=1:Nfft;
kk3=1:Nused; kk4=Nused/2+Nvc+1:Nfft; kk5=Nvc+[1:Nused/2];
H= fft([h zeros(1,Nfft-Lch)]); % Channel frequency response
H_shift(kk3)= [H(kk4) H(kk5)];
for k=1:Nframe
Y(kk2)= y_GI(Ng+1:Nsym);
Y_r = fft(Y);
Y_shift=[Y_r(kk4) Y_r(kk5)];
Xmod_r(kk3)=Y_shift./H_shift; % Equalizer - channel compensation
kk1=kk1+Nsym; kk2=kk2+Nfft; kk3=kk3+Nused; kk4=kk4+Nfft;
kk5=kk5+Nfft;
end
X_r=qamdemod(Xmod_r*norms,M,0,'gray');
Neb=Neb+sum(sum(de2bi(X_r,Nbps)~=de2bi(X,Nbps)));
Ntb=Ntb+Nused*Nframe*Nbps; %[Ber,Neb,Ntb]=ber(bit_Rx,bit,Nbps);
error= Neb/Ntb;
avgerror= avgerror+error;
if Neb>Target_neb, break; end
end
if i==0, sigPow= sigPow/Nsym/Nframe/N_iter;
else
Ber(i) = avgerror/N_iter;
end
end
semilogy(EbN0,Ber,'k');
legend('simulated');
axis([min(EbN0) max(EbN0) 1e-5 1])
grid on;
xlabel('EbN0');
ylabel('BER');
title('Bit error probability curve for QAM in rayleigh channel using OFDM');
plz kindly help me.........where it's going wrong........
[ - ]
Reply by jtp_1960August 17, 2017

Hmm... your code needs formatting (did you try code formatting option (2nd icon from left))?

[ - ]
Reply by yashasriAugust 17, 2017

i'm sorry i didn't get you....if u can help me, i will provide further details, plz.......the block diagram i used etc....

[ - ]
Reply by jtp_1960August 17, 2017

Your .m code looks like a mess without proper formatting.

At that point you paste the source code to your post you be able to use code formatting feature to keep it in original form as like:

if
    nnn
else
    if
        kkk
    else
        lll
    end
end

It's much readable! Ofcourse if what you pasted is the original then sorry but I'm not going to read it.

[ - ]
Reply by yashasriAugust 17, 2017
ofdm.m

 that's the matlab file, i'm sorry i'm new to these online forums.

actually its a code from the text MIMO-OFDM,

http://www.wiley.com//legacy/wileychi/cho/,

i have edited the code from this text to use in my M.Tech project. Plz bear with my ignorance and help me out. 

[ - ]
Reply by jtp_1960August 17, 2017

Your plot data: 

Ber = 0.0000e+000  0.0000e+000  0.0000e+000  0.0000e+000  0.0000e+000  0.0000e+000  1.0017e-005


I tried by using plot(EbN0,Ber) and it looked like it worked.

[ - ]
Reply by chessAugust 17, 2017

If Ber vector is all zeros then it makes sense why semilogy produces empty graph.