Smoothing the curve (moving average)

2 views (last 30 days)
PRITESH GARG
PRITESH GARG on 21 Jul 2015
Answered: Star Strider on 21 Jul 2015
I have an array of size (1000,1)
. I need a smooth curve for these data points. I tried using 'smooth' command but it gives the same values as that of original array. Please guide

Answers (1)

Star Strider
Star Strider on 21 Jul 2015
It is difficult to determine what result you want, but there are several options. (I don’t have your data, so I can’t experiment with it.)
The simplest way to ‘smooth’ your signal might be to fit a 3 or 4 order polynomial to it using polyfit and its friends.
The easiest moving average filter is something like this:
s = randi(10, 1, 1000); % Signal
t = linspace(0, 1, length(s)); % Time Vector
N = 10; % Filter Length
sf = filter(ones(1,10), N, s); % Filter Signal (Moving Average)
figure(1)
plot(t, s, t, sf)
grid
If you have the Signal Processing Toolbox, experiment with the filtfilt function as well as filter.
The correct way to design a filter is a bit more involved (see this outline for instance). Begin by taking the fft of your signal to see if you can separate specific frequency bands, then low-pass filter your signal to eliminate the high-frequency components.
If you have the Signal Processing Toolbox, the Savitzky-Golay filter is another option.

Community Treasure Hunt

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

Start Hunting!