Closed Galfy1 closed 11 months ago
Hi @Galfy1 I will answer one-by-one.
Second case: we have single real input signal with length N, and we need to make FFT for this input. We can make a complex signal length N and copy input signal as real part, and 0 as imag part, then make FFT, bit reverce and that's it. But, in this case result complex spectrum 0..N/2 will be almost the same as N/2...N. It means we did some useless calculations. To avoid this situation, we can make a FFT N/2 and add additional operation dsps_cplx2real that will finalize spectrum for input real signal. We copy input signal N llength to real and to imag part of complex signal length N/2, iWe will use complex FFT N/w, but we will do next: FFT N/w ->bit reverce N/w ->dsps_cplx2real. At output of this operation we will have complex spectrum of real input signal length N.
The property of real input that complex spectrum at ouput from N/2...N almost repeat samples from 0..N/2, that's why we need only complex samples from 0 to N/2.
For FFT for real input you make: In case of radix 2:
dsps_fft2r_fc32(x1, N>>1);
// Bit reverse
dsps_bit_rev2r_fc32(x1, N>>1);
// Convert one complex vector with length N/2 to one real spectrum vector with length N/2
dsps_cplx2real_fc32(x1, N>>1);
Here, finally in the x1 you will have complex spectrum of your input real signal.
In case of radix-4
// FFT Radix-4
unsigned int start_r4 = dsp_get_cpu_cycle_count();
dsps_fft4r_fc32(x2, N>>1);
// Bit reverse
dsps_bit_rev4r_fc32(x2, N>>1);
// Convert one complex vector with length N/2 to one real spectrum vector with length N/2
dsps_cplx2real_fc32(x2, N>>1);
Here the same, in x2 you will have complex spectrum length N/2 for input real signal length N.
3 and 4. The output of FFT is a full spectrum with complex values. To get amplitude you should make sqrt(rere + imim). If you use dsps_cplx2reC or dsps_cplx2real_fc32 you will have only single side.
regards, Dmitry
I forget to thank you for your in depth answer! Thanks!
First of all thanks for providing this API. I want to use the FFT api on an esp32-s3 but there are some things that I struggle to understand.
I will be referencing to pages from this article: https://www.sjsu.edu/people/burford.furman/docs/me120/FFT_tutorial_NI.pdf
Here is a list of my questions
Why are dsps_cplx2reC and cplx2real used? What do they do? and what is the difference between them? There is conflicting documentation about this. For example, a comment in the FFT examples states that dsps_cplx2 returns two complex vectors, but the ESP-DSP Library documentation states that it returns two real arrays. Why can’t I just take the magnitude of the complex result directly after doing the FFT and bit reversal?
How to use the FFT with real input values? I get that i can set all the imaginary parts to 0, but this is not what is done in the fft4real example. Here all the values are simply concatenated directly after each other without “padding 0’s” in the imaginary parts (see code snippet bellow). In the fft4real example dsps_cplx2real is also used instead of dsps_cplx2reC (referring back to question 1).