How to extract a period of history of a signal in simulink?
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!