FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > DSP

DSP comp.dsp newsgroup, mailing list

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-17-2005, 02:12 PM
Fred
Guest
 
Posts: n/a
Default [FFTW] Cyclic results with FFTW?

Dear all,

I implemented some test FFT's from various libraries, having
decomposed and reconstructed a simple signal (sine), my code worked
for all of them however, the signal I got using fftw was not
reconstructed correctly, indeed, the transform is not cyclic.

How to get cyclic output from fftw?

Below is a code in 1D I used. sorry to ask such a trivial question and
thanks for your answer...

Fred



--------- C CODE ----------

#include <stdio.h>
#include <math.h>

#include <fftw3.h>

unsigned flags = FFTW_ESTIMATE | FFTW_PRESERVE_INPUT;

/* volontary not equal to 2^n (n E ZZ+*) */
F = fopen("FULLT", "w");


for(i=0; i<ARRAY_SIZE; i++) {
A[i] = sin(i/10.);
B[i] = 0;
}

for(i=0; i<ARRAY_SIZE; i++) {
fprintf(o, "%u\t%f\n", i, A[i]);
}

/* this just interleaves A & B into C */
interleave(C, A, B, ARRAY_SIZE, 0);

for(i=0; i<ARRAY_SIZE; i++) {
fprintf(R, "%u\t%f\n", i, A[i]);
}

p = fftw_plan_dft_r2c_1d(ARRAY_SIZE, A, C, flags);
fftw_execute(p);

/* this just splits C into A & B */
split(A, B, (const fftw_complex * const) C, ARRAY_SIZE, 0);

for(i=0; i<ARRAY_SIZE; i++) {
fprintf(R, "%u\t%f\n", i, A[i]);
fprintf(I, "%u\t%f\n", i, B[i]);
fprintf(F, "%u\t%f\n", i, sqrt(A[i]*A[i] + B[i]*B[i]));
}

interleave(A, B, ARRAY_SIZE, 0);

invp = fftw_plan_dft_c2r_1d(ARRAY_SIZE, C, A, flags);
fftw_execute(invp);

split B, (const fftw_complex * const) C, ARRAY_SIZE, 0);

for(i=0; i<ARRAY_SIZE; i++) {
fprintf(O, "%u\t%f\n", i, A[i]/ARRAY_SIZE);
}

fftw_destroy_plan(p);
fftw_destroy_plan(invp);
fftw_cleanup();

fclose(I);
fclose(R);
fclose(O);
fclose(o);
fclose(F);

return EXIT_SUCCESS;
}
Reply With Quote
  #2 (permalink)  
Old 03-17-2005, 05:56 PM
One Usenet Poster
Guest
 
Posts: n/a
Default Re: [FFTW] Cyclic results with FFTW?

Fred wrote:
> Dear all,
>
> I implemented some test FFT's from various libraries, having
> decomposed and reconstructed a simple signal (sine), my code worked
> for all of them however, the signal I got using fftw was not
> reconstructed correctly, indeed, the transform is not cyclic.
>
> How to get cyclic output from fftw?
>
> Below is a code in 1D I used. sorry to ask such a trivial question and
> thanks for your answer...
>
> Fred


Fred:

The FFTW output is not in [-f,0,+f] order. FFTW stores the data
starting at DC, then positive frequencies, and lastly the negative
frequencies beginning with the most negative frequency.

Good luck,
OUP
Reply With Quote
  #3 (permalink)  
Old 03-17-2005, 06:09 PM
[email protected]
Guest
 
Posts: n/a
Default Re: Cyclic results with FFTW?

(What do you mean by "not cyclic"?)

Rest assured that FFTW computes the DFT correctly, so any error is
almost certainly in your own code.

Most likely you are simply misunderstanding the output format of FFTW's
r2c transforms (which are DFTs specialized for real inputs). For N
inputs, the output is a complex array, but it is *not* of the same
length N. Rather, it is of length N/2+1. The reason is that the
outputs of a real-input DFT are redundant by a conjugate symmetry, so
only ~half of them are outputted.

This is all described in detail by the FFTW manual.

Cordially,
Steven G. Johnson

PS. Or it could be that you have bugs in your "split" routines, etc.
These sorts of transformations aren't needed for FFTW. e.g. it's not
clear to me why you would call split after the c2r transform, whose
output is already a real array. It's impossible to evaluate, of course,
because you don't post working code...not that you should expect others
to debug your code, anyway.

Reply With Quote
  #4 (permalink)  
Old 03-17-2005, 06:19 PM
[email protected]
Guest
 
Posts: n/a
Default Re: Cyclic results with FFTW?

(I'm not aware of *any* widely used FFT code that outputs in [-f, 0,
+f] order, so I doubt that is the poster's problem.)

Reply With Quote
  #5 (permalink)  
Old 03-17-2005, 08:19 PM
Fred Marshall
Guest
 
Posts: n/a
Default Re: [FFTW] Cyclic results with FFTW?


"Fred" <[email protected]> wrote in message
news:[email protected] om...
> Dear all,
>
> I implemented some test FFT's from various libraries, having
> decomposed and reconstructed a simple signal (sine), my code worked
> for all of them however, the signal I got using fftw was not
> reconstructed correctly, indeed, the transform is not cyclic.
>
> How to get cyclic output from fftw?


Fred,

First, do you mean cyclic in time or in frequency?

You won't get "cyclic" output from fftw or any other fft (i.e. forward
transform time > frequency) unless you do some particular things:

By definition, a normal fft addresses only a single "cycle" of the spectrum.
You can repeat it if you want to make it cyclic. That's equivalent to
increasing the sample rate - zero stuffing between the time samples -
without adding non-zero sample values (as would be the case in
interpolation - which is a bit different or more involved).

If the temporal record is cyclic then a "round trip" FFT / IFFT should
result in the same sequence as was input -neglecting any numerical roundoff
type noise that's added.

Fred


Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Zero padding in FFTW Peng Yu DSP 5 03-06-2005 04:21 AM
Correlation using FFTW.... Ramoj Paruchuri DSP 0 07-19-2004 10:37 PM
Re: custom FFTW lib Steven G. Johnson DSP 1 06-30-2004 04:17 PM
input to FFTW seia0106 DSP 7 05-14-2004 02:58 PM
FFTW from C#? John DSP 1 08-05-2003 04:31 AM


All times are GMT +1. The time now is 01:36 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved