Giter Club home page Giter Club logo

audio-filtering-on-stm32-using-cmsis-dsp's Introduction

Audio-Filtering-on-STM32-Using-CMSIS-DSP

Introduction

STM32F446RE Nucleo Board is the main microcontroller unit used to realise the implementation of the FIR filter in this project. The micro SD card act as external storage to keep the audio data file in txt format which consists of 32 bits floating-point numbers. The audio file is originally in .wav format and it is converted to text format to allow the Nucleo board to read the data. The micro SD card adaptor is utilized to allow the STM32 Nucleo board to access the micro SD card via a Serial Peripheral Interface (SPI) connection. The SPI is communicated in full-duplex mode using a master-slave architecture with a single master or microcontroller unit. The data transmitted into the board is managed by the middleware called File Allocation Table File System (FATfs) which is widely used in memory card and USB storage drive. The status of the process is updated on user monitoring via the Universal Asynchronous Receiver Transmitter (UART) interface. The output audio data file is written back to the SD card once the FIR processing on the board is done.

Filter Specification

Declaration Value
Cut-off Frequency 2000 Hz
Fs 48000Hz
Fpass 0 Hz - 2000 Hz
Fstop 5000 Hz - 24000 Hz
TEST_LENGTH_SAMPLES 19084 (number of input data)
BLOCK_SIZE 1
NUM_TAPS 17

Hardware

Software

Pinout and Configuration

In this project, we store the input and output of the FIR filter in an SD card. Therefore, we need to set the interface between the SD card module and STM32.

SD card Pin Board Pinout
VCC 5V
GND GND
SCK PA5
MISO PA6
MOSI PA7
CS PB6

image

  1. First, create a new project using STM32 cube IDE. In the pinout & configuration, we will connect our SD card using the SPI1 pin. After enabling the SPI1 connection, our SCK pin will be auto-assigned to PA5, MISO pin to PA6 and MOSI pin to PA7. In the SPI1 setting, we need to set it to Full Duplex Master so that both master and slave can send data at the same time via the MOSI and MISO lines respectively. Then, change the clock prescaler to 128 to reduce the baud rate of the SD card. image

  2. Connect the CS pin to PB6 using a GPIO connection and label it as SD_CS. image

  3. Next, communicate the SD card module with the FAT file system provided by Middleware. We changed the maximum sector size from 512 to 4096 so that it can support any type of memory card. image

  4. In this project, we used the serial monitor to debug our connection and check our data transfer status. We connect the board to the serial monitor using default UART, USART2. The UART mode is set to asynchronous because UART interface does not use a clock signal to synchronize the transmitter and receiver devices and the baud rate was changed to 9600 Bits/s. image

  5. In the system mode setting, the debug state changed to serial wire mode. For the RCC setting, we used a crystal/ceramic resonator to generate our clock. While for the clock configuration, we set it to maximum frequency,180 MHz. image

Design and Generate Filter Coefficients

Design the filter using this website. In this project, we set the spec to:

from to gain ripple/att.
0 Hz 2000 Hz 1 5db
5000 Hz 24000 Hz 0 -30db

image

Code Configuration

First, we need to import the FatFS SD card function (fatfs_sd.c and fatfs_sd.h) to our project and include it in the header of user_diskio.c and main.c. In the user_diskio.c Private Functions, we return all the data to the controller through SPI1 using the function we just added.

image

In the main.c file, we can check our SD card connection status using the f_mount function and print the status to the serial monitor using the send_uart function. After that, we enter our main loop and start to read-write data to our SD card and monitor through the serial monitor. image

After include the CMSIS DSP library, we will use these two function to implement FIR in our project which are arm_fir_f32 and arm_fir_init_f32. The arm_fir_init_f32 is an associated initialization function for each data type. The initialization function has two main function. It is used to set the values of the internal structure fields and initialize the values in the state buffer. If the initialization function is used, then the instance structure cannot be placed into a constant data section. There is a total of five parameters are needed for this function. First, S is points to an instance of the floating-point FIR filter structure. numTaps is number of filter coefficients in the filter. firCoeffs32 points to the filter coefficients buffer which are the values of the impulse response generated from the online website. firStateF32 points to the state buffer, blockSize is the number of samples processed per call.

This figure below shows the use of FIR function in our project main.c file. All the variable and parameter are first declared. Then, the fir function is called in the main function and pass all the parameter and variables accordingly for the FIR filter algorithm computation.

image

Demo

image image video

Reference

  1. https://os.mbed.com/platforms/ST-Nucleo-F446RE/
  2. https://controllerstech.com/sd-card-using-spi-in-stm32/
  3. https://www.keil.com/pack/doc/CMSIS/DSP/html/index.html
  4. https://www.youtube.com/watch?v=nAot1FCgYGo

audio-filtering-on-stm32-using-cmsis-dsp's People

Contributors

mkel1123project avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.