Skip to content

Active Noise Control on Raspberry Pi

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
matplotlibcpp-license.txt
Notifications You must be signed in to change notification settings

psykulsk/RpiANC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RpiANC

Implementation of Active Noise Control Algorithms for Raspberry Pi.

This is the accompanying code to the publication 'Adaptive Active Noise Cancelling System for Headphones on Raspberry Pi Platform' that has been presented at the Signal Processing Workshop 2020 conference https://mrweek.org/spw/

Link to the article: https://ieeexplore.ieee.org/document/9259141

Used hardware

Assembled system

System schematic

Build and run commands

Example:

mkdir build && cd build
cmake ../ && make all

Main binary that does feedforward active noise control:

./ffANC

Simple tests that show how LMS and FxLMS attenuate simulated noise on matplotlib plots:

./lmstest
./fxlmstest

Build dependencies

Builds tested on Ubuntu 18.04 and Raspbian distributions:

Cmake >= 3.7
Alsa library, so packages like: libasound2, libasound2-dev.
Python2.7 libraries (matplotlibcpp dependency) so packages like: python-dev
OpenMP directives (propably supported by your compiler)

Repository and code structure

Cmake and make commands build a few binaries. The main one, is the ffANC binary that executes tha main function from the feedforward_anc.cpp file. Inside this file you can define or remove the DEPLOYED_ON_RPI macro to change devices used for capture and playback. Define CAP_MEASUREMENTS macro to capture sample values and save them to files.

The main function of the ffANC target executes a specified number of loop iterations. During each iteration 3 main operations: capture of new samples, sample processing and playback of the calculated samples, are executed concurrently, in a fork-join model. Firstly, each of the 3 operations is executed in a separate thread. Then, output samples from each operation are exchanged. Most recently calculated output samples are moved to the input array of the playback function and newly captured samples are moved to the input array of the signal processing function.

In constants.h file, you can find the names of devices used on Raspberry Pi and other constants used in signal processing.

All signal processing is in the header files under the Headers and the processing.cpp source file.

Scripts directory contains python and bash scripts that automate measurements, gathering data, deploying code etc.

Results

Comparison of attenuation of a noise signal of a constant frequency between the created ANC system and Sennheiser HR 4.50 BTNC headphones.

Attenuation comparison

Disclaimer: this implementation worked on a specific hardware setup and attenuated a specific (constant frequency) type of noise. It is not guaranteed that it will work out of the box on a different setup. I've published the code on github so that when someone else is going to try to implement something similar this codebase can be used as a starting point or an inspiration.

Useful links, articles, etc.

Included third-party libraries

This software uses matplotlibcpp - see matplotlibcpp-license.txt