Index exceeds the number of array elements error

I am trying to do a recursion operation to get the output of a butterworth filter (A, B) 'y', where 'x' is the vector of a soundfile. I am getting the error 'Index exceeds the number of array elements error. Index must not exceed 28153' (28153 is the length of x) in line 17 and i was wondering if anyone could spot what is going wrong in the code?
Thanks in advance!
a = A
b = [0 B]
y0 = 0
x0 = 0
n = 1:length(x)
z = ones(1, length(n))
y1 = recur(a, b, n, z, x0, y0)
function y = recur(a,b,n,z,x0,y0)
N = length(a);
M = length(b)-1;
y = [y0 zeros(1,length(n))];
z = [x0 z];
a1 = a(length(a):-1:1); % reverses the elements in a
b1 = b(length(b):-1:1);
for i=N+1:N+length(n),
y(i) = -a1*y(i-N:i-1)' + b1*z(i-N:i-N+M)';
end
y = y(N+1:N+length(n));
end

댓글 수: 1

Where do you get the error, in which line?
Also copy and paste the full error message i.e. all of the red text.
There are many undefined parameters in your code, so we can not run your code and see where the error occurs.

댓글을 달려면 로그인하십시오.

답변 (1개)

Torsten
Torsten 2023년 11월 3일
y(i-N:i-1) is a vector of length N
z(i-N:i-N+M) is a vector of length M+1
y(i) is a single value of length 1
How do you imagine
y(i) = -a1*y(i-N:i-1)' + b1*z(i-N:i-N+M)';
should work ?

댓글 수: 1

The dimensions of a and b are not known as well, the matrix multiplication might be not be possible.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2023a

질문:

2023년 11월 3일

댓글:

2023년 11월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by