+1  A: 

I'd first try to display the running average over a number of points, like 5 or 10. This way, a single discrepancy in the values only have a little impact on the graph. Of course, it depends on how accurate you need the graph to be.

driis
+5  A: 

A simple (ad hoc) way is to just take a weighted average (tunable by alpha) at each point with its neighbors:

data(2:n-1) = alpha*data(2:n-1) + (1-alpha)*0.5*(data(1:n-2)+data(3:n))

or some variation thereof. Yes, to be more sophisticated you can Fourier transform your data first, then cut off the high frequencies. Something like:

f = fft(data)
f(n/2+1-20:n/2+20) = zeros(40,1)
smoothed = real(ifft(f))

This cuts out the highest 20 frequencies. Be careful to cut them out symmetrically otherwise the inverse transform is no longer real. You need to carefully choose the cutoff frequency for the right level of smoothing. This is a very simple kind of filtering (box filtering in frequency domain), so you can try gently attenuating high order frequencies if the distortion is unacceptable.

Victor Liu
shouldn't c=ifft(fft(a)) always give c=a? it is true for some cases but not for a=[2 3 4 5 6 1 2 4 7 3 3 21 1 4 5 77 3 2 256 3 312 1 5 76 4 3 3 2 6 7 3 3 56 5 645 4 4 4 4] I am getting some imaginary numbers in c. Any guesses why?
Lazer
@eSKay: It is exactly true for me. However due to rounding, c may acquire a small imaginary component. I fixed the code above to put real on the outside of ifft, as it should have been.
Victor Liu
@Victor Liu okay. what is 'n' in your calculation of smooth?
Lazer
@eSKay: `n` is the length of the data.
Victor Liu
@Victor Liu thanks.
Lazer
+5  A: 
Amro
@Amro thanks, using smooth() is easy and simple!
Lazer
+1  A: 

FFT isn't a bad idea, but it's probably overkill here. Running or moving averages give generally poor results and should be avoided for anything besides late homework (and white noise).

I'd use Savitzky-Golay filtering (in Matlab sgolayfilt(...)). This will give you the best results for what you are looking for - some local smoothing while maintaining the shape of the curve.

-Paul

Paul

related questions