cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Explorer
Explorer
10,454 Views
Registered: ‎02-18-2008

FFT v 5.0

Jump to solution

Hi,

 

I'm using Ise 9.2 sp4 and I  want to generate a FFT core.

 

I use the core generator and modelsim.

 

Now I have generated a dds which generates a sine wave (8 bits  length ). The input issent to FFT real part port.

 

I assert the start FFT and wait until conversion (1024 point fft - radix-2 burst unscaled ).

 

When the fft start to unload the fft results I have noticed these strange situations:

 

1) the signal xk_n (output counter) send "random) number insteadof 0,1,2,...1023

2) the real part of FFT (19 bits length) is similar to noise, and I don't see the tone generated from DDS.

 

Can anyone help me?

 

I haven't find any  solution...

 

Best REgards,

 

Alexiul

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Xilinx Employee
Xilinx Employee
7,815 Views
Registered: ‎11-28-2007

Your matlab code for importing the data doesn't work well. Try this:

 

function value = importfile(fileName,nbits)
a = fi(0,1,nbits,nbits-1);
h = fopen(fileName,'r');
i = 1;
index = zeros(1,1024);
while ~feof(h)
    str = fscanf(h, '%s',1);
    % Get xk_index and store inside an array
    indice = fscanf(h, '%d', 1);

    if length(str) > 0    
        index(1,i) = indice;
        a.hex = str;
        %disp(a.hex);
        valueTmp(i) = a.double;
        i = i+1;
    end;   
end;

fclose(h);
valueTmp = valueTmp';
 
% Re-order FFT output according xk_index
for i = 1:length(valueTmp)
    value(index(i)+1) = valueTmp(i);
end

 

Cheers,

Jim

 

Cheers,
Jim

View solution in original post

23 Replies
Highlighted
Xilinx Employee
Xilinx Employee
10,433 Views
Registered: ‎11-28-2007

When you generated the core, what (Bit Reversed Order or Natural order) did you select for "Output Ordering"?

 

Below is the excerpt from FFT core datasheet:

 

In the Radix-2, Burst I/O, Radix-2 Lite, Burst I/O and Pipelined, Streaming I/O architectures, the Bit
Reverse order is simple to calculate, by taking the index of the data point, written in binary, and reversing
the order of the digits. Hence, 0000, 0001, 0010, 0011, 0100,...(0, 1, 2, 3, 4,...) becomes 0000, 1000, 0100,
1100, 0010,...(0, 8, 4, 12, 2,...).

 

Cheers,

Jim

Cheers,
Jim
0 Kudos
Highlighted
Explorer
Explorer
10,406 Views
Registered: ‎02-18-2008

Hi Jim,

 

it's perfectly true, infact I use these lines for invert the out index (Reversed output)

 

  
   for i in 0 to 9 loop       
    indexOut(i) <= xk_index(9 -i);
   end loop;

 

but the result from fft is totally incorrect; I add as attachment two matlab figure and the output of the fft...

 

in the figure "noArrange.jpg" I don't reorder the output, in "Arrange.jpg" I invert the result.

 

If you want I can post the code, testbench and do file...

 

thanks a lot for your help

AlexGiul

0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
10,403 Views
Registered: ‎11-28-2007

Sorry, I don't have SW for .rar files. Can you zip it up?

 

Cheers,

Jim

 

Cheers,
Jim
0 Kudos
Highlighted
Explorer
Explorer
10,391 Views
Registered: ‎02-18-2008

No problem, Jim

 

if you want I can zip  all the xilinx project and send you.

 

 I use this simple script to generate plots:

 

A = importfile('F:\XilinxWork\model_udp\output\fft_output_re.txt',19);

 

 %------------------------------------------------------------------------

function value = importfile(fileName,nbits)

clc

a = fi(0,1,nbits,nbits-1);

%a = fi(0,1,19,7);

h = fopen(fileName,'r');

 

i = 1;

 

while ~feof(h)

str = fscanf(h, '%s',[1 1]);

if length(str) > 0

a.hex = str;

% disp(a.hex);

value(i) = a.double;

i = i+1;

end;

end;

 

value = value';

fclose(h);

 

0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
10,377 Views
Registered: ‎11-28-2007

Please take a look at this http://www.mathworks.com/support/tech-notes/1700/1702.htm on how to do spectral analysis. 

 

Cheers,

Jim

 

 

 

Cheers,
Jim
0 Kudos
Highlighted
Explorer
Explorer
10,373 Views
Registered: ‎02-18-2008

