I need to implement the Matlab
filter(b,a,x) function in Java. Before I do this, I would like to rewrite the function in Matlab before translating into Java. So far, writing out all the coefficients works really well. See below:
x = load('data.csv'); windowSize = 10; b = (1/windowSize)*ones(1,windowSize); % b coefficient - a is unused i = 1; for n = length(b) : length(x) % yes I know I am losing my first 10 samples y(i,:) = [ b(1)*x(n) + b(2)*x(n-1) + b(3)*x(n-2) + b(4)*x(n-3) + ... b(5)*x(n-4) + b(6)*x(n-5) + b(7)*x(n-6) + b(8)*x(n-7) + ... b(9)*x(n-8) + b(10)*x(n-9) ]; i = i+1; % used for indexing calculated results into new array end
However, I want the loop contents to automatically update when I change the window size. In the above example, if I were to increase the windowsize by a factor of two, then I would have to write out twice as many multiples of b and x within the for loop. Which is a terrible solution to my problem. Please advise.