Smoothing the curve (moving average)
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
Star Strider
le 21 Juil 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.
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!