Page 1 of 1

[SOLVED] gpu_fft troubleshooting

Posted: Mon Apr 01, 2019 3:20 am
by 5chmidti
I've been testing out the gpu_fft api on my pi and came upon some strangeness.

By changing the test data from being a cosine to a sine wave my program does not behave like I would anticipate it (same freq), while the cosine data works just fine.
(Code at the bottom)

I've attached a screenshot of output diagrams. The top one is just the test cosine wave (sine would be redundant to show) and the middle one is the corresponding output of fft for that (cos), so far so good, but at the bottom you'll find the output for the sine wave (same freq, just changed from cos to sin) and here it gets weird.

Why should my program work for the cosine but not for the sinus function?

EDIT: Just tested a square wave and it looked fine


Here my code (+ makefile): repo
screenshot.png
screenshot.png (87.22 KiB) Viewed 142 times

Re: gpu_fft troubleshooting

Posted: Mon Apr 01, 2019 7:14 am
by PeterO
You code only prints the real part of the fft result. When you transform a cosine the output is all real , but when you transform a sine the result is all imaginary (in the .im part of the data array). If you look at the scale on your lower graph you will see the values are all very small, and are actually the accumulated errors from lots of calculations. They are numerical "noise" due to finite precision in the gpu.

If you just want the magnitude of spectrum and are not interested in the phase, then print

Code: Select all

hypot(out[i].re,out[i].im) 
PeterO