How to extract a period of history of a signal in simulink?
Show older comments
I would like to extract a period of history of a signal in simulink. Say, I have a discrete sampled signal 'u', the task is to retrieve the vector [u(k-1), u(k-2), ..., u(k-N)], where each 'k' represents the signal at each sampled time. When k<N+1, we set the elements at k:N as zeros since there is no definition of the signal before the starting time. I have a simple M-file that can do the job (see the following code), but I feel puzzled to implement this functionality in simulink. The input variable 'u' in the M-file is the measured signal that I want to create a buffer zone to store the period from u(k-1) backward to u(k-N). Can anyone give me a hint on this, thanks a million.
function hist = extract_hist(u, k, N)
% -------------------------------------------------------------------------
% Extract a period of history of a signal 'u' at a given discrete moment
% 'k'. The output stores the history from u(k-1) to u(k-N) in a stack form.
% For the discrete moments before (N+1), elements from k:N are zeros. The
% input signal 'u' shall be an ongoing growing vector in simulink.
% -------------------------------------------------------------------------
hist = zeros(N,1);
if k >= N+1
hist = u(k-1:-1:k-N);
elseif k > 1 && k < N+1
hist(1:k-1) = u(1:k-1);
end
Answers (1)
You can use a group of Unit Delay Blocks to do the same. That precisely does what you want.
3 Comments
Fu-Rui Xiong
on 21 Oct 2013
ES
on 21 Oct 2013
You need this, use a MATLAB Fcn Block and place your code inside.
Fu-Rui Xiong
on 21 Oct 2013
Categories
Find more on Signal Attributes and Indexing 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!