フィルターのクリア

Signals Question difference equation: Write a function y=diffeqn(a,x,yn1) which computes the output y[n] determined by the first-order system y[n]=ay[n-1]+x[n]

2 ビュー (過去 30 日間)
I need to Write a function y=diffeqn(a,x,yn1) which computes the output y[n] of the causal system determined by the first-order autoregression system y[n]=ay[n-1]+x[n] The input vector x, contains x[n] for 0 ≤ n ≤ N − 1 and yn1 supplies the value of y[-1]. The output vector y contains y[n] for 0 ≤ n ≤ N − 1.
Note that y[−1] is necessary for computing y[0], which is the first step of autoregression. Use a for loop in your M-file to compute
  5 件のコメント
Rick Rosson
Rick Rosson 2014 年 9 月 11 日
I don't think you need a function within a function. Instead, you need a function that computes y as required and then a script that calls your function once or perhaps several times to test out your function.

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

採用された回答

Image Analyst
Image Analyst 2014 年 9 月 11 日
Hint, in test.m have both of these functions.
function test()
a = 10; % For example.
x = randi(9, 1, 7); % 1 by 7 array of integers
yn1 = 5; % For example.
yOut = diffeqn(a, x, yn1);
function [y, yn] =diffeqn(a,x,yn1)
for k = 1 : length(x)
y(k) = .....
end
% Not sure exactly what is meant by y[n], so return the full the y and y(n), i.e. the last element by itself.
yn = y(end);
Good luck.
  3 件のコメント
Rick Rosson
Rick Rosson 2014 年 9 月 11 日
編集済み: Rick Rosson 2014 年 9 月 11 日
Since y(k) depends on y(k-1), the lower limit on the for loop should be 2 instead of 1. Otherwise, the code will trigger an error or you will need an if...else... block inside the loop (to handle the first element as a special case), which is not ideal.

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

その他の回答 (1 件)

Rick Rosson
Rick Rosson 2014 年 9 月 11 日
編集済み: Rick Rosson 2014 年 9 月 11 日
Here's a start. Create a file called diffeqn.m and insert the following code:
function y = diffeqn(a,x,yn1)
% Number of rows:
N = size(x,1);
% Pre-allocate:
y = zeros(N,1);
y(1) = ...
for k = 2:N
...
...
...
end
end

カテゴリ

Help Center および File ExchangeMeasurements and Feature Extraction についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by