MATLAB: How to apply moving average filter for continious strem of incomming data

moving average filter

i am having accelerometer and i am getting its x,y and z axis values(in g units) continuously from the serial port. i need to filter/smooth-en the incoming data. so i want to apply moving average filter/Savitzky-Golay smoothing filters.. how can i do it?. In http://in.mathworks.com/help/matlab/data_analysis/filtering-data.html they took an 24×3 array.. but in my case array size is not known or it keeps on increasing.. so how to solve this problem?

Best Answer

To do real-time filtering, you need the DSP System Toolbox. You probably also need specialised hardware. (I have no experience with the DSP System Toolbox, so I cannot help you with it.)
I seriously doubt that you could do a Savitzky-Golay filter in real time. Instead, save your raw signals and process them later. You will need to do a fft on your saved signals, determine the frequencies of the signals and the frequencies of the noise, then design a bandpass filter to eliminate the d-c offset and slow baseline drift on the low end, and noise at the high end. You cannot eliminate broadband noise with a frequency selective filter, so some noise will remain after the filtering process.