Simulinkにお​けるリングバッファの​作成方法について

22 views (last 30 days)
Osamu Sekino
Osamu Sekino on 19 May 2018
Commented: Osamu Sekino on 22 May 2018
Simulinkでリングバッファを作成しようとしております。
上記のモデルな動作をさせようとしております。配列の行を1500行にしたいのですが、1500個のUnit Delayを配置するのは非現実的であるためこれをMATLAB functionを用いて再現しようとしております。
そこで、MATLAB functionに下記のようなコードを書き、シミュレーションを行いました。(ここではシミュレーションを行うため、15行としています)
function y = fcn(u)
A = zeros(15,1);
A(1,1) = u;
for i = 1:10000
A = circshift(A,1);
A(1,1) = u;
y = A;
end
しかし下記の図のように、すべての行が同じ値になり正常に動作しません。
どのようにコードを修正すれば、Unit Delayを用いたモデルのような動作を実現することができますでしょうか。
参考のため、モデルのファイルを添付いたします。

Answers (1)

Naoya
Naoya on 22 May 2018
MATLAB Function を利用する場合、 Unit Delay を表現する 変数A は永続変数(persistent変数)として扱う方ができます。 persistent変数の初期化については、 A が空行列の場合で判断し、 zeros() で初期化します。 下記で所望の動作 (Unit Delay の組み合わせでモデル化した結果と同等の動作)が得られることを確認できます。
function y = fcn(u)
persistent A
if isempty(A)
A = zeros(15,1);
end
A = circshift(A,1);
A(1,1) = u;
y = A;
  1 Comment
Osamu Sekino
Osamu Sekino on 22 May 2018
解決いたしました。ご回答ありがとうございました。

Sign in to comment.

Categories

Find more on 言語の基礎 in Help Center and File Exchange

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!