How we can give Delay in a clock ?

Hi. I am using "Delayseq" function in MATLAB function block using simulink. But it doesn't provide delay in a clock. I cannot use ideal fixed unit delay block because, I need variable delay and later I have to adjust that delay. therefore, I am using this customized function. but it's not giving delay in a clock.
shifted_signal = delayseq(u,0.004,250);
here, I am giving delay 4ms and sampling frequency is 250. I set 250 because in clock generation block I set sampling time =4ms.
I attached the snaps please have a look and help in this regard. I really need help for this work. if anyone help it would be appreciated. Thanks

 Accepted Answer

delayseq works on a vector, e,g.,
>> delayseq([1;0;1;0;1;0;1;0;1;0],0.004,250)
>> ans =
0
1
0
1
0
1
0
1
0
1
while if I under your model correctly, the pulse samples are generated one at a time, that's why the function is not providing the correct answer. You can consider adding a buffer in between to convert the signal to vector, but then you need to live with the fact that there is a latency due to the buffering at the output.
HTH

13 Comments

Sarfaraz Ahmed
Sarfaraz Ahmed on 6 Nov 2018
Edited: Sarfaraz Ahmed on 6 Nov 2018
Thank you Chen for your valuable answer. I added buffere in order to convert signal into vector but it gain showing the same. That's the same buffer which you were talking about ?
could you please have a look into attached file ? Thanks you.
How did you setup the buffer? And would it be possible to share the model?
Thanks Mr.Chen, I setup just by adding buffer block between clock and delay function. I attached my model and other snap. if the model file doesn't open please let me know. inside function block the code is :
function y = sample(u)
shifted_signal = delayseq(u,0.002,500);
y=shifted_signal;
Please help me how I can add proper buffer ? so that delayseq work properly.
it would be really appreciated. Thanks
Hi. Sir could you please help me in the buffer design ? Thanks
In your model, if you set the overlay in Buffer to 1, you should be able to see the correctly shifted sequence.
If you want to further remove the extra line, you can change your code slightly by doing
y = shifted_signal(2);
HTH
Thanks sir. But if i changes the delay from 0.002 to 0.003 it should produce 1ms more delay instead it's giving straight line at 0. why it's happening ? delay should be flexible but I don't know how to fix this issue. could you please help me here ?
function y = sample(u)
shifted_signal = delayseq(u,0.003,500);
y=shifted_signal(2);
please see an attachment. Thanks
This is because if you only buffer two samples, then you don't get anything in the output since the delay is more than what can be accommodated in two samples. You certainly need to adjust parameters but in addition you probably won't get a clean signal since your delay includes a half-sample and in theory this is not well defined.
HTH
Sarfaraz Ahmed
Sarfaraz Ahmed on 9 Nov 2018
Edited: Sarfaraz Ahmed on 9 Nov 2018
Thanks Sir. I understand but I am worried how parameter can be set ? what factor/parameter needs these setting ? ok, let say I don't give much delay I just give 3us delay then how parameter setting can be defined ? Actually, I have to give some delay and later this delay control by another signal in 2,3 steps automatically not manually.
for ex, if I give delay 3us then it will reduce to zero by external signal in 3 steps. could you please help in that scenario ?
%3us delay
function y = sample(u)
shifted_signal = delayseq(u,0.000003,500);
y=shifted_signal(2);
%sampling time of clock =0.002
Thanks
Sorry I missed this.
I think an important issue here is you chose the source block which outputs one sample a time but delayseq() really likes to work with a vector. Thus the mismatch and the need for the buffer. I would suggest if possible to provide a vector as input then the processing becomes easier and you can specify the parameter more freely as long as the delay is not longer than the duration of the signal vector.
HTH
Thanks Chen.
yes, I understand but How can I pass vector clock as a source block ? This become a problem here.
Thanks
If it's just a pulse, you can try the Rectangular Waveform block from Phased Array System Toolbox.
Sarfaraz Ahmed
Sarfaraz Ahmed on 22 Nov 2018
Edited: Sarfaraz Ahmed on 22 Nov 2018
Thanks Chen, I will try this . Let see if it works in my aplication.
Thanks for such kind of supporting.
hi,
I am facing the same problem. I want to provide variable time delay to a sawtooth signal using matlab function block. Please help in this regard.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!