signal processing with matlab: system simulation and real-time implementation · 2 why are we here...
TRANSCRIPT
1© 2014 The MathWorks, Inc.
Signal Processing with MATLAB: System Simulation
and Real-Time Implementation
Jonas Rutström
Senior Application Engineer
2
Why are we here today?
Learn more about algorithm and system design in MATLAB and Simulink
– The why, how, and what…
Hopefully get some new ideas that makes you work easier
– There is always someting new to learn…
Give you the possibility to talk with MathWorks representatives
– Share your thoughts, give us feedback – We are here for you!
3
Algorithm Development
ALGORITHM
Hardware Implementation
4
DEMO(Kinect)
5
From MATLAB Script to Real-Time C Code
6
C/C++
MATLAB1. Experiment with algorithm in MATLAB
2. Customize the MATLAB code
3. Generate C/C++ code
4. Verify/validate generated code
5. Optimize generated code
7
1. Experiment with algorithm in MATLAB
2. Customize the MATLAB code
3. Generate C/C++ code
4. Verify/validate generated code
5. Optimize generated code
C/C++
MATLAB
8
A closer look at the algorithm…
9
delay
Sound source
delay
𝜃
ALGORITHM
d
d
10
How to calculate the delay?
11
Cross-correlation Interpolation
Delay
12
1. Experiment with algorithm in MATLAB
Simplify:
– Get a static source
– Take a picture
– Record the stereo audio input
Understand your setup
– Distance between microphones?
– Resonable delay?
Implement according to the masterplan
– verify the result
13
DEMO(MATLAB Script)
14
1. Experiment with algorithm in MATLAB
15
What is the next step?
16
1. Experiment with algorithm in MATLAB
2. Customize the MATLAB code
3. Generate C/C++ code
4. Verify/validate generated code
5. Optimize generated code
C/C++
MATLAB
17
How do you intend to use the algorithm?
18
19
“Real-Time”
20
Function + Test bench
21
2. Customize the MATLAB code
Testability
Re-usability
C code generation
Algorithm
22
2. Customize the MATLAB code
Testability
Re-usability
C code generation
AlgorithmAlgorithm
AlgorithmAlgorithm
Algorithm
23
2. Customize the MATLAB code
Testability
Re-usability
C code generation
24
DEMO(Algorithm + Test Bench + Code Generation)
25
2. Customize the MATLAB Code
26
Performance?
27
tic/toc
% start timer
tic
% execute code
out = myFunction(in);
% stop timer (and store
% elapsed time)
et = toc;
profile
% turn on profiler
profile on
% execute code
out = myFunction(in);
% turn off profiler
profile off
% open html report
profile report
Where are the bottlenecks?
2. Customize the MATLAB Code
How long did it take?
28
Before After
2. Architect/review/optimize MATLAB code
Let´s profile two versions of the interpolate function!
29
DEMO(Profiling)
30
Alternative 1 Alternative 2
2. Architect/review/optimize MATLAB code
31
Alternative 1 Alternative 2
Interpolation: 5x faster Algorithm: > 2x faster
2. Architect/review/optimize MATLAB code
32
Lesson learned from profiling?
– Separate initialization and setup from recurring execution
2. Architect/review/optimize MATLAB code
33
Can we make it execute faster?
34
1. Experiment with algorithm in MATLAB
2. Customize the MATLAB code
3. Generate C/C++ code
4. Verify/validate generated code
5. Optimize generated code
C/C++
MATLAB
35
DEMO(MATLAB to C MEX)
36
~8x faster
3. Generate C/C++ Code
37
Are there other implementation options?
38
System Objects
39
2. Architect/review/optimize MATLAB code
init/setup
process
40
2. Architect/review/optimize MATLAB code
~ 2X faster in MATLAB
41
~3x faster in C
3. Generate C/C++ Code
42
3. Generate C/C++ Code
43
3. Generate C/C++ Code
44
45
46
1. Experiment with algorithm in MATLAB
2. Customize the MATLAB code
3. Generate C/C++ code
4. Verify/validate generated code
5. Optimize generated code
C/C++
MATLAB
47
4. Verify/Validate Generated Code
Software-in-the-Loop Verification
48
DEMO(Software-in-the-Loop)
49
1. Experiment with algorithm in MATLAB
2. Customize the MATLAB code
3. Generate C/C++ code
4. Verify/validate generated code
5. Optimize generated code
C/C++
MATLAB
50
4. Optimize Generated Code
Operator level (e.g. fixed-point arithmetic)
c = a + b
*c = _sadd(a, b)
Routine level
out = matlabFcn(in)
optimFcn(*in, *out)
Solution: Code Replacement Libraries (CRL)(requires Embedded Coder)
coder.replace
51
4. Optimize Generated Code
coder.ceval('cfun_name', arg1, arg2, …)
Calling legacy code
Non-algorithmic code (e.g. peripherals, profiling)
Interacting with larger C/C++ application
Verifying C/C++ using existing MATLAB testbench
52
What if software is not fast enough?
53
HW/SW Co-Design
= +SoftwareHardwareSystem
54
HW/SW Co-DesignThe Zynq Platform - Example
FPGAARM
55
HDL MATLAB
Generating HDL Code
56
DEMO(MATLAB HDL Code)
57
HDL
Manual Translation
Manual Verification
MATLAB
Verifying Handwritten HDL Code
58
DEMO(Verification of Handwritten HDL Code)
59
Algorithm Development
ALGORITHM
Hardware Implementation
60
1. Experiment with algorithm in MATLAB
2. Customize the MATLAB code
3. Generate C/C++ code
4. Verify/validate generated code
5. Optimize generated code
C/C++
MATLAB
Summary | Algorithm Development
61
Summary | Hardware Implementation
= +SoftwareHardwareSystem
“Integrated Workflow for both SW and HW System Design”
62
Contact us for more information:
www.mathworks.com
Wrap Up and Q & AMore information…