DSP: Best curve fitting approach via MATLAB?

ElijahRockers
Gold Member
Messages
260
Reaction score
10
I am doing an experiment that generates data in three 1-hour-blocks. Each block has a different number and timing for acquisitions. (The first hour is more frequent and numerous, while the last hour is only 6 acquisitions)

The reason for breaking it up into 3 hours is to give the subjects a break from the experiment. My ultimate goal is to try to account for the break times (perhaps just linearly interpolating where the breaks should be), and create a new curve that is a smoothed version of the original data with the breaks added.

Unfortunately I run into a bit of a speed bump, when I try a smoothing filter, there seems to be an artifact where the breaks are, I believe because of the discontinuities (both in value, and probably in time also).

Does anyone have any advice as to how I might best go about constructing a smooth curve based on this data? Polyfit is just not faithful enough to the original data.

This is a link to two graphs, the top graph being the data with break times inserted into the x-axis, whereas the bottom graph is the same plot after a smoothing filter.

Thanks in advance!
 
Physics news on Phys.org
Can you do it in freq domain? Just throwing out ideas.
 
It's hard for me to tell where the breaks are. Are you just connecting the breaks with straight lines (linear interpolation) and then trying to filter out the discontinuities?

You would be better off with cubic spline interpolation or some other sort of polynomial best fit.

https://en.wikipedia.org/wiki/Spline_(mathematics)

WHat does the MATLAB manual say about interpolation?
See "interpolating missing data" here http://www.mathworks.com/help/matlab/data_analysis/missing-data.html
 
meBigGuy said:
It's hard for me to tell where the breaks are. Are you just connecting the breaks with straight lines (linear interpolation) and then trying to filter out the discontinuities?

You would be better off with cubic spline interpolation or some other sort of polynomial best fit.

https://en.wikipedia.org/wiki/Spline_(mathematics)

WHat does the MATLAB manual say about interpolation?
See "interpolating missing data" here http://www.mathworks.com/help/matlab/data_analysis/missing-data.html

Yea, the time gaps have been linearly interpolated by MATLAB, at least as far as the plotting goes..

I have corrected the data so it now looks like a relatively smooth curve (i.e. there are no large 'kinks' in the curve), but it has yet to be actually smoothed. Whenever I do the smoothing, I still get large discontinuous looking artifacts at the first break, I assume because the time gap is so much larger.

Would it be better to interpolate those points and THEN do the smoothing? The problem is I have a large data set and the time gaps are not consistent, I would have to interpolate a little differently for each sequence.
 
meBigGuy said:
See "interpolating missing data" here http://www.mathworks.com/help/matlab/data_analysis/missing-data.html

Duh, my brain. I see, thanks for the link. I performed a linear interpolation using interp1(), then sgolayfilt() to smooth the curve. The results are astounding, thanks!
 

Similar threads

  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 12 ·
Replies
12
Views
7K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 6 ·
Replies
6
Views
6K
  • · Replies 4 ·
Replies
4
Views
11K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 11 ·
Replies
11
Views
4K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 5 ·
Replies
5
Views
12K