Hi Jim,

 

I put the above link on my prefereed site!!!

 

But the plot which I sent you, are generated "on fly"...

 

the problem is that: the dds generates a 5 Mhz tone and this signal i sent to FFT...you cannot see any tone on the plot.

 

I add my design and "testFFT_tb1_vhd.do" to test it.

0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
10,368 Views
Registered: ‎11-28-2007

Please read the article in the link to find out what to plot to get the tone. (Hint: it's not just the real part of the fft result).

 

Cheers,

Jim

Cheers,
Jim
0 Kudos
Highlighted
Explorer
Explorer
10,363 Views
Registered: ‎02-18-2008

Hi Jim,

 

I read the doc and I produce this plot in attach....the result is wrong...

 

Now I use both real part and the imaginary part from fft block.

 

 

powerFFT.jpg
0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
10,359 Views
Registered: ‎11-28-2007

Two things:

 

1. Why do you do this in your tb:

        
            for i in 0 to 18 loop           
                tmp(i) := xk_re(18-i);               

                --tmp(i) := xk_re(i);               
            end loop;

 

2.  You bit-reverse the xk_index, but you're not using rearranged index "indiceOut".

 

Cheers,

Jim

 

Cheers,
Jim
0 Kudos
Highlighted
Explorer
Explorer
9,114 Views
Registered: ‎02-18-2008

Hi Jim

 

in the newer version I replace with these :

 

            for i in 0 to 18 loop           
                tmpRe(i) := xk_re(18-i);               
                tmpIm(i) := xk_im(18-i);                                       
            end loop;
           
            for i in 0 to 9 loop                           
                indiceOut(i) <= xk_index(9 -i);
            end loop;

 

1) Because I understand that I have to bit-reverse the output , so bit-reverse and write in file

 

2) Yes I don't use now, but my target will be writing the fft output  to a ram

0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
9,111 Views
Registered: ‎11-28-2007

It is the output order that is bit-reversed, not the output value.

 

Cheers,

Jim

 

Cheers,
Jim
0 Kudos
Highlighted
Explorer
Explorer
9,106 Views
Registered: ‎02-18-2008

Hi Jim,

 

you're right, I check on the datasheet figure 14 and 15 and I see that bit-reversed is only the xk_index.

 

Now, I remove the code for reverse the output values without no improvement...the 5 Mhz tone is always absent.

 

 

0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
9,095 Views
Registered: ‎11-28-2007

You first need to reorder the output. Otherwise, you may see a tone, but not at 5MHz. Or I would just select the natural output order in coregen and regenerate the core if the extra latency doesn't matter to your applicaiton.

 

Can you post you latest matlab code for plotting the fft result?

 

Cheers,

Jim

 

Cheers,
Jim
0 Kudos
Highlighted
Explorer
Explorer
9,094 Views
Registered: ‎02-18-2008

Hi Jim,

 

You're right, but for now I would see a tone... :) :) :)

 

This is the last version with your contribution of malab file 

 

0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
9,091 Views
Registered: ‎11-28-2007

I can see a tone in the plot:

 

Cheers,

Jim

 

Cheers,
Jim
ScreenHunter_01 Feb. 28 07.09.jpg
0 Kudos
Highlighted
Explorer
Explorer
9,089 Views
Registered: ‎02-18-2008

.... another step to solve my problem: thanks Jim!

 

Now, I re-order the otuput into the matlab file with these line code:

 

(displayFFT.m)

fftxTmp = Re + i.*Im;

 

for i = 1:length(fftxTmp)

fftx(length(fftxTmp)-(i-1)) = fftxTmp(i);

end

 

With the output re-ordening, I see two tone at 1 Mhz, and the second at 9 Mhz, why?

The dds should generate a 5 Mhz tone.

 

The plot is:

 

 

 

 

fftPower.jpg
0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
9,087 Views
Registered: ‎11-28-2007

