Delay line for code generation
Mostrar comentarios más antiguos
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 comentario
Walter Roberson
el 16 de Dic. de 2024
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.
Respuestas (1)
jibrahim
el 13 de Dic. de 2024
0 votos
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.
13 comentarios
Mattias Arlbrant
el 16 de Dic. de 2024
jibrahim
el 16 de Dic. de 2024
Hi Mattias,
This depends on your use case. Make sure you use the minimum required resources for your problem (e.g. number of filter states, delay length, etc), and the generated code will honor your selections.
Mattias Arlbrant
el 17 de Dic. de 2024
jibrahim
el 17 de Dic. de 2024
I think you should use dsp.VariableIntegerDelay and set its MaximumDelay to the value that works for you.
Mattias Arlbrant
el 19 de Dic. de 2024
Editada: Mattias Arlbrant
el 30 de Dic. de 2024
jibrahim
el 19 de Dic. de 2024
Hi Mattias,
dsp.VariableIntegerDelay supports code generation. For example, this generates code fine:
function y=foo(x)
delay_line_1 = dsp.VariableIntegerDelay('MaximumDelay',128);
y = delay_line_1(x,2);
end
% codegen foo -args {1}
The error must be caused by some other line of code, maybe by how the structure is handled. If you share a function or class where I can reproduce the issue, I can take a look.
Mattias Arlbrant
el 19 de Dic. de 2024
Editada: Mattias Arlbrant
el 19 de Dic. de 2024
Mattias Arlbrant
el 19 de Dic. de 2024
Mattias Arlbrant
el 19 de Dic. de 2024
jibrahim
el 19 de Dic. de 2024
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.
Mattias Arlbrant
el 30 de Dic. de 2024
Walter Roberson
el 30 de Dic. de 2024
I definitely want to avoid using global variables and instead make the delaylines members of structs or classes.
If you were to create struct or class variables representing the integer delay, and were to somehow import them into the function, then you would run across the problem that simulink signals cannot be System objects and so you cannot store system objects in simulink variables. As a result, the best you could do would be to import a variable that is an integer or double, and create the dsp.VariableIntegerDelay every time though the function.
Mattias Arlbrant
el 31 de Dic. de 2024
Categorías
Más información sobre Signal Generation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!