Delay line for code generation

41 views (last 30 days)
Mattias Arlbrant
Mattias Arlbrant on 13 Dec 2024 at 15:48
Commented: jibrahim on 19 Dec 2024 at 19:27
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
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.

Sign in to comment.

Answers (1)

jibrahim
jibrahim on 13 Dec 2024 at 18:52
There are multiple objects you can use to model delays:
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
Mattias Arlbrant
Mattias Arlbrant on 19 Dec 2024 at 14:54
I have successfully used this code structure with many different structs, it seems like problems begin when I try to use system objects like my own objects.
jibrahim
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.

Sign in to comment.

Products


Release

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!