Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- STMicroelectronics Community
- STM32 MCUs Software development tools
- STM32CubeIDE (MCUs)
- STM32F407 - CMSIS DSP - IFFT not working with audi...

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

STM32F407 - CMSIS DSP - IFFT not working with audio input/output

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

2024-04-28 02:18 PM

I'm currently using the stm32f407g-disc1 and reading an audio input through PMOD I2S2. I've carried out some examples and the hardware is working fine (writing data from the rx to the tx buffer) such as the code below.

```

for (int i=0; i<BUFFER_LENGTH*4; i=i+4) {

txBuf[i] = rxBuf[i];

txBuf[i+1] = rxBuf[i+1];

txBuf[i+2] = 0;

txBuf[i+3] = 0;

}

```

I now wish to perform the FFT on this incoming buffer, manipulate it (my first aim is to implement a pitch shifting algorithm) and perform the IFFT again. Thus I've tried the following:

```

for (int i=0; i<BUFFER_LENGTH*4; i=i+4) {

fft_in_buf[fft_in_ptr] = (float) ((int) (rxBuf[i]<<16)|rxBuf[i+1]);

fft_in_ptr++;

}

arm_rfft_fast_f32(&fft_handler, fft_in_buf, fft_out_buf, 0);

arm_rfft_fast_f32(&fft_handler, fft_out_buf, fft_in_buf, 1);

fft_in_ptr = 0;

for (int i=0; i<BUFFER_LENGTH*4; i=i+4) {

txBuf[i] = (fft_in_buf[fft_in_ptr] >> 16) & 0xFF; // MSB

txBuf[i + 1] = fft_in_buf[fft_in_ptr] & 0xFF; // LSB

txBuf[i + 2] = 0;

txBuf[i + 3] = 0;

fft_in_ptr++;

}

```

In the main initialization I'm also carrying out `arm_rfft_fast_init_f32(&fft_handler, BUFFER_LENGTH);`

My issue is that I get a very very low output (barely audible) with the above code. I might have a scaling issue as I found in similar issues but I still can't get it to work by scaling fft_in_buf[fft_in_ptr].

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

2024-04-29 11:21 PM

Hi, thank you for pointing me in the right direction. My issue was in fact with converting back the tx buffer.

```
for (int i=0; i<BUFFER_LENGTH*4; i=i+4) {
txBuf[i] = (fft_in_buf[fft_in_ptr] >> 16) & 0xFFFF; // MSB
txBuf[i + 1] = fft_in_buf[fft_in_ptr] & 0xFFFF; // LSB
txBuf[i + 2] = 0;
txBuf[i + 3] = 0;
fft_in_ptr++;
}
```

3 REPLIES 3

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

2024-04-28 10:37 PM - edited 2024-04-28 10:53 PM

You use a float fft , so scaling is not the problem, i suppose. (float giving about 1500 dB dynamic range)

What comes out, if you just comment out the two // arm_rfft_fast_f32() lines ?

If you feel a post has answered your question, please click "Accept as Solution".

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

2024-04-29 11:21 PM

Hi, thank you for pointing me in the right direction. My issue was in fact with converting back the tx buffer.

```
for (int i=0; i<BUFFER_LENGTH*4; i=i+4) {
txBuf[i] = (fft_in_buf[fft_in_ptr] >> 16) & 0xFFFF; // MSB
txBuf[i + 1] = fft_in_buf[fft_in_ptr] & 0xFFFF; // LSB
txBuf[i + 2] = 0;
txBuf[i + 3] = 0;
fft_in_ptr++;
}
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

2024-04-30 03:52 AM

Thanks for coming back with the solution.

JW

Related Content

- Troubleshooting STM32F407 USB Device Mode: IAR vs. Cube IDE Code Generation Differences in STM32CubeIDE (MCUs)
- USART3 Receive interrupts issue. in STM32CubeIDE (MCUs)
- Debug not working with relocated code with Cortex-Debug (Visual Studio Code) in STM32 VSCode extension (MCUs)
- STM32F407 Disc SPI3 initially it's working fine then MISO pin stop working? in STM32CubeIDE (MCUs)