Audio Signal Processing
Audio Signal Processing
Why: To demonstrate that you can use MATLAB and your laptop to
develop and test real time audio signal processing algorithms
Who:
– I manage a development group at MathWorks focused on DSP and Communications
Includes fixed-point modeling and deployment to C or HDL
– Audio is a focus area for DSP System Toolbox
What:
– I am on the road to channel customer input directly into development
– I am seeking a few customers to work closely with and by helping them succeed, to
make our tools better for everyone.
– Could you be one of those customers?
2
Goals for today
Initiate contact with key people or groups to help drive this area forward.
3
Where would you like us to invest next?
How can we best help you?
5
I said “real time”. What did I really mean?
A laptop does not provide a true real time environment. On the other hand,
if it can process the data fast enough and reliably enough, it might work just
fine.
– E.g. We use our PCs for voice and video (Skype) communications frequently. That’s
real time communications.
For audio signal processing, real time is only important when either or both
input and output are live audio.
– Audio input comes from microphone, audio output goes to speakers or headphones.
What about latency?
– Not important if either input or output are not live. E.g. consider playing recorded music.
As long as the latency is not ridiculous, users will not notice it.
– If both input and output are live, then latency must be small (< 30 ms).
– We have a shipping example in 14a demonstrating how to measure latency.
6
New scopes in DSP System Toolbox
Visualizations
– Time Scope
– Spectrum Analyzer
– Logic Analyzer
7
How to create a streaming test bench
Spectrum Analyzer
View it
Speak it
Spectrum
Analyzer
Microphone
Hear it
Audio Input Visualize sound in real-time
Speaker
Audio Output
9
How to create test bench in MATLAB
Spectra=dsp.SpectrumAnalyzer ('SampleRate',Fs);
%% Stream processing loop
tic;
%% Terminate Terminate
release(Microphone)
release(Spectra)
10
Use test bench App from in product example to create a test
bench
11
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: Average power, PeaktoRMS ratio, mean, variance, ...
– Signal processing algorithms
FIR, Biquad, Multirate FIR, FFT, LMS, ...
Variable fractional delay (useful for audio beamforming)
– Connectivity
UDP, MIDI (simultaneous support for multiple controls on multiple devices)
12
Audio I/O with MATLAB: The gear
13
Audio Hardware is Automatically Detected
Audio device I/O components (in both MATLAB and Simulink) detect audio
devices registered with OS and dynamically populate pick lists
14
Choice of Modern File Formats Allows Interplay with other
Common Audio Players
15
Audio demos
16
Optional additional topics
Filter design
– Sample Rate Conversion
17
Filter Design and Sample Rate Conversion
filterbuilder
– Generates MATLAB code for given design
– Optionally generates HDL code
Sample rate conversion
– Baseline: FIR Decimation, FIR Interpolation and FIR Rate Converter
– New design assist: dspdemo.SampleRateConverter (see associated demo in 14a)
Preview of 14b sample rate converter
– Allows “tolerance” to find smaller factors if approximate rate conversion acceptable
– Can reduce number of operations and/or number of stages
Is there interest in Asynchronous sample rate conversion?
– What would you expect for interface?
Demo
18
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
21
THANK YOU!
© 2014 The MathWorks, Inc. MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be
23
trademarks or registered trademarks of their respective holders.
Where would you like us to invest next?
How can we best help you?
25
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
26
Tunable parameter equalizer example
Tune parameters
in real-time
See it
Tune it
Create it
Speaker
Hear it
27
Part 1: Test bench and peripheral access
28
Part 2: Algorithms
29
Example 1: Dynamic audio range expander
Audio Input Custom Audio Algorithm Audio output
x
Gain
Level Gain
LPF
measurement processor
Expand
dynamic
A range B
(dB)
(dB)
%% Terminate
release(Microphone) Terminate
release(MyTimeScope)
31
Example 2: Tunable audio parametric equalizer
Tune parameter
equalizer in real-time
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
32
How to incorporate algorithms into test bench
%% Create & Initialize
SamplesPerFrame = 1024;
FReader=dsp.AudioFileReader('guitar2min.ogg','SamplesPerFrame’,SamplesPerFrame)
Fs = FR.SampleRate; Initialize
TransferFuncEstimate= dsp.TransferFunctionEstimator('SampleRate',Fs,’FrequencyRange','onesided','SpectralAverages',1);
MyArrayPlot = dsp.ArrayPlot('PlotType','Line','Title','Transfer Function Estimate');
Speaker = dsp.AudioPlayer('SampleRate',Fs);
GUI = CreateParamTuningGUI(param, 'Tuning');
33
Part 3: Acceleration of simulation
34
Stream processing:
Data acquisition & algorithm times
As long as
We have
Real-time signal processing
35
MATLAB to C code generation* MATLAB Coder
function y = audio_algorithm_peqso(u,tunedparams)
% Copyright 2013 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
36
Simulation acceleration benchmarks
37
Audio signal processing is everywhere!
Tablet/ MP3 Player Gaming System
& Smart Phone
Automotive Audio
& Navigation System
Professional
Audio & Music Medical Devices
Hearing Aids
39
Create Your Own System Objects
properties (DiscreteState)
Mean = 0 % Initial value methods implements the functions specific to
end your system
methods (Access=protected)
function y = stepImpl(obj,u) stepImpl implements the kernel
y = u - obj.Mean; of the step function
obj.Mean = u - y*obj.Weight;
end
end
Other methods to consider:
end setupImpl, resetImpl, releaseImpl
http://www.mathworks.nl/help/dsp/basic-operations.html
40