Delay line for code generation
41 views (last 30 days)
Show older comments
Hi,
I am doing audio processing algorithms in matlab code that should support code generation. What is a good choice for a simple delay? The delay does not need to change during processing, it should be efficient, have a fixed upper bound and the actual delay set during initialization from a parameter (before playback starts).
I would like to avoid reinventing the wheel or at least reinventing delay lines. Is dsp.VariableIntegerDelay a good choice for this purpose?
dsp.VariableIntegerDelay seems to work for processing in matlab but I have not tried codegen yet.
When I check the size of my dsp.VariableIntegerDelay as a member of my processor object using whos, I get 8 bytes. Seems weird since I instantiated it using dsp.VariableIntegerDelay('MaximumDelay',256);
Thanks
1 Comment
Walter Roberson
on 16 Dec 2024 at 18:58
When I check the size of my dsp.VariableIntegerDelay as a member of my processor object using whos, I get 8 bytes.
Likely you are checking the size of a handle object. whos reflects the size of the handle pointer, 8 bytes, not the size of the underlying object.
Answers (1)
jibrahim
on 13 Dec 2024 at 18:52
There are multiple objects you can use to model delays:
- dsp.Delay: Delay input signal by fixed samples
- dsp.VariableIntegerDelay: Delay input by time-varying integer number of sample periods
- dsp.VariableFractionalDelay: Delay input by time-varying fractional number of sample periods
They all support code generation.
You can't use 'whos' to check how much memory the object is consuming, as 'whos' just returns the size of the handle variable pointing to the object.
10 Comments
jibrahim
on 19 Dec 2024 at 19:27
Hi Mattias,
To make the function friendly to streaming scenarios, simply declare the object as persistent:
function y=foo(x)
persistent delay_line_1
if isempty(delay_line_1)
delay_line_1 = dsp.VariableIntegerDelay('MaximumDelay',128);
end
y = delay_line_1(x,2);
end
This is a very common pattern with system objects and objects with state in general.
See Also
Categories
Find more on C Code Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!