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 comentario

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.

Iniciar sesión para comentar.

Respuestas (1)

Torsten
Torsten el 3 de Nov. de 2023
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 comentario

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

Iniciar sesión para comentar.

Categorías

Productos

Versión

R2023a

Etiquetas

Preguntada:

el 3 de Nov. de 2023

Comentada:

el 3 de Nov. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by