0% found this document useful (0 votes)
14 views

Arduino

The document describes how to apply a low-pass filter to audio samples captured in real time on an Arduino device. It involves installing an FIR filter library, designing a filter to a specific frequency specification, integrating the filtering code with the audio capture code, and verifying it works by generating tones on a phone.

Uploaded by

Santi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Arduino

The document describes how to apply a low-pass filter to audio samples captured in real time on an Arduino device. It involves installing an FIR filter library, designing a filter to a specific frequency specification, integrating the filtering code with the audio capture code, and verifying it works by generating tones on a phone.

Uploaded by

Santi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

TECHNOLOGIES ON SMART SYSTEMS

LAB 3 :
Audio filtering on Arduino

Santiago Gandía Mira


● CONCEPTOS TRATADOS: Audio processing

● DEVICES: Computer with Arduino installed, the Arduino Nano BLE 33


and a micro USB cable. Also, a mobile phone is needed.

● PREVIOUS KNOWLEDGE: C programming language (arduino).

● ESTIMATED DURATION: 2 hours

● DESCRIPTION: Create a program that applies a low-pass filter to the


audio samples captured in real time on the Arduino device.

● EVALUATION: Upload the resulting Arduino program file (.ino) and a


screenshot with the final verification that the tones are filtered correctly.
You can answer the question in this same document and upload it; or in
the comments section when delivering.


This practice session pretends to carry out a short audio acquisition on the Arduino
device and be able to apply some type of processing. In this case, it is suggested to
apply a low-pass filter to the samples captured in real time.

STEP 1. CAPTURE REAL TIME SAMPLES

o capture the samples in real time, it is recommended to start with a sketch called
PDMSerialPlotter located at the following path: File
→ Examples → PDM → PDMSerialPlotter

This code is very simple to analyze and all it does is capture the already encoded
samples from the microphone and print them through the serial port. The Arduino
application allows us to see these values ​numerically (Tools → Serial Monitor) or
graphically (Tools → Serial Plotter).

If we upload this example, open the graphic monitor and speak into the
microphone, we can visualize the sound waves (figure 1).

Figure 1. Sound signal plotted on the Serial Plotter tool

PASO 2. FILTER DEFINITION


The library that we are going to have to install in the Arduino application to apply a
filter is called FIR Filter by the author called Leeman. In the library link, there is an
example called multiple_filters that demonstrates how these filters should be
applied. The lines of code that are of interest in this application are the following:

Defining the objects that contain the filters:


#include <FIR.h>
FIR<float, 13> fir_lp;
In this case it is a low-pass filter defined with 13 coefficients. These 13 coefficients
that make up the filter must be specified and set in the following way:

float coef_lp[13] =
{660,470,-1980,-3830,504,10027,15214,10027,504,-3830,-1980,470
,660};
fir_lp.setFilterCoeffs(coef_lp);

Once the filter has been created, to apply it to a sample, it is done with the method
processReading.

fir_lp.processReading(data[i])

These previous coefficients correspond to a filter that allows signals with a


frequency lower than 2kHz to pass. In our case, we intend to apply a filter with other
specifications. In this library it is recommended to use the following link to design an
FIR filter with specific specifications:

http://t-filter.engineerjs.com

To create a new filter, we are going to use the following data:

● Microphone sample frequency: 16Khz


● Frequency range pass band: 0 to 2Khz
● Frequency range stop band: 4Khz to 8kHz

Pregunta: Why do we have to limit the frequency band we want to eliminate and
not say that we want to filter out all frequencies from 4kHz onwards?
Specifying a stop band allows for more precise control over the filtering process,
ensuring that only the intended frequencies are attenuated while preserving the desired
signal characteristics and avoiding potential side effects.

Once the characteristics of the FIR filter have been entered and the design has
been applied, we can copy the coefficient values. It is important that the format of
these coefficients be a 16-bit integer.

STEP 3. INTEGRATE BOTH PROGRAMS


Once we have seen the first program that captures the audio samples in real time
and the second program that shows how to apply a filter to an input signal, the
objective is now to unify both sketches and make a single program that captures
the samples in real time and apply the low pass filter designed above.

The program must print the two values ​on the same line: the sampled value and the
filtered value (see the example code called multiple_filters). In this way, we can
have the result of the two superimposed signals as shown below:

Figura 2. Result of plotting the two signals: filtered and unfiltered.

PASO 4. COMPROBACIÓN

In Figure 2 it cannot be verified that the filtering algorithm is being applied correctly,
because our voice is not high enough and the established filtering ranges (> 4Khz)
are not applied. In order to verify that our algorithm is correct, we can use a tone
generation application that exists for free in mobile phone markets. Tone Generator
or Frequency Sound Generator are two Android applications that can be useful
(figure 3).

If we execute frequency tones < 2Khz and frequency tones > 4Khz and bring them
closer to the Arduino Nano device, we can see how in the second signal, the tones
are filtered.
Figure 3. Application Tone Generator

You might also like