implement parametric audio equalizer using raspberry pi -凯发k8网页登录
this example shows how to use alsa audio playback block from the raspberry pi™ block library to implement a parametric audio equalizer algorithm with a simulink® model and to run the model on raspberry pi hardware.
introduction
parametric equalizers are used to adjust the frequency response of audio systems. for example, a parametric equalizer can be used to compensate for biases with specific speakers that have peaks and dips at different frequencies.
in this example, you will implement a parametric audio equalizer with a simulink model and then run that model on raspberry pi hardware. the parametric equalizer algorithm in this example provides three second-order (bi-quadratic) filters whose coefficients can be adjusted to achieve a desired frequency response. a graphical user interface (gui) is used in simulation to dynamically adjust filter coefficients and explore behavior.
the following sections describe how the parametric equalizer algorithm is specified, how the performance can be assessed through simulation, and how the model is run on raspberry pi hardware. you will also learn how the alsa audio playback block is used to output audio signals.
prerequisites
we recommend completing example.
required products
dsp system toolbox™
required hardware
to run this example you will need the following hardware:
raspberry pi hardware
headphones, speakers or a tv/monitor with hdmi input
task 1 - configure and run parametric equalizer simulink model
in this task, you will configure and run the parametric equalizer model on raspberry pi hardware.
1. connect a pair of speakers or headphones to the analog audio output connector on the raspberry pi hardware.
2. open the model.
3. go to apps > run on hardware board > options.... review the parameters on the page that opens. if you performed a firmware update, board information will be automatically populated with the host name, user name and password of your raspberry pi hardware. if you have not performed a firmware update or you need to change the board parameters, enter the ip address, user name and password of your raspberry pi hardware.
4. in the simulink model, double-click on the signal from workspace block. the block outputs the samples of the signal called audiosignal at a rate of 44100 samples per second. the audiosignal is read from a wave file called guitartune.wav in the model initfcn callback. to view model callbacks click on file > model properties > model properties and navigate to desired callback function in the model properties gui.
5. in the simulink model, double-click on the alsa audio playback block. note that this block sends the processed audio signal to the 'default' audio device on the raspberry pi hardware. you can also enter the name of an audio device such as 'plughw:0,0' to send audio to a device other than the 'default' audio device. to get a list of audio playback devices on your raspberry pi hardware, execute the following command on the matlab command line:
r = raspberrypi; a = listaudiodevices(r,'playback')
the output returned by the listaudiodevices function is a structure array containing the name and the device numbers of the available audio playback devices. a typical output is:
a(1) name: ' bcm2835 - bcm2835 alsa...' device: '0,0'
a(2) name: ' bcm2835 - bcm2835 alsa...' device: '0,1'
a(3) name: ' usb-audio - usb pnp sound device...' device: '1,0'
the output above indicates that there are three audio playback devices with alsa audio device numbers 0,0, 0,1 and 1,0. the first two devices correspond to the analog audio output and the hdmi output of the raspberry pi board. the third device is a usb audio dongle. to use the playback device 0,0, enter 'plughw:0,0' for the device name parameter on the alsa audio playback block.
6. on the hardware tab of the simulink model, in the mode section, select run on board and then click monitor & tune.
task 2 - change frequency response of parametric equalizer
1. as the simulink model is running on raspberry pi hardware, you will hear audio from the speakers/headphones connected to the raspberry pi hardware.
2. a gui displaying the frequency response of the audio equalizer will appear as shown in the picture below:
3. click and drag the markers or lines in the three band equalizer gui to specify the desired filter response characteristics. note the change in audio output as the frequency response of the equalizer changes.
4. press the stop button on the model to stop model execution.
other things to try
change the volume of the sound sent to speakers/headphones by tuning the gain parameter in the 'sum left & right channels and to single* subsystem in the simulink model.