Pipeline element FFT returns strange values

tamhan
Posts: 8
Joined: Tue May 19, 2020 7:22 pm

Pipeline element FFT returns strange values

Postby tamhan » Tue May 19, 2020 7:29 pm

Hello Folks,
and it is my turn to come here. After a disastrous run with a BlueNRG based solution, my customer and I are trying to rescue what is left of the project.

We decided to settle on the ESP-ADS; and use a LyraT 4.3 as our development board (nice hardware). Sadly, we have a problem. Our worker sits in the process method, and should do FFT on the incoming signal with the following code:
  1. static int _tams_process(audio_element_handle_t self, char *in_buffer, int in_len)
  2. {
  3.     ESP_LOGI("ICY", "FFT for %i len data buf", in_len);
  4.     short* realBuffer = ((void*)in_buffer);
  5.  
  6.  
  7.     for (int i=0 ; i< in_len ; i++)
  8.     {
  9.         y_cf[i] = realBuffer[i];
  10.     }
  11.  
  12.     dsps_fft2r_fc32(y_cf, N);
  13.     dsps_bit_rev_fc32(y_cf, N);
  14.     dsps_cplx2reC_fc32(y_cf, N);
  15.  
  16.  
  17.     // Bit reverse
  18.     dsps_bit_rev_fc32(y_cf, N);
  19.     // Convert one complex vector to two complex vectors
  20.     dsps_cplx2reC_fc32(y_cf, N);
  21.  
  22.     float tams_store[N/10 + 1];
  23.  
  24.  
  25.     for (int i = 0 ; i < N ; i++) {
  26.         tams_store[i/10] =0;
  27.     }
  28.  
  29.     for (int i = 0 ; i < N ; i++) {
  30.         tams_store[i/10] +=y1_cf[i];
  31.     }
  32.  
  33.     int lmin= tams_store[0];
  34.     int lmax= tams_store[0];
  35.  
  36.     for (int i = 0 ; i < N/10 ; i++) {
  37.         if(lmin > tams_store[i])lmin=tams_store[i];
  38.         if(lmax < tams_store[i])lmax=tams_store[i];
  39.     }
  40.  
  41.  
  42.     // Show power spectrum in 64x10 window from -100 to 0 dB from 0..N/4 samples
  43.     ESP_LOGW("ICY", "Signal min %i max %i", lmin, lmax);
Sadly, we get really strange output values. Here is the minimum and maximum for a few runs:
I (7111) ICY: FFT for 2048 len data buf
W (7111) ICY: Signal min -6864482 max 6757346
I (7121) ICY: FFT for 2048 len data buf
W (7131) ICY: Signal min -6864633 max 6756954
I (7131) ICY: FFT for 2048 len data buf
W (7131) ICY: Signal min -6858810 max 6753439
I (7141) ICY: FFT for 2048 len data buf
W (7151) ICY: Signal min -6860889 max 6753106
I (7161) ICY: FFT for 2048 len data buf
W (7161) ICY: Signal min -6863030 max 6751432
I (7171) ICY: FFT for 2048 len data buf
W (7171) ICY: Signal min -6858686 max 6753943
I (7181) ICY: FFT for 2048 len data buf
W (7181) ICY: Signal min -6856832 max 6755413
If we chase the data through dsps_view, the diagram looks really crazy too.

Could it be a problem with the way we use the input data? I took the initialization from the SD card recorder program, so the pipeline should get 44.1KhZ data at 16bit resolution and with two channels.

Ideas, anyone? And big thanks in advance
Tam + Elicia

tamhan
Posts: 8
Joined: Tue May 19, 2020 7:22 pm

Re: Pipeline element FFT returns strange values

Postby tamhan » Thu May 21, 2020 1:15 pm

Hello,
we managed to get forward a little bit. This now leads to somewhat workable data - aka if we do not talk to the unit, it does not show a spectrum:
  1. int16_t DspBuf[4096];
  2.  
  3. static int _tams_process(audio_element_handle_t self, char *in_buffer, int in_len)
  4. {
  5.     ESP_LOGI("ICY", "FFT for %i len data buf", in_len);
  6.     audio_element_input(self, (char *)DspBuf, in_len);
  7.  
  8.  
  9.     for (int i=0 ; i< in_len ; i++)
  10.     {
  11.         y_cf[i] = ((float)DspBuf[i]) /  (float)32768;;
  12.     }

ESP_Vikram
Posts: 25
Joined: Fri Nov 23, 2018 12:07 pm

Re: Pipeline element FFT returns strange values

Postby ESP_Vikram » Sun Jun 28, 2020 1:10 am

What is your in_len?
I think that fft function is optimized only for sizes > 3.

Can you please use len > 3 and check if it still gives error?

Who is online

Users browsing this forum: No registered users and 9 guests