Can someone please help me figure this out, this is part of a bigger code. If the input is 3 we want the output to be 1 2 1. If the input is 5 we want the output to be 1 2 3 2 1 and so on.The input could be any odd number 3,5,7,9… Thank you in advanced and please let me know if you have any questions. Follow up : I am trying to create n point symmetric weighted moving filter, without the use of filter function. I attached an image of my approach. (I can't figure out how to upload the excel file)
time=xlsread('ECG','A:A') amp=xlsread('ECG','B:B') N=length(time) for i=2:N-1 %3 point filter
t(i-1)= (amp(i-1)+2*amp(i)+amp(i+1))/4; end for i=3:N-2%5 point filter
t2(i-2)=(amp(i-2)+2*amp(i-1)+3*amp(i)+2*amp(i+1)+amp(i+2))/9 end %My approach for n weighted filter:
n=input('enter point: '); k= floor(n/2); for i=k+1:N-k weights=[1 2 1]%if the input was 3
x(i-k)=(amp(weights.*(i-k:i+k))/sum(weights); end
Best Answer