espressif / esp-dsp

DSP library for ESP-IDF
Apache License 2.0
442 stars 87 forks source link

Two potential issues regarding dsps_fft4real example as well as documentation for cplx2real(). (DSP-91) #58

Open Galfy1 opened 1 year ago

Galfy1 commented 1 year ago

Hello. I have found two potential issues while working with esp-dsp. These issues are unrelated to each other.

  1. In the dsps_fft4real example. When the result of cplx2real() is converted from complex to real power values, a division of N is used (aka binsize*2) However I would argue that a division of (binsize)^2 should be used instead when converting to power. Pow = ampl^2 --> Pow = (sqrt(Real^2+Img^2)/binsize)^2 --> Pow = (Real^2+Img^2) / binsize^2 So the scaling in the dsps_fft4real example should be (N/2)^2 instead correct?

  2. In the documentation for dsps_cplx2real_sc16_ansi() it is stated that "Convert FFT result of complex FFT for real input to real array". However, as far as I understand, the result of cplx2real() is not real but complex. In the dsps_fft4real example the output of cplx2real() is also used as if it was complex. I understand that cplx2real has to be used when 1 real sequence is used as input, but is it not misleading to state that the output of cplx2real() is real?

dmitry1945 commented 11 months ago

Hi @Galfy1 ,

  1. We not use any divider because they could be different for direct and inverse FFTs. It’s up to user to apply any number.
  2. To save processing time we take two real input arrays with length N and make one complex array length N, where first array is real part, and second is imag part. Then we process this complex array with FFT and we will have one complex spectrum. Then we take this complex spectrum and by simple operation split this complex array of length N to two complex arrays with length N/2 (cplx2real function). Each of these arrays will be complex spectrum or input real signal. The result of cplx2real is two complex spectrum arrays with length of N/2.

Regards, Dmitry