Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
17 years ago

OFDM using DSP Builder

Hi,

I'm trying to implement a simplistic (4 channel) QPSK OFDM transmitter/receiver using Altera's DSP Builder and Megacore IP in Simulink.

Let me just mention that I have very basic knowledge of OFDM and pretty much any book/reference material I read has too much detail and goes over my head. So correct me anywhere I start going off the track.

Let me explain what I have so far (implementing what I have learned so far):

Bits to Trasnmit: 11001011

Since I am using 4 channels (all QPSK), I can transmit 8 bits in parallel. These bits get split up into pairs of two and go into seperate channel busses. Now I have:

Channel 1: 11

Channel 2: 00

Channel 3: 10

Channel 4: 11

These bits get encoded into symbols (using Gray Coded QPSK). So now the channels contain:

Channel 1 I: +0.7071

Channel 1 Q: +0.7071

Channel 2 I: -0.7071

Channel 2 Q: -0.7071

Channel 3 I: +0.7071

Channel 3 Q: -0.7071

Channel 4 I: +0.7071

Channel 4 Q: +0.7071

*note: each I/Q bus is 18 bits

Now I know I need to send the data into the FFT block. The FFT block takes in a real and imag input and I'm completely lost.

Reading the FFT block documentation, I need to scale the input by (2^data_precission - 1). The output should also be scaled by (2^-exp_out / 2^data_precission - 1).

Any help or hint at the right direction would be greatly appreciated.

19 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    orchestradirector and kaz: Thank you both for your help.

    Greatly Appreciated!
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Before I continued with my design, I wanted to make sure I understood how to use the FFT(IFFT) megacore block properly.

    To test, I wrote a .m file where I performed the IFFT using the Matlab's built in ifft() function and Altera's IFFT megacore block using the .m file interface created when the block is generated.

    I got the result from Matlab's ifft function and Altera's IFFT block to come out to be exactly the same (note about scaling later).

    Now, I implemented the FFT block inside of DSP Builder and created a dummy setup with the same inputs as the data in the .m file. I compared the output of the Altera FFT block (from dsp builder) to the output of the Altera FFT (from matlab .m file) and they are totally different.

    Here's a screenshot giving you an idea of what I'm talking about:

    http://img353.imageshack.us/img353/5056/ifftcomparisonmh7.th.png (http://img353.imageshack.us/img353/5056/ifftcomparisonmh7.png)

    I'm attaching both files.

    -------------------

    Now about the scaling issue (this might be related to my problem).

    I have read many different things about "scaling" related the ifft block.

    You have to scale your FFT/IFFT block output by

    2^(-exponent)
    I have also read, that if your input is very small, then it's recommended to scale it on the input side and the same on the output side (aside from the 2^(-exponent)).

    In my .m file, to match the Matlab ifft block output with the Altera IFFT, I tried many scaling factor and somehow came upon this magical scaling property which works for all cases (different N points, different data or twiddle precision):
    Scale input by:2^(Nbits)
    Scale output by:2^(-exponent) / (2^(Nbits+Nbits-1))
    WHEREo Nbits = log2(N) + 1
    o N     = transform length (points)
    
    The thing is, I don't know why it works, but it does (at least in the .m file). For different N (transform length/points) and different data/twiddle precision, it just works!

    Maybe I'm completely off here. I need some more help!

    Thanks
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    Your output symbol shape looks ok to me.

    I believe your scaling must be wrong if you are getting this fiddle factor.

    you need to scale your inputs to the available input resolution as described in previous post e.g. for 8 bits your input can swing between integers -127 & +127. You can go lower if you wish but not higher).

    Use the same scaled input for Matlab ifft and altera ifft.

    Now pay attention to your output scaling:

    Matlab ifft: do not scale output, it is always done for you

    Altera ifft - for their convenience - has introduced scale factor of 2^-exp

    Make sure you are scaling correctly per each block of ifft(per each exp value):

    To multiply by 2^n: shift towards MSb (n) bits inserting leading zeros.

    To divide by 2^n:shift towards LSB (n) bits inserting the sign bits.

    If your shift is larger than available bit space then you must saturate, but this better be avoided in the first place by lowering the input scaling .
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Kaz,

    So I'm back in Matlab making the changes you suggested. Things are starting to make sense. I just have 1 questions/problem now.

    The output of the Altera IFFT, I used the Matlab bitshift function to implement the 2^-exponent scaling. The output of Matlab IFFT and Alera IFFT do not match when I do this. Although if I change 2^-exponent to 2^exponent, then it comes out to be the same (change -outaltexp to outaltexp, on line 27 in fftTestMatlab.m).

    Next goal is to get the same output using DSP Builder.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    I am not familiar with Matlab bitshift but had a quick look at it. It only accepts unsigned integer values. Therefore I suggest you got one more task; you need to convert negative values to equivalent unsigned then reverse that as follows(however, since your function bitshift did not crash on negative values, may be it sees values as unsigned already...I don't how)

    for bitshift input: for n bits signed decimal

    if value is < 0 %negative

    value = value + 2^n;

    end

    for bitshift output:to recover negative values:

    if value >2^(n-1)

    value = value -2^n;

    end

    I can see how Matlab/DSP builder is making life so hard, you better do the shift by hand(in vhdl code)

    kaz
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Just a thought. Since you are working in Matlab platform,Why use bitshift?

    Why not just scale the altera_fft output by 2^-exp directly:

    altera_fft_scaled = altera_fft * 2^(-exp); % that's all

    kaz
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Kaz,

    Even if I scale by multiplication of 2^-exp, I'm getting the same problem. The output scales in the wrong direction, its only equal to the Matlab IFFT output if I multilpy by 2^exp. I triple checked my code, it seems to be correct. Attaching my new .m file.

    My overall goal is to build an OFDM transceiver in DSP Builder using only Altera blocks, currently I'm stuck at the IFFT step of the transmitter. The matlab code was just to test my understanding of the Altera IFFT block and make sure I'm getting the correct result from it before I implement it in my design.

    The real problem here, is what I showed you in my previous post. In DSP Builder, using the same exact parameters of the Altera IFFT block, I'm getting different wave output (not scaled, but completely different shape) from DSP Builder Altera IFFT block compared with Altera IFFT block used from Matlab.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    little left to play around.

    Check that scaling is indeed as stated in the documentation

    Round up your results, just in case:

    symbols = round(inputScale * symbols); % scale the input

    check that altera fft doesn't centre output on dc(Matlab doesn't centre, it nees fftshift to centre it..)

    kaz

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    the Altera FFT core works the same as MATLAB's FFT in that it needs an FFT shift to center DC.

    edit: unless you're using bit-reversed modes.