DSPRelated.com
Forums

Please help: BER for QPSK in OFDM over Rayleigh matlab code doesn't work.

Started by mackenfy September 19, 2011
I try to implement the matlab code on BER for QPSK in OFDM over rayleigh
channel (with n taps). However the result is a straight line. There must be
something wrong in my code but I cannot figure it out what is wrong. Could
you please help me to check it. I have to hand the work soon. Please please
please help. Thank you very much.

[QUOTE]clear;
clc;

N=64; % FFT size
Nsd = 48; % Number of data subcarriers 48
Nsp = 4 ; % Number of pilot subcarriers 4
ofdmBW = 20 * 10^6 ; % OFDM bandwidth

%Derived Parameters
deltaF = ofdmBW/N;  %=20 MHz/64 = 0.3125 MHz
Tfft = 1/deltaF; % IFFT/FFT period = 3.2us 
Tgi = Tfft/4;%Guard interval duration - duration of cyclic prefix
Tsignal = Tgi+Tfft; %duration of QPSK-OFDM symbol
Ncp = N*Tgi/Tfft; %Number of symbols allocated to cyclic prefix
Nst = Nsd + Nsp;  %Number of total used subcarriers
nBitsPerSym=2*Nst; %For QPSK the number of Bits per Symbol is double of num
of subcarriers

%Simulation parameters
nSym=2; %Number of OFDM Symbols to transmit (I try to work out in small
number first)

EbN0dB = 0:2:45; % bit to noise ratio
EsN0dB = EbN0dB + 10*log10(Nst/N) + 10*log10(N/(Ncp+N)); % converting to
symbol to noise ratio

simulatedBER = zeros(1,length(EsN0dB));
theoreticalBER = zeros(1,length(EsN0dB));

for i=1:length(EsN0dB),
    %-----------------------------------------------
    %Transmitter
    %-----------------------------------------------
re=rand(1,(nBitsPerSym/2)*nSym)>0.5;
    im=rand(1,(nBitsPerSym/2)*nSym)>0.5;
        
    
    % ----------Modulation---------
    %Constellation Mapper
ip = (2*re-1) + j*(2*im-1); %
    s1 = (1/sqrt(2))*ip; % normalization of energy to 1
    
    %serial to parallel conversion
    s=reshape(s1,nBitsPerSym/2,nSym).';
 % Assigning modulated symbols to subcarriers from [-26 to -1, +1 to +26]
X_Freq = [zeros(nSym,6) s(:,[1:Nst/2]) zeros(nSym,1) s(:,[Nst/2+1:Nst])
zeros(nSym,5)] ;
%IFFT block
x_Time = (N/sqrt(Nst))*ifft(fftshift(X_Freq.')).';

    %Adding Cyclic Prefix
    ofdm_signal=[x_Time(:,N-Ncp+1:N) x_Time];
    [rows cols]=size(ofdm_signal);
    %-----------------------------------------------
    %Channel Modeling 
    %-----------------------------------------------

 nTap = 10;
   ht = 1/sqrt(2)*1/sqrt(nTap)*(randn(nSym,nTap) + j*randn(nSym,nTap));
   
   % computing and storing the frequency response of the channel, for use
at recevier
   hF = fftshift(fft(ht,64,2));

   % convolution of each symbol with the random channel
   for jj = 1:nSym
      xht(jj,:) = conv(ht(jj,:),ofdm_signal(jj,:));
   end
   xt1 = xht;

   % Concatenating multiple symbols to form a long vector
   xt = reshape(xt1.',1,nSym*(80+nTap-1));
   
   
   

   % Gaussian noise of unit variance, 0 mean
   nt = 1/sqrt(2)*[randn(1,nSym*(80+nTap-1)) +
j*randn(1,nSym*(80+nTap-1))];

   % Adding noise, the term sqrt(80/64) is to account for the wasted energy
due to cyclic prefix
   %yt = sqrt(80/64)*xt + 10^(-EsN0dB(i)/20)*nt;
   yt = sqrt(80/64)*xt + 10^(-EsN0dB(i)/20)*nt;

 %-----------------------------------------------
    %Receiver
    %-----------------------------------------------
    %Serial to Parallel conversion

 r_Parallel=reshape(yt.',89,nSym).';
    
    %Removing cyclic prefix
    r_Parallel=r_Parallel(:,Ncp+1:(N+Ncp));
    
    %FFT Block
r_Time = (sqrt(Nst)/N)*fftshift(fft(r_Parallel.')).'; 
    
    % equalization by the known channel frequency response
   yF = r_Time./hF;
   
    %Extracting the data carriers from the FFT output

R_Freq = yF(:,[6+[1:Nst/2] 7+[Nst/2+1:Nst] ]); 
    
   
%----------------------------------------------------------------------
  
 %--------- QPSK demodulation ------------%
 y_re = real(R_Freq); % real
     y_im = imag(R_Freq); % imaginary
     ipHat(find(y_re < 0 & y_im < 0)) = -1 + -1*j; % iphat= input^ hat
     ipHat(find(y_re >= 0 & y_im > 0)) = 1 + 1*j;
     ipHat(find(y_re < 0 & y_im >= 0)) = -1 + 1*j;
     ipHat(find(y_re >= 0 & y_im < 0)) = 1 - 1*j;

%---------------------------------------------%
numErrors = size(find([ip- ipHat]),2); % couting the number of errors
 simulatedBER(i)=numErrors/(nSym*nBitsPerSym);
theorySer_QPSK(i) = erfc(sqrt(0.5*(10.^(EsN0dB(i)/10)))) -
(1/4)*(erfc(sqrt(0.5*(10.^(EsN0dB(i)/10))))).^2;

end
semilogy(EsN0dB,simulatedBER,'r-o','LineWidth',2);
hold on;

semilogy(EsN0dB,theorySer_QPSK,'k*','LineWidth',2);



[/QUOTE]

Please check it for me and let me know which part is wrong here. Thank you
so much in advance.
Here is the result graph.


I had only a quick look but I noticed
>> nSym=2
Hint: How many bit errors do I need to observe to get a reliable bit error rate? At a target BER x, how many bits do I need to simulate in average?
>I had only a quick look but I noticed >>> nSym=2 > >Hint: How many bit errors do I need to observe to get a reliable bit
error
>rate? At a target BER x, how many bits do I need to simulate in average? >
Thank you so much for your response. When I try to simulate it, I always set nSym to be very small to save time on running. However when it seems to be ok, I will change nSym to be big number e.g. 10^4, 10^5 and see if it produces accurate result. However in this case, if I change nSym to be 10^5, the result will be the same which is straight line. I am guessing the BER is very small at high Es/No. I cannot really figure it out which part of the simulation is wrong. I have done simulation of BER for BPSK in OFDM and it works using the same code. But when I change to QPSK, the result is just go wrong. I am very beginner in wireless communication so please please help me. Please check for me and figure out which part is wrong.Thank you very much.
can someone please help me. I need to fix this very soon. pleasee 

mackenfy wrote:

> can someone please help me. I need to fix this very soon. pleasee
How much are you willing to pay for getting this job done? VLV
> > >mackenfy wrote: > >> can someone please help me. I need to fix this very soon. pleasee > >How much are you willing to pay for getting this job done? > >VLV >
Just delete me from this website then! I am not student. I just want to learn. and what a racist to insult people like this. You are clever on this topic doesn't mean people who don't have knowledge on the topic you are keen on, is stupid. Because it shows that you are more stupid. Just delete me, delete all my posts PLEASE!
>> >> >>mackenfy wrote: >> >>> can someone please help me. I need to fix this very soon. pleasee >> >>How much are you willing to pay for getting this job done? >> >>VLV >> > >Just delete me from this website then! I am not student. I just want to >learn. and what a racist to insult people like this. You are clever on
this
>topic doesn't mean people who don't have knowledge on the topic you are >keen on, is stupid. Because it shows that you are more stupid. Just
delete
>me, delete all my posts PLEASE! >
Hi Had a glance at your channel Model. Assuming rest you have done is fine, your Channel Model is incorrect. Channel Modelling is not as simple as what you have done. In order to check you BER curve, use Matlab inbuilt channel model. If you get nice bell curve, it means your rest of the chain is fine and will also prove your model is incorrect. You can read some of the books on fading channel modelling for details on how to model a Rayleigh/Ricing faded channel. Regards Hozefa
>>> >>> >>>mackenfy wrote: >>> >>>> can someone please help me. I need to fix this very soon. pleasee >>> >>>How much are you willing to pay for getting this job done? >>> >>>VLV >>> >> >>Just delete me from this website then! I am not student. I just want to >>learn. and what a racist to insult people like this. You are clever on >this >>topic doesn't mean people who don't have knowledge on the topic you are >>keen on, is stupid. Because it shows that you are more stupid. Just >delete >>me, delete all my posts PLEASE! >> > >Hi > >Had a glance at your channel Model. Assuming rest you have done is fine, >your Channel Model is incorrect. Channel Modelling is not as simple as
what
>you have done. In order to check you BER curve, use Matlab inbuilt
channel
>model. If you get nice bell curve, it means your rest of the chain is
fine
>and will also prove your model is incorrect. > >You can read some of the books on fading channel modelling for details on >how to model a Rayleigh/Ricing faded channel. > >Regards >Hozefa >
Hi Also your impulse reponse is modelled wrongly. You are using the same to equalize at the receiver. There is too much to explain to tell you why it is wrong. Only a book on channel modeling will help you. If you have queries in understanding the book, you can post it step by step. I will try to help Regards Hozefa
Few tips:

1. Do not add any channel effect, just use the clean signal and if you can
get all your bits at the receiver. 
2. Start with BPSK (specially when you are learning). It makes life easier.

3. Then add some WGN noise. And run your receiver. 
4. Add some ISI. It can be done in just one line of command. 
5. Then go for higher order modulation.

This might seem a long process but there is ano other alternative. 

Hope this helps. 

Chintan
mackenfy if you have dine this job.please send your code to me i really need this.
saidwali160@yahoo.com