DSPRelated.com
Forums

Help with FFT for DSP

Started by Diux March 23, 2005
I'm working with a motorola's DSP56824. But I need a library or
algorithm to calculate de FFT (256 points and 1 Dimension). The
problem is that I'm working with codewarrior(to programm with C), but
I tried to compile some algorithms but they doesn't compile. Someone
knows a link for a free FFT algorithm por DSP. Than You
>I'm working with a motorola's DSP56824. But I need a library or >algorithm to calculate de FFT (256 points and 1 Dimension). The >problem is that I'm working with codewarrior(to programm with C), but >I tried to compile some algorithms but they doesn't compile. Someone >knows a link for a free FFT algorithm por DSP. Than You >
This is a generic, unoptimized,ANSI C FFT program.Pls modify it for your needs: ------------------------------------------------------------------ /* fft256.c complex data stored re, im, re, im, re, ... im */ void fft256(float Z[512]) /* input data points and output [0] to [511] */ { static float W[512]; /* scratch vector */ static float E[258] = /* constants for FFT algorithm */ {1.0, 0.0, 0.999699, 0.0245412, 0.998796, 0.0490677, 0.99729, 0.0735646, 0.995185, 0.0980171, 0.99248, 0.122411, 0.989177, 0.14673, 0.985278, 0.170962, 0.980785, 0.19509, 0.975702, 0.219101, 0.970031, 0.24298, 0.963776, 0.266713, 0.95694, 0.290285, 0.949528, 0.313682, 0.941544, 0.33689, 0.932993, 0.359895, 0.92388, 0.382683, 0.91421, 0.405241, 0.903989, 0.427555, 0.893224, 0.449611, 0.881921, 0.471397, 0.870087, 0.492898, 0.857729, 0.514103, 0.844854, 0.534998, 0.83147, 0.55557, 0.817585, 0.575808, 0.803208, 0.595699, 0.788346, 0.615232, 0.77301, 0.634393, 0.757209, 0.653173, 0.740951, 0.671559, 0.724247, 0.689541, 0.707107, 0.707107, 0.689541, 0.724247, 0.671559, 0.740951, 0.653173, 0.757209, 0.634393, 0.77301, 0.615232, 0.788346, 0.595699, 0.803208, 0.575808, 0.817585, 0.55557, 0.83147, 0.534998, 0.844854, 0.514103, 0.857729, 0.492898, 0.870087, 0.471397, 0.881921, 0.449611, 0.893224, 0.427555, 0.903989, 0.405241, 0.91421, 0.382683, 0.92388, 0.359895, 0.932993, 0.33689, 0.941544, 0.313682, 0.949528, 0.290285, 0.95694, 0.266713, 0.963776, 0.24298, 0.970031, 0.219101, 0.975702, 0.19509, 0.980785, 0.170962, 0.985278, 0.14673, 0.989177, 0.122411, 0.99248, 0.0980171, 0.995185, 0.0735646, 0.99729, 0.0490677, 0.998796, 0.0245412, 0.999699, 0.0, 1.0, -0.0245412, 0.999699, -0.0490677, 0.998796, -0.0735646, 0.99729, -0.0980171, 0.995185, -0.122411, 0.99248, -0.14673, 0.989177, -0.170962, 0.985278, -0.19509, 0.980785, -0.219101, 0.975702, -0.24298, 0.970031, -0.266713, 0.963776, -0.290285, 0.95694, -0.313682, 0.949528, -0.33689, 0.941544, -0.359895, 0.932993, -0.382683, 0.92388, -0.405241, 0.91421, -0.427555, 0.903989, -0.449611, 0.893224, -0.471397, 0.881921, -0.492898, 0.870087, -0.514103, 0.857729, -0.534998, 0.844854, -0.55557, 0.83147, -0.575808, 0.817585, -0.595699, 0.803208, -0.615232, 0.788346, -0.634393, 0.77301, -0.653173, 0.757209, -0.671559, 0.740951, -0.689541, 0.724247, -0.707107, 0.707107, -0.724247, 0.689541, -0.740951, 0.671559, -0.757209, 0.653173, -0.77301, 0.634393, -0.788346, 0.615232, -0.803208, 0.595699, -0.817585, 0.575808, -0.83147, 0.55557, -0.844854, 0.534998, -0.857729, 0.514103, -0.870087, 0.492898, -0.881921, 0.471397, -0.893224, 0.449611, -0.903989, 0.427555, -0.91421, 0.405241, -0.92388, 0.382683, -0.932993, 0.359895, -0.941544, 0.33689, -0.949528, 0.313682, -0.95694, 0.290285, -0.963776, 0.266713, -0.970031, 0.24298, -0.975702, 0.219101, -0.980785, 0.19509, -0.985278, 0.170962, -0.989177, 0.14673, -0.99248, 0.122411, -0.995185, 0.0980171, -0.99729, 0.0735646, -0.998796, 0.0490677, -0.999699, 0.0245412, -1.0, 0.0}; float Tre, Tim; int i, j, k, l, m; m = 128; l = 1; while(1) { k = 0; j = l; i = 0; while(1) { while(1) { /* W[i+k] = Z[i] + Z[m+i]; complex */ W[2*(i+k)] = Z[2*i] + Z[2*(m+i)]; W[2*(i+k)+1] = Z[2*i+1] + Z[2*(m+i)+1]; /* W[i+j] = E[k] * (Z[i] - Z[m+i]); complex */ Tre = Z[2*i] - Z[2*(m+i)]; Tim = Z[2*i+1] - Z[2*(m+i)+1]; W[2*(i+j)] = E[2*k] * Tre - E[2*k+1] * Tim; W[2*(i+j)+1] = E[2*k] * Tim + E[2*k+1] * Tre; i++; if(i >= j) break; } k = j; j = k+l; if(j > m) break; } l = l+l; /* work back other way without copying */ k = 0; j = l; i = 0; while(1) { while(1) { /* Z[i+k] = W[i] + W[m+i]; complex */ Z[2*(i+k)] = W[2*i] + W[2*(m+i)]; Z[2*(i+k)+1] = W[2*i+1] + W[2*(m+i)+1]; /* Z[i+j] = E[k] * (W[i] - W[m+i]); complex */ Tre = W[2*i] - W[2*(m+i)]; Tim = W[2*i+1] - W[2*(m+i)+1]; Z[2*(i+j)] = E[2*k] * Tre - E[2*k+1] * Tim; Z[2*(i+j)+1] = E[2*k] * Tim + E[2*k+1] * Tre; i++; if(i >= j) break; } k = j; j = k+l; if(j > m) break; } l = l+l; if(l > m) break; // result is in Z } } /* end fft256 */ This message was sent using the Comp.DSP web interface on www.DSPRelated.com
Diux wrote:
> I'm working with a motorola's DSP56824. But I need a library or > algorithm to calculate de FFT (256 points and 1 Dimension). The > problem is that I'm working with codewarrior(to programm with C), but > I tried to compile some algorithms but they doesn't compile. Someone > knows a link for a free FFT algorithm por DSP. Than You
Have a look at http://sourceforge.net/projects/kissfft
Thanks for your fast answers. I dowloaded the algorithms sugessted in
this page. But I want an example that how call it algorithm. Can you
send me a short code in C about it. Thank you.
Diux wrote:
> Thanks for your fast answers. I dowloaded the algorithms sugessted in > this page. But I want an example that how call it algorithm. Can you > send me a short code in C about it. Thank you.
The README file in the .tar.gz/.zip archive has example code. There are other examples in the tools directory. If you are struggling with your development environment, I cannot help you. I am not familiar with the DSP chip you mentioned. If you are struggling with the concept of the DFT itself, you need to refer to a decent textbook. Hopefully, you can find a good one in your native language (Spanish?). Cheers, Mark
Thank you mark for you answer. My problem is that I can't de FFT,
because I am using a fixed point, and the DSP gives errors when I
compile the algorithm.

Thank you
Diux wrote:
> Thank you mark for you answer. My problem is that I can't de FFT, > because I am using a fixed point, and the DSP gives errors when I > compile the algorithm. > > Thank you
The problem is not with your processor, but with your code. DSPs don't give errors. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
in article FcednXqevck6oc3fRVn-vQ@rcn.net, Jerry Avins at jya@ieee.org wrote
on 04/03/2005 14:57:

> Diux wrote: >> Thank you mark for you answer. My problem is that I can't de FFT, >> because I am using a fixed point, and the DSP gives errors when I >> compile the algorithm. > > The problem is not with your processor, but with your code. DSPs don't > give errors.
well, they don't tell you about it when they do. (i've had errors because of fabrication or mask problems with both the 56K and the early SHArC. it can be very frustrating.) -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
robert bristow-johnson wrote:
> in article FcednXqevck6oc3fRVn-vQ@rcn.net, Jerry Avins at jya@ieee.org wrote > on 04/03/2005 14:57: > > >>Diux wrote: >> >>>Thank you mark for you answer. My problem is that I can't de FFT, >>>because I am using a fixed point, and the DSP gives errors when I >>>compile the algorithm. >> >>The problem is not with your processor, but with your code. DSPs don't >>give errors. > > > well, they don't tell you about it when they do. (i've had errors because > of fabrication or mask problems with both the 56K and the early SHArC. it > can be very frustrating.) >
Be precise, Robert. What you're claiming is that sometimes DSPs _make_ errors. I stand resolute. :-) Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
in article eJWdnfoJfaSMzMzfRVn-1g@rcn.net, Jerry Avins at jya@ieee.org wrote
on 04/04/2005 10:36:

>> well, they don't tell you about it when they do. (i've had errors because >> of fabrication or mask problems with both the 56K and the early SHArC. it >> can be very frustrating.) >> > > Be precise, Robert. What you're claiming is that sometimes DSPs _make_ > errors. I stand resolute. :-)
that's funny, i was just making a reference to such a phrase... anyway, i am talking about version 0.6 silicon of the ADSP-21062 SHArC (in 1996) that literally crashed when certain instructions were executed and other problems that i can't remember (some of these bugs did get fixed by 1.0 silicon). sorta like that floating-point error that was discovered on the Intel Pentiums sometime last decade, that embarrassed Intel so much that the did a total recall of that particular chip. i would call that a "chip making an error". -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."