Matlab Tips in Signal Processing
Moving average filter
To compute an N-sample moving average of x with zero padding:
y=filter(ones(N,1)/N,1,x);
For large N, it is faster to use
x = [1:0.2:4]‘;
N = 5;
windowSize = 5;
y1 = filter(ones(1,N)/N,1,x);
y2=cumsum(x)/N;
y2(N+1:end)=y2(N+1:end) – y2(1:end-N);
Locating zero-crossings and extrema
To obtain the indices where signal x crosses zero:
i=find(diff(sign(x))); % The kth zero crossing lies between x(i(k)) and x(i(k)+1)
Linear interpolation [...]

