How to extract a period of history of a signal in simulink?

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

Respuestas (1)

ES
ES el 21 de Oct. de 2013
Editada: ES el 21 de Oct. de 2013
You can use a group of Unit Delay Blocks to do the same. That precisely does what you want.

3 comentarios

Indeed, this is a solution, but when the history extraction turns out longer, say, I wanna extract 45 historical moments from u(k-45) to u(k-1), it must be a tedious job to pile all those modules in a model. Is there a way to vectorize the block like unit delay? Or how can I integrate the M-file I wrote to a simulink model? I feel puzzle because the signal itself is growing during the measuring process. Thanks anyway Chocolate.
Thanks buddy, I'll try it out.

Iniciar sesión para comentar.

Categorías

Más información sobre Simulink en Centro de ayuda y File Exchange.

Preguntada:

el 21 de Oct. de 2013

Comentada:

el 21 de Oct. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by