The way you did reordering is not quite right. Remeber that the output are in the bit-reversed order. xk_index (again, it's bit-reversed) tells you the position of each FFT value.  You will need to make use of the indiceOut value that you calculated in your testbench.

 

Cheers,

Jim

 

Cheers,
Jim
0 Kudos
Highlighted
Explorer
Explorer
9,078 Views
Registered: ‎02-18-2008

Hi Jim,

 

I'm sorry but I don't understand...

 

I'm reading the datasheet page 31 figure 15 xfft_ds260.pdf , in the timing diagram you cannot see how the output order should be...

 

I inverted the xk_index and I get correct values 0,1,2,3,....,1020,1021,1022,1023 ("indiceOut")

 

but for the output of fft I don't find the mistake...

0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
9,063 Views
Registered: ‎11-28-2007

Sorry my mistake. xk_index is the actual postion of the corresponding xk_re and xk_im. The bit reversed order is the order the fft data come out. If the fft core didn't output the xk_index, you would need to get the actual index yourself by bit reversing.

 

Anyway, in your case, xk_index = 0, 512, 256, 768,128, ... you will need to assign the 1st xk_re data to value(0),  2nd to value(512), 3rd to value(256)... and then do the same for xk_im.

 

I will let you figure out the rest. The good news is that everything works (see the 5MHz tone in the plot below).

 

Cheers,

jim

 

Message Edited by jimwu on 02-28-2009 02:23 PM
Cheers,
Jim
ScreenHunter_02 Feb. 28 14.04.jpg
0 Kudos
Highlighted
Explorer
Explorer
7,041 Views
Registered: ‎02-18-2008

Hi Jim,

 

I change a bit the matlab function to read the file data, now I take from the simulation also the xk_index and I re-order the fft output according xk_index:

 

this is the matlab code:

function value = importfile(fileName,nbits) a = fi(0,1,nbits,nbits-1); h = fopen(fileName,'r'); i = 1; index = zeros(1,1024); while ~feof(h) str = fscanf(h, '%s',[1 1]);

 

% Get xk_index and store inside an array indice = fscanf(h, '%d'); index(i) = indice(1,1); if length(str) > 0 a.hex = str; % disp(a.hex); valueTmp(i) = a.double; i = i+1; end; end; fclose(h); valueTmp = valueTmp';

 

% Re-order FFT output according xk_index for i = 1:length(valueTmp) value(index(i)+1) = valueTmp(i); end

 

In the vhdl file "testFFT_tb1.vhd" I removed the line which invert the xk_index:

 

 

. ....

..... 

process(clk50) variable Iline_re,Iline_im : line; begin if rising_edge(clk50) then if dv = '1' then write(Iline_re,hstr( xk_re )); write(Iline_re,string'(" ")); write(Iline_re,CONV_INTEGER(xk_index) ); write(Iline_im,hstr( xk_im )); write(Iline_im,string'(" ")); write(Iline_im,CONV_INTEGER(xk_index) ); writeline(vectors_re,Iline_re); writeline(vectors_im,Iline_im); end if; end if; end process;

 

why is my plot totally wrong???

 

Can you post the right code or do correction to mine?

 

Thanks a lot,

Alexgiul

 

fftPower.jpg
0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
7,816 Views
Registered: ‎11-28-2007

Your matlab code for importing the data doesn't work well. Try this:

 

function value = importfile(fileName,nbits)
a = fi(0,1,nbits,nbits-1);
h = fopen(fileName,'r');
i = 1;
index = zeros(1,1024);
while ~feof(h)
    str = fscanf(h, '%s',1);
    % Get xk_index and store inside an array
    indice = fscanf(h, '%d', 1);

    if length(str) > 0    
        index(1,i) = indice;
        a.hex = str;
        %disp(a.hex);
        valueTmp(i) = a.double;
        i = i+1;
    end;   
end;

fclose(h);
valueTmp = valueTmp';
 
% Re-order FFT output according xk_index
for i = 1:length(valueTmp)
    value(index(i)+1) = valueTmp(i);
end

 

Cheers,

Jim

 

Cheers,
Jim

View solution in original post

Highlighted
Explorer
Explorer
7,018 Views
Registered: ‎02-18-2008

Hi Jim, thanks a lot for your help!

Now I have correct results!!!

 

 

I see that I can scale the fft output and use less harware resources... for my case Radix 2 Burst 1024 pionts on page 21 the value of SCALE_SCH should be 20

 

but I don't understand how put this value into the  SCALE_SCH.

 

I see the example for radix-4 Burst [1 0 2 3 2] which became in binary x"0001 0000 0010 0011 0010" , but from the fromula I obtain 10.

 

Do you know a valid schedule scaling for radix2 burst 1024 fft?

 

0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
6,995 Views
Registered: ‎11-28-2007

This thread is getting too long. Can you start a new one and post your question?

 

Cheers,

Jim

 

Cheers,
Jim
0 Kudos