A 100 lines example of signal processing written in C++
In this example, a noisy square wave signal is generated. This signal is passed into a low-pass filter to reduce noise. An automatic gain control (AGC) is used to prevent fluctuation of the amplitude and get a constant output signal. Then, a limiter limits output value of each sample to a fixed value to avoid impossible value during conversion to 16-bit (hard clipping)
Build the example :
g++ -Wall -pipe -Ofast main.cpp -o signalprocessing
Run the example :
./signalprocessing > out
Use audacity (or other audio software) and import output data as Raw Data using the following parameters :
- Signed 16-bit PCM
- Little-endian
- 1 Channel (Mono)
- Sample rate : 44100
Cutoff frequency can be adjusted by changing the value of the variable lowPassSamples : a lower value will rise cutoff frequency.