How do i do moving average in s-function level 2?

1 回表示 (過去 30 日間)
dab483
dab483 2013 年 3 月 18 日
Hi i want to do moving average in s-function level 2, When using matlab script i wrote this formula where r=residual with size 1, samples is the time step.
window=10;
if samples > window
sumS = 0;
for l = 1:window,
if l==1,
S = (1/window) * (Htime(samples,:)) ./ R.^(1/2);
else
S= (1/window) * sum( (Htime(samples-(l-1):samples,:)) ./ R.^(1/2) );
end;
sumS=sumS + S*S';
end;
CovTime=((1/window)*sum(r(:,samples-window+1:samples)./ R.^(1/2))).^(2);
CovEnsemble=S*Pold*S' + (1/window);
CovDifference = CovTime - CovEnsemble;
if CovDifference > 0
Qparameter = CovDifference / sumS;
else
Qparameter = 0;
end;
the problem is when i am using s-function level 2, where i want to get this residual ~ r(:,samples-window+1:samples) , where i only have 1 data only when running the simulation. how do i get the previous data (residual) in s-function and to use in concurrently?
How do i define/ do it in s-function level 2? Thank you.

回答 (1 件)

Kaustubha Govind
Kaustubha Govind 2013 年 3 月 18 日
It looks like you need to maintain a "state" on the block. Please look into Using DWork Vectors in Level-2 MATLAB S-Function.
  1 件のコメント
dab483
dab483 2013 年 3 月 18 日
Hi, i am a bit confuse, if in matlab script to run the program i can just put for example
for sample: 1:L (where L is simulation length) EKF algorithm window =10 if samples >window ...... end
so if i define L=200 , means that i have 200 samples but in s-function with the sampling time and everything, the length becomes larger. I can just put the sampling time=1 (which is big) but it wont work in my simulink model. any advice?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by