ofdm simulation

Upload: milica-milicic

Post on 04-Jun-2018

232 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 OFDM Simulation

    1/46

  • 8/13/2019 OFDM Simulation

    2/46

  • 8/13/2019 OFDM Simulation

    3/46

  • 8/13/2019 OFDM Simulation

    4/46

  • 8/13/2019 OFDM Simulation

    5/46

  • 8/13/2019 OFDM Simulation

    6/46

    = +

    ( ) ( ) ( )( ) ( )

    ( ) ( )( )

    =

    = +

    =

    =

    ( )( ) ( )( )( ) ( )

    ( )

    =

    =

    +

    =

    ( )( ) ( ) ( )( )( ) ( )

    +

    =

    =

    ( ) ( )( ) ( ) ( )( )( )

    +

    =

    =

    ( )

    =

    = +

    ( ) ( )

    ( )

    =

  • 8/13/2019 OFDM Simulation

    7/46

    =

    = =

    = + =

    = + =

    = =

    = =

    = =

  • 8/13/2019 OFDM Simulation

    8/46

    =+

    ( ) ( ) ( )( ) ( ) = =

    =

    +

  • 8/13/2019 OFDM Simulation

    9/46

    ( ) ( )( ) =

    < >

    ( ) ( ) ( ) ( ) = +

    ( ) ( ) ( )( )

    = +

    ( ) ( )( ) ( )

    ( )

    =

  • 8/13/2019 OFDM Simulation

    10/46

    ( )

    +

    ( )

    +

    ( )

    +

    ( )

    +

    ( )

    +

  • 8/13/2019 OFDM Simulation

    11/46

  • 8/13/2019 OFDM Simulation

    12/46

  • 8/13/2019 OFDM Simulation

    13/46

    para=128; % Number of parallel channel

    fftlen=128; % FFT length

    noc=128; % Number of carrier

    nd=6; % Number of OFDM symbol for one loop

    ml=2; % Modulation level: QPSK

    sr=250000; % Symbol rate

    br=sr.*ml; % Bit rate per carrier

    gilen=32; % Length of guard interval

    ebn0=100 % ebn0 : Eb/No

    =

    nloop=100; % Number of simulation loops

    noe=0; % Number of error data

    nod=0; % Number of transmitted data

    eop=0; % Number of error packet

    nop=0; % Number of transmitted packet

  • 8/13/2019 OFDM Simulation

    14/46

    seridata

    seridata=rand(1,para*nd*ml)>0.5;

    seridata paradata

    paradata=reshape(seridata,para,nd*ml);Next, the vector

    paradata was fed into the mapping circuit. In the

    circuit, the parallel data were converted into modulated

    parallel data of two channels, Ich and Qch by a predefined

    mapping method.

    [ich,qch]=qpskmod(paradata,para,nd,ml);

    kmod

  • 8/13/2019 OFDM Simulation

    15/46

  • 8/13/2019 OFDM Simulation

    16/46

    kmod=1/sqrt(2);

    ich1=ich.*kmod;

    qch1=qch.*kmod;

    x=ich1+qch1.*i;

    y=ifft(x); % ifft : built-in function

    ich2=real(y); % real : built-in function

    qch2=imag(y); % imag : built-in function

    ich2 qch2

    [ich3,qch3]= giins(ich2,qch2,fftlen,gilen,nd);

    fftlen2=fftlen+gilen;

    fftlen2

  • 8/13/2019 OFDM Simulation

    17/46

  • 8/13/2019 OFDM Simulation

    18/46

    comb.m

    attn attn spow spow para

    spow=sum(ich3.^qch3)./nd./para;

    attn=0.5*spow*sr/br*10.^(-ebn0/10);

    attn=sqrt(attn);

    attn

    comb.m

    [ich4,qch4]= comb(ich3,qch3,length(ich3),attn);

    [ich5,qch5]= girem(ich4,qch4,fftlen2,gilen,nd);

    ich5 qch5

    rx=ich5+qch5.*i;

    ry=fft(rx);

    ich6=real(ry);

    qch6=imag(ry);

    kmod

    ich7=ich6./kmod;

    qch7=qch6./kmod;

    [demodata]=qpskdemod(ich7,qch7,para,nd,ml);

    demodata1

    demodata1=reshape(demodata,1,para*nd*ml);

    seridata demodata1

  • 8/13/2019 OFDM Simulation

    19/46

    % instantaneous number of errors and data bits

    noe2=sum(abs(seridata-demodata1); nod2=length(seridata);

    % cumulative number of errors and data bits in noe and nod

    noe=noe+noe2;nod=nod+nod2;

    % calculating PER

    if noe2~=0

    eop=eop+1;

    else

    eop=eop;

    end

    eop;

    nop=nop+1;

    ber=noe/nod;

    per=eop/nop;

    ofdm

    +

    =

  • 8/13/2019 OFDM Simulation

    20/46

    =

    gilen

    fftlen2

    gilen fftlen2

    % Generated data are fed into a fading simulator

    [ifade,qfade]=sefade(ich3,qch3,itau,dlv1,th1,n0,itnd1,...

    now1,length(ich3),tstp,fd,flat);

    % Updata fading counter

    itnd1=itnd1+itnd0

    flat

  • 8/13/2019 OFDM Simulation

    21/46

  • 8/13/2019 OFDM Simulation

    22/46

  • 8/13/2019 OFDM Simulation

    23/46

    = = =

    =

    = =

  • 8/13/2019 OFDM Simulation

    24/46

  • 8/13/2019 OFDM Simulation

    25/46

    paradata=reshape(seridata,para,nd*ml);

    paradata

    [ich,qch]=qpskmod(paradata,para,nd,ml);

    kmod

    kmod=1/sqrt(2);

    ich1=ich.*kmod;

    qch1=qch.*kmod;

    Ich Qch

    [ich1,qch1]=crmapping(ich,qch,fftlen,nd);

    ich1 qch1

    X=ich1+qch1.*i; % i : complex number

    y=ifft(x); % ifft : built-in function

    ich2=real(y); % real : built-in function

    qch2=imag(y); % imag : built-in function

    fftlen2=fftlen+gilen;

    [ich4,qch4]= giins(ich2,qch2,fftlen,gilen,nd);

    fftlen2

    % %

  • 8/13/2019 OFDM Simulation

    26/46

    comb.m

  • 8/13/2019 OFDM Simulation

    27/46

    attn attn spow

  • 8/13/2019 OFDM Simulation

    28/46

    spow para

    spow=sum(ich4.^2+qch4.^2)/nd./para;

    attn=0.5*spow*sr/br*10.^(-ebn0/10);

    attn=sqrt(attn);

    attn comb.m

    [ich5,qch5]=comb(ich4,qch4,attn);

    ich5 qch5

    [ich6,qch6]= girem(ich5,qch5,fftlen2,gilen,nd);

    ich6 qch6

    rx=ich6+qch6.*i;

    ry=fft(rx); % fft : built in function

    ich7=real(ry);

    qch7=imag(ry);

    [ich8,qch8]=crdemapping(ich7,qch7,fftlen,nd);

    kmod

    [ich8,qch8]=crdemapping(ich7,qch7,fftlen,nd);

    ich9=ich8./kmod;

    qch9=qch8./kmod;

    [demodata]=qpskdemod(ich9,qch9,para,nd,ml);

    demodata1

    demodata1=reshape(demodata,1,para*nd*ml);

    seridata demodata1

  • 8/13/2019 OFDM Simulation

    29/46

    % instantaneous number of errors and data

    noe2=sum(abs(demodata1-seldata)); nod2=length(seldata);

    % length : built in function

    % calculating BERnoe=noe+noe2;

    nod=nod+nod2;

    % calculating PER

    if noe2~=0

    eop=eop+1;

    else

    eop=eop;

    end

    eop;

    nop=nop+1;

    per=eop/nop;

    ber=noe/nod;

    ofdmda.m

    +

    +

  • 8/13/2019 OFDM Simulation

    30/46

    =

    gilen

    fftlen2

    gilen fftlen2

    % flat

    +

  • 8/13/2019 OFDM Simulation

    31/46

    %CE data generation

    Ich

    % CE data generation

    kndata=zeros(1,fftlen);

    kndata0=2.*(rand(1,52)>0.5)-1;

    kndata(2:27)=kndata0(1:26);

    kndata(39:64)=kndata0(27:52);

    ceich=kndata; % CE:BPSK

    ceqch=zeros(1,64);

    %--------data mapping (DC=0)--------

    [ich1,qch1]=crmapping(ich,qch,fftlen,nd);

    ich2=[ceich. ich1]; % I-channel transmitted data

    qch2=[ceqch. qch1]; % Q-channel transmitted data

    ich2 qch2

    %--------- IFFT ---------

    x=ich2+qch2.*i;

    y=ifft(x);

    ich3=real(y);

    qch3=imag(y);

    rx=ich6+qch6.*i;

    ry=fft(rx);

    ich7=real(ry);

    qch7=imag(ry);

    %-------- fading compensation by CEsymbol --------

    ich7 qch7

    % taking pilot data out of received data

    ce=1;

    ice1=ich7(:,ce);

    qce1=qch7(:,ce);

  • 8/13/2019 OFDM Simulation

    32/46

    % preparation known CE data

    ce=1;ice0=ich2(:,ce);

    qce0=qch2(:,ce);

    ice1

    qcel

    ice0

    qce0

    ice1

    qce1

    ice0

    qce0

    =

    =

    =

    +

    ( )=+

    +

    icel qcelice0 ice1 qce0 qce1

    ( )=+

    icel qcelqce0 ice1 ice0 qce1

    % calculating reverse rotation

    iv=real((1./(ice1.^2+qce1.^2)).*(ice0+i.*qce0).*...

    (ice1-i.*qce1));

    qv=imag((1./(ice1.^2+qce1.^2)).*(ice0+i.*qce0).*...

    (ice1-i.*qce1));

  • 8/13/2019 OFDM Simulation

    33/46

    % matrices for reverse rotation

    ieqv1=[iv iv iv iv iv iv iv];

    qeqv1=[qv qv qv qv qv qv qv];

    7

    ich7 qch7 icompen qcompen ich7 qch7icompen qcompen ieq1 qeq1

    icompen ich7 ieqv1 qch7 qeqv1=

    qcompen qch7 ieqv1 ich7 qeqv1= +

    % reverse rotation

    icompen=real((ich7+i.*qch7).*(ieqv1+i.*qeqv1));

    qcompen=imag((ich7+i.*qch7).*(ieqv1+i.*qeqv1));

    ich7=icompen;qch7=qcompen;

    %-------- CE symbol removal ---------

    ich8=ich7(:,knd+1:nd+1);

    qch8=qch7(:,knd+1:nd+1);

    % %----Fading compensationby CE symbol

  • 8/13/2019 OFDM Simulation

    34/46

    +

    +

  • 8/13/2019 OFDM Simulation

    35/46

    %-------interference wave initialization -------

    ci=10; % C/I ratio

    ml2=2; % modulation level

    itau2=[0];dlvl2=[0];

    n02=[6];

    th2=[0.0];

    itnd2=[10000+floor(rand(1)*10)*1000];

    now2=1;

    fd2=fd;

    flat2=0;

    % Number of fading counter to skip

    itnd02=nd*(fftlen+gilen)*300;

    fadingpara

    % store all parameters in one matrix fadingpara

    fadingpara=zeros(8,length(itau2));

    fadingpara(1,:)=itau2;

    +

    +

  • 8/13/2019 OFDM Simulation

    36/46

    fadingpara(2,:)=dlvl2;

    fadingpara(3,:)=n02;

    fadingpara(4,:)=th2;

    fadingpara(5,:)=itnd2;fadingpara(6,:)=now2;

    fadingpara(7,:)=fd2;

    fadingpara(8,:)=flat2;

    fadingpara

    %%% interference wave addition

    % interference

    [iintw,qintw]=interwave(ci,spow,ml2,length(ich4),tstp,fadingpara);

    itnd2=itnd2+itnd02;

    fadingpara(5,:)=itnd2;

    ich4=ich4+iintw;

    qch4=qch4+qintw;

    ==

  • 8/13/2019 OFDM Simulation

    37/46

    =

    =

  • 8/13/2019 OFDM Simulation

    38/46

  • 8/13/2019 OFDM Simulation

    39/46

    % Program 4-1

    % ofdm.m

    %

    % Simulation program to realize OFDM transmission system

    %

    % programmed by T. Yamamura and H. Harada

    %

    %****************** preparation part ******************

    para=128; % Number of parallel channel to transmit

    fftlen=128; % FFT length

    noc=128; % Number of carrier

    nd=6; % Number of information OFDM symbol for

    % one loop

    ml=2; % Modulation level : QPSK

    sr=250000; % Symbol rate

    br=sr.*ml; % Bit rate per carrier

    gilen=32; % Length of guard interval (points)

    ebn0=3; % Eb/N0

    %******************** main loop part ******************

    nloop=100; % Number of simulation loops

    noe = 0; % Number of error data

    nod = 0; % Number of transmitted data

    eop=0; % Number of error packet

    nop=0; % Number of transmitted packet

    for iii=1:nloop

    %******************** transmitter *********************

    %****************** Data generation *******************

    seldata=rand(1,para*nd*ml) > 0.5;

    % rand : built in function

    %*********** Serial to parallel conversion ************

    paradata=reshape(seldata,para,nd*ml);

    % reshape : built in function

    %******************* QPSK modulation ******************

    [ich,qch]=qpskmod(paradata,para,nd,ml);

    kmod=1/sqrt(2); % sqrt : built in function

  • 8/13/2019 OFDM Simulation

    40/46

    ich1=ich.*kmod;

    qch1=qch.*kmod;

    %************************ IFFT ************************

    x=ich1+qch1.*i;

    y=ifft(x); % ifft : built in function

    ich2=real(y); % real : built in function

    qch2=imag(y); % imag : built in function

    %************** Guard interval insertion **************

    [ich3,qch3]= giins(ich2,qch2,fftlen,gilen,nd);

    fftlen2=fftlen+gilen;

    %**************** Attenuation Calculation *************

    spow=sum(ich3.^2+qch3.^2)/nd./para;

    % sum : built in function

    attn=0.5*spow*sr/br*10.^(-ebn0/10);

    attn=sqrt(attn);

    %********************* Receiver *********************

    %******************** AWGN addition *******************

    [ich4,qch4]=comb(ich3,qch3,attn);

    %***************** Guard interval removal *************

    [ich5,qch5]= girem(ich4,qch4,fftlen2,gilen,nd);

    %*********************** FFT ************************

    rx=ich5+qch5.*i;

    ry=fft(rx); % fft : built in functionich6=real(ry); % real : built in function

    qch6=imag(ry); % imag : built in function

    %********************* demodulation *******************

    ich7=ich6./kmod;

    qch7=qch6./kmod;

    [demodata]=qpskdemod(ich7,qch7,para,nd,ml);

    %*********** Parallel to serial conversion ************

    demodata1=reshape(demodata,1,para*nd*ml);

    %**************** Bit Error Rate (BER) ****************

    % instantaneous number of error and data

  • 8/13/2019 OFDM Simulation

    41/46

    noe2=sum(abs(demodata1-seldata));

    % sum : built in function

    nod2=length(seldata);

    % length : built in function

    % cumulative the number of error and data in noe and nod

    noe=noe+noe2;

    nod=nod+nod2;

    % calculating PER

    if noe2~=0

    eop=eop+1;

    else

    eop=eop;

    end

    eop;

    nop=nop+1;

    fprintf(%d\t%e\t%d\n,iii,noe2/nod2,eop);

    % fprintf : built in function

    end

    %******************* Output result ********************

    per=eop/nop;

    ber=noe/nod;

    fprintf(%f\t%e\t%e\t%d\t\n,ebn0,ber,per,nloop);

    fid = fopen(BERofdm.dat,a);

    fprintf(fid,%f\t%e\t%e\t%d\t\n,ebn0,ber,per,nloop);

    fclose(fid);

    %********************* end of file ********************

    % Program 4-2

    % ofdm_fading.m

    %

    % Simulation program to realize OFDM transmission system

    % (under one path fading)

    %

    % programmed by T. Yamamura and H. Harada

    %

    %****************** preparation part ******************

    para=128; % Number of parallel channel to transmit

    fftlen=128; % FFT length

  • 8/13/2019 OFDM Simulation

    42/46

    noc=128; % Number of carrier

    nd=6; % Number of information OFDM symbol for

    % one loop

    ml=2; % Modulation level : QPSKsr=250000; % Symbol rate

    br=sr.*ml; % Bit rate per carrier

    gilen=32; % Length of guard interval (points)

    ebn0=10; % Eb/N0

    %*************** Fading initialization ****************

    % If you use fading function sefade, you can

    % initialize all of the parameters.

    % Otherwise you can comment out the following

    % initialization.

    % The detailed explanations of all of variables are

    % mentioned in Program 2-8.

    % Time resolution

    tstp=1/sr/(fftlen+gilen);

    % Arrival time for each multipath normalized by tstp

    % If you would like to simulate under one path fading

    % model, you have only to set% direct wave.

    itau = [0];

    % Mean power for each multipath normalized by direct

    % wave.

    % If you would like to simulate under one path fading

    % model, you have only to set

    % direct wave.

    dlvl = [0];

    % Number of waves to generate fading for each multipath.

    % In normal case, more than six waves are needed to

    % generate Rayleigh fading

    n0=[6];

    % Initial phase of delayed wave

    % In this simulation one-path Rayleigh fading is

    % considered.

    th1=[0.0];

    % Number of fading counter to skipitnd0=nd*(fftlen+gilen)*10;

    % Initial value of fading counter

    % In this simulation one-path Rayleigh fading is

    % considered.

    % Therefore one fading counter is needed.

  • 8/13/2019 OFDM Simulation

    43/46

    itnd1=[1000];

    % Number of direct wave + Number of delayed wave

    % In this simulation one-path Rayleigh fading is% considered

    now1=1;

    % Maximum Doppler frequency [Hz]

    % You can insert your favorite value

    fd=320;

    % You can decide two modes to simulate fading by changing

    % the variable flat

    % flat : flat fading or not% (1-flat (only amplitude is fluctuated),0-normal(phase

    % and amplitude are fluctuated))

    flat =1;

    %******************* main loop part *******************

    nloop=500; % Number of simulation loops

    noe = 0; % Number of error datanod = 0; % Number of transmitted data

    eop=0; % Number of error packet

    nop=0; % Number of transmitted packet

    for iii=1:nloop

    %********************* transmitter ********************

    %****************** Data generation *******************

    seldata=rand(1,para*nd*ml) > 0.5;

    % rand : built in function

    %*********** Serial to parallel conversion ************

    paradata=reshape(seldata,para,nd*ml);

    % reshape : built in function

    %****************** QPSK modulation *******************

    [ich,qch]=qpskmod(paradata,para,nd,ml);

    kmod=1/sqrt(2); % sqrt : built in function

    ich1=ich.*kmod;

    qch1=qch.*kmod;

  • 8/13/2019 OFDM Simulation

    44/46

    %************************ IFFT ************************

    x=ich1+qch1.*i;

    y=ifft(x); % ifft : built in functionich2=real(y); % real : built in function

    qch2=imag(y); % imag : built in function

    %************** Guard interval insertion **************

    [ich3,qch3]= giins(ich2,qch2,fftlen,gilen,nd);

    fftlen2=fftlen+gilen;

    %*************** Attenuation Calculation **************

    spow=sum(ich3.^2+qch3.^2)/nd./para;% sum : built in function

    attn=0.5*spow*sr/br*10.^(-ebn0/10);

    attn=sqrt(attn);

    %******************* Fading channel *******************

    % Generated data are fed into a fading simulator

    [ifade,qfade]=sefade(ich3,qch3,itau,dlvl,th1,n0,itnd1,...

    now1,length(ich3),tstp,fd,flat);

    % Updata fading counter

    itnd1 = itnd1+ itnd0;

    %********************** Receiver *********************

    %******************** AWGN addition *******************

    [ich4,qch4]=comb(ifade,qfade,attn);

    %*************** Guard interval removal ***************

    [ich5,qch5]= girem(ich4,qch4,fftlen2,gilen,nd);

    %*********************** FFT ************************

    rx=ich5+qch5.*i;

    ry=fft(rx); % fft : built in function

    ich6=real(ry); % real : built in function

    qch6=imag(ry); % imag : built in function

    %******************** demodulation ********************

    ich7=ich6./kmod;

    qch7=qch6./kmod;

    [demodata]=qpskdemod(ich7,qch7,para,nd,ml);

    %*********** Parallel to serial conversion ************

  • 8/13/2019 OFDM Simulation

    45/46

    demodata1=reshape(demodata,1,para*nd*ml);

    %**************** Bit Error Rate (BER) ****************

    % instantaneous number of error and data

    noe2=sum(abs(demodata1-seldata));

    % sum : built in function

    nod2=length(seldata);

    % length : built in function

    % cumulative the number of error and data in noe and nod

    noe=noe+noe2;

    nod=nod+nod2;

    % calculating PER

    if noe2~=0

    eop=eop+1;

    else

    eop=eop;

    end

    eop;

    nop=nop+1;

    fprintf(%d\t%e\t%d\n,iii,noe2/nod2,eop);% fprintf : built in function

    end

    %******************* Output result ********************

    per=eop/nop;

    ber=noe/nod;

    fprintf(%f\t%e\t%e\t%d\t\n,ebn0,ber,per,nloop);

    fid = fopen(BERofdmfad.dat,a);fprintf(fid,%f\t%e\t%e\t%d\t\n,ebn0,ber,per,nloop);

    fclose(fid);

    %********************* end of file ********************

    % Program 4-3

    % giins.m

    %

    % Function to insert guard interval into transmission

    % signal

    %

    % Programmed by T. Yamamura and H. Harada

    %

  • 8/13/2019 OFDM Simulation

    46/46

    function [iout,qout]= giins(idata,qdata,fftlen,gilen,nd);

    %********************** variables *********************

    % idata : Input Ich data

    % qdata : Input Qch data

    % iout : Output Ich data

    % qout : Output Qch data

    % fftlen : Length of FFT (points)

    % gilen : Length of guard interval (points)

    % *****************************************************

    idata1=reshape(idata,fftlen,nd);

    qdata1=reshape(qdata,fftlen,nd);idata2=[idata1(fftlen-gilen+1:fftlen,:); idata1];

    qdata2=[qdata1(fftlen-gilen+1:fftlen,:); qdata1];

    iout=reshape(idata2,1,(fftlen+gilen)*nd);

    qout=reshape(qdata2,1,(fftlen+gilen)*nd);

    %******************** end of file *********************

    % Program 4-4

    % girem.m

    %

    % Function to remove guard interval from received signal

    %

    % Programmed by T. Yamamura and H. Harada

    %

    function [iout,qout]= girem(idata,qdata,fftlen2,gilen,nd);

    %********************** variables *********************

    % idata : Input Ich data

    % qdata : Input Qch data

    % iout : Output Ich data

    % qout : Output Qch data

    % fftlen2 : Length of FFT (points)

    % gilen : Length of guard interval (points)

    % nd : Number of OFDM symbols

    % *****************************************************

    idata2=reshape(idata,fftlen2,nd);

    qdata2 reshape(qdata fftlen2 nd);