Audio Signal Processing in Matlab
Audio Signal Processing in Matlab
Youssef Abdelilah
Senior Product Manager
2
Stream processing of audio is everywhere!
Tablet/MP3 Player & Smart Phone Gaming System
Automotive Infotainment
3
Tunable parameter equalizer example
MIDI Control
Tune parameters
in real-time
See it
Tune it
Audio Input Array Plot
Guitar10min.ogg Parameter
a 44.1Khz stereo Equalizer
audio Filters
Audio Output Visualize audio
Play it Custom Audio Algorithm waveforms in real-time
Create it
Speaker
Hear it
4
Challenges in audio system design
“I have to process large data and test my simulations with streaming signals. I need a simulation
testbench that can keep up with real-time data.”
“I need to optimize my high-level MATLAB algorithm for speed. I then need to verify that the optimized code
works the same way as the original MATLAB code.”
5
What DSP System Toolbox offers in MATLAB
Stream
“I have processing
to process techniques
large data and andwith
test my simulations hardware
streaming peripheral
signals. I need aaccess
simulationthat
speed
testbench that can upwith
keep up simulation and reduce memory footprint
real-time data.”
7
Stream processing in MATLAB
Streaming techniques* process continuous data from a captured signal or large file by
dividing it into “frames” and fully processes each frame before the next one arrives
Memory efficient
Streaming algorithms in DSP System Toolbox provide
Implicit data buffering, state management and indexing
Simulation speed-up by reducing overhead
MATLAB Memory
Stream Stream
Source Processing
*http://www.mathworks.com/discovery/stream-processing.html
8
How to create a streaming test bench
Spectrum
Analyzer
Algorithm
under test
Microphone Audio Output
Audio Input Visualize sound in real-time
Speaker
9
How to create test bench in MATLAB
Spectra=dsp.SpectrumAnalyzer ('SampleRate',Fs);
%% Stream processing loop
tic;
%% Terminate Terminate
release(Microphone)
release(Spectra)
10
How to automatically create test benches from
“Generate DSP Testbench” App
>>HelperGenDSPTestbenchUI
11
Part 2: Algorithms
12
Example 1: Audio Tone Removal
MIDI Control
Tune it
View it
Y Spectrum
Play it Analyzer
13
How to incorporate algorithm into test bench
%% Create & Initialize
Fs = 44.1e3;
SamplesPerFrame = 1024;
h = dsp.AudioFileReader('guitar10min.ogg');
hp = dsp.AudioPlayer;
% Interfering tone
ftone = 250;
initialize
hw = dsp.SineWave('Amplitude',0.8,'SampleRate',Fs,’Frequency',[ftone ftone],'SamplesPerFrame',SamplesPerFrame);
hs = dsp.SpectrumAnalyzer('SampleRate',Fs,'SpectralAverages',5,'ShowLegend',true,’Title',titlestr);
while ~isDone(h)
% Read one frame from audio file and add a tone to input audio
x = step(h) + step(hw);
MIDI Control
Tune it See it
X H
H=Y/X
Array Plot
Y Transfer Function
Play it
Estimator
Guitar file Parameter Y
Hear it
@ 44.1Khz Equalizer
stereo audio
X Filters Y
Audio Input
Speaker
Custom Audio Algorithm Audio Output
Visualize audio waveform
in real-time
Create it
15
DSP System Toolbox audio related components
(supported on Apple/Windows/Linux)
– Multichannel audio I/O (Number of channels depends on hardware)
Audio Player/Recorder
(Supports multiple devices, one sound driver per MATLAB session)
Audio File Reader/Writer
ASIO low latency driver support on Windows(R)
Custom channel mapping
– Audio signal analysis
Scopes: time, spectrum analyzer, Array plot
Transfer function estimator
Measurements: SNR, THD, Average power, PeaktoRMS ratio, mean, variance, ...
– Signal processing algorithms
FIR, Biquad, Multirate FIR, FFT, LMS, ...
– Connectivity
UDP, MIDI (simultaneous support for multiple controls on multiple devices)
16
Part 3: Acceleration of simulation
17
Stream processing in real-time
Data acquisition & algorithm times
As long as
We have
Real-time signal processing
18
Stream processing in real-time
Data acquisition & algorithm times
As long as
We have
Real-time signal processing
19
Accelerating algorithm execution*
function y = audio_algorithm_peqso(u,tunedparams)
% Copyright 2014 The MathWorks, Inc.
persistent PE1 PE2
if isempty(PE1)
PE1 = parametricEQFilter('Bandwidth',2000,…
'CenterFrequency',3000,'PeakGaindB',6.02);
PE2 = ParametricEQFilter('Bandwidth',2000,…
'CenterFrequency',1000,'PeakGaindB',-6.02);
end
[PE1,PE2] = processtunedparams(tunedparams,PE1,PE2);
v = step(PE1,u);
y = step(PE2,v);
%-------------------------------------
function [PE1,PE2] = processtunedparams(tunedparams,PE1,PE2)
if ~isnan(tunedparams.CenterFrequency)
PE1.CenterFrequency = tunedparams.CenterFrequency;
end
if ~isnan(tunedparams.Bandwidth)
PE1.Bandwidth = tunedparams.Bandwidth;
end
if ~isnan(tunedparams.Gain)
PE1.PeakGaindB = tunedparams.Gain;
end
if ~isnan(tunedparams.CenterFrequency2)
PE2.CenterFrequency = tunedparams.CenterFrequency2;
end
if ~isnan(tunedparams.Bandwidth2)
PE2.Bandwidth = tunedparams.Bandwidth2;
end
if ~isnan(tunedparams.Gain2)
PE2.PeakGaindB = tunedparams.Gain2;
end
(*) Design and Prototype Real-Time DSP Systems with MATLAB (Conference Presentation):
http://www.mathworks.com/company/events/conferences/matlab-virtual-conference/2013/proceedings/design-and-prototype-real-time-dsp-systems-with-matlab.html
21
Simulation acceleration benchmarks
22
DSP System Toolbox *
Over 300 algorithms for modeling, designing, implementing and deploying dynamic
system applications
●Advanced Filter Design, Adaptive, Multistage and Multi-rate Filters ●Visualization in Time and Frequency-domain
●FFT, DCT & other Transforms ●System objects and functions in MATLAB
●Signal processing blocks for Simulink ●Stream signal Processing
●Support for Fixed-Point, C/C++ code generation and HDL ● ARM Cortex-M support for hardware prototype
Algorithm libraries in MATLAB Algorithm libraries in Simulink
*http://www.mathworks.com/
products/dsp-system/index.html
23
Summary
24
THANK YOU!
© 2014The MathWorks, Inc. MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
ww.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be trademarks
25
or registered trademarks of their respective holders.