On 5th semester I took Digital Signal Processing course and I volunteered to build a microcontroller-based filter.
At first I wanted to use this circuit as a low-pass filter for subwoofer, but that function did not play along with the system requirements given by the professor.
Basic system specification:
- Sampling frequency 8kHz
- 5 filter implemented: Butterworth LP/HP/BP and Chebyshev I LP/HP (designed using MATLAB)
- Ability to change filter type by pressing a button
- Input and output signals amplitude: 0-5V
- KiCad - electronics design
- MATLAB - filters design and simulation
- OpenOffice Calc - simple data processing, generating comparison plots
- Logic 1.2.5 - logic analyzer data logging and visualisation
- WinAVR and Notepad++
- Necessary electronic components
- Function generator (Rigol DG1032Z)
- Oscilloscope (Rigol DS1052E)
- USBasp programmer
- Saleae logic analyzer (8 channels, 24Mhz)
I used ATmega328p on Arduino Pro Mini board with 16MHz clock, internal ADC (10-bit resulution) and external 16-bit DAC8571. I2C interface runs at 400kHz. The circuit is assembled on a breadboard to ease making modifications.
Code is written in C++ without Arduino libraries (as I needed full control over program's execution). Program is mainly interrupt-driven: Timer1 is set to 'tick' with 8kHz frequency. Its interrupt triggers the ADC conversion and initializes previous output value sending to the DAC. To make debugging easier I hooked logic analyzer to the circuit and modified the software to turn certain pins (labeled DEBUG_PIN_x on schematic) on and off in a few critical moments. That enabled me to log the program execution: Implemented filters have discrete transfer function in form . Output value is calculated using formula where corresponds to .
The calculations are done using int32_t numbers
- 11.2015 - Initial project idea, TWI control routines.
- 12.2015 - Butterworth LP filter with 44kHz sampling frequency. Testing as audio filter. Problems with stability.
- 01.2016 - Lowering sampling frequency, making system more stable, debugging, filters design and simulation scripts writing, creating documentation.
To assess system performance I created Bode plots (amplitude only), recorded step responses and compared collected data with simulation results (from MATLAB). In section below you can see the comparison plots. The only plots that are slightly off are those with Butterworth BP filter and they result from integer rounding: filter's transfer function generated by MATLAB is , which was rounded to .