Tapped delay function with varying size in Simulink

Hello
I wanted to know if there a way to give the "Number of delays" externally in the tapped delay function.
My idea is, the user should be able to connect an input port and this port gives the number of delays that the tapped function needs to have. So as to make it dynamic and not static where I set the number of delays during development phase itself.
(Setting parameters of the tapped delay function in simulink externally)
Thanks

 Accepted Answer

Hi Swati
I have tested a few things and I don't think it is an easy problem to solve.
I have personally never used the Tapped Delay - and I don't know why you need it in your specific application - but the issue I see is that the output dimension depends on the number of delays you put into the dialog. If you enter 4, then the signal dimension of the output is 4. If you chose 7, the signal dimension if 7. That's why it is very difficult - I believe even impossible - to provide it as an input port.
One thing I was thinking about, is that the Unit delay block can have the delay length as an Input port. You can change this during simulation. But it will only output the input signal with the defined delay, it will not provide all other signals such as the Tapped Delay block does.
With kind regards,
Jonas

4 Comments

Hi Jonas,
Thanks for taking out the time.
My reason for using a tapped delay function is ideally not to delay my signal (so unit delay won't suffice) but to store the value indirectly.
Ideally i want to kind of build a storage/array where the user can define the number of values to be stored and then average out the value.
I noticed that the atpped delay function perfectly stores the values as per my requirement and hence wanted to edit the number of delays externally.
The challenge is I can't use matlab/ even a S function for my application and have to stick to simulink blocks to build my logic.
Is there a method to acheive this?
So you are trying to implement a Moving Average Filter?
Take a look at the answer posted here. Using the Selector and Memory block, you can store the last N samples of a signal. What you can do, is implement this where N is the highest amount of samples you will want to store or take the average of. Afterwards, you can use another Selector block where the index is not a fixed value such as N, but an input port with the amount of samples you want to select.
The reason why you need another Selector block is that the Memory and IC block require a fixed size, so you first store the maximum you will need which is fixed (N), and then after you pick a smaller selection of that which can be flexible.
Please check attached for the Simulink model. I have saved it in version R2019a.
Thanks,
Din't realise that the function i was trying to acheive using a tapped delay can also be implemented using the selector.
Cheers!

Sign in to comment.

More Answers (1)

Hi Swati,
Try to use one variable in "Number of Delays" field.
In my case, I wanted "Number of Delays" to be equal to Simulation Time. So first I wrote the variable:
After that, create a Matlab function externally, with the algorithm of your input value and use Callbacks (in Model Explorer) to run the Matlab function (in my case, the variable was created when the model was run, so I used the function in InitFnc):
Matlab Script saved as "StopTime_InitF"
StopTime_1 = double(0);
My_model = get_param(0, 'CurrentSystem');
stop_time_as_str = get_param(My_model, 'StopTime');
StopTime_1 = str2double(stop_time_as_str);
The function will modify "StopTime_1" variable in Model Workspace just before running the model.
Then, "Number of Delays" has been modified externally.
I hope you can adapt this to your case.
Regards,
Oscar.

1 Comment

Hi Oscar,
I have a similar issue and worked this out before.
I think this mostly works if you stay with simulation or C code generation.
My application requires HDL generation and it is a pain to regenerate this all over again all the time using this method.
I'm using the Memory and Selector method as above.
Regards,
V.

Sign in to comment.

Categories

Find more on General Applications in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!