Thread Subject: Fitting Data to N-number of points

Subject: Fitting Data to N-number of points

From: ms

Date: 24 Jan, 2010 15:35:19

Message: 1 of 14

I am trying to represent data as a function of % of a particular cycle
and would like the x axis to be %(0-100). However, some of the data
are less than 100 points and some are more than 100 points. Is there
a common way this is handled? That is, for less than 100 points is
data interpolated and more than 100 points data downsampled/
resampled? I would like to have this for all of my different samples
to ultimately graph them. Hope this makes sense. Thanks.

Subject: Fitting Data to N-number of points

From: Matt J

Date: 24 Jan, 2010 16:15:05

Message: 2 of 14

ms <silvertonm@gmail.com> wrote in message <f4dd57f5-78bc-4b0e-a8b2-51fa236a8682@36g2000yqu.googlegroups.com>...
> I am trying to represent data as a function of % of a particular cycle
> and would like the x axis to be %(0-100). However, some of the data
> are less than 100 points and some are more than 100 points. Is there
> a common way this is handled? That is, for less than 100 points is
> data interpolated and more than 100 points data downsampled/
> resampled? I would like to have this for all of my different samples
> to ultimately graph them. Hope this makes sense. Thanks.
====================

No, the function plot(X,Y) will plot only the data in the vector Y versus the data in the vector X. No other data will appear on the plot, due to some implicit interpolation or otherwise.

However, you can force the x-axis of the plot to be *displayed* as 0-100, just by ussing the command

xlim([0 100])

Subject: Fitting Data to N-number of points

From: Walter Roberson

Date: 24 Jan, 2010 16:21:09

Message: 3 of 14

ms wrote:
> I am trying to represent data as a function of % of a particular cycle
> and would like the x axis to be %(0-100). However, some of the data
> are less than 100 points and some are more than 100 points. Is there
> a common way this is handled? That is, for less than 100 points is
> data interpolated and more than 100 points data downsampled/
> resampled?

interp() is used for interpolation. It has a number of options as to how
the interpolation is done; you will have to choose the most realistic
match to the characteristics of your function.

Subject: Fitting Data to N-number of points

From: dpb

Date: 24 Jan, 2010 16:24:09

Message: 4 of 14

ms wrote:
> I am trying to represent data as a function of % of a particular cycle
> and would like the x axis to be %(0-100). However, some of the data
> are less than 100 points and some are more than 100 points. Is there
> a common way this is handled? That is, for less than 100 points is
> data interpolated and more than 100 points data downsampled/
> resampled? I would like to have this for all of my different samples
> to ultimately graph them. Hope this makes sense. Thanks.

In addition to Matt J's response, iiuc you'll need to either do
something like you outline above or (probably my approach) simply
normalize based on the number of samples in the data set instead and
plot the actual data instead of worrying about getting precisely 100 points.

ie., something like

plot(100*x./x(end), y);

hth...

--

Subject: Fitting Data to N-number of points

From: Matt J

Date: 24 Jan, 2010 16:46:02

Message: 5 of 14

ms <silvertonm@gmail.com> wrote in message <f4dd57f5-78bc-4b0e-a8b2-51fa236a8682@36g2000yqu.googlegroups.com>...
> I am trying to represent data as a function of % of a particular cycle
> and would like the x axis to be %(0-100). However, some of the data
> are less than 100 points and some are more than 100 points. Is there
> a common way this is handled? That is, for less than 100 points is
> data interpolated and more than 100 points data downsampled/
> resampled? I would like to have this for all of my different samples
> to ultimately graph them. Hope this makes sense. Thanks.
======================

It would appear that you're assuming that your data contains at least 1 point equal to 100% and another that is 0%. It would also appear that sampling at integer intervals between 0% and 100% would be sufficiently fine sampling for what you're trying to do.

Without these assumptions it is not remotely clear why <100 points implies the need to interpolate or why >100 points implies the need to downsample.

Anyway, the bottom line is, in the cases where you have more than enough points to cover the desired interval, I don't see why you would need to throw data away.

In the cases where you don't have enough points in the interval covered by your data, you need to interpolate using an interpolation function that is sensible for the function you are trying to reconstruct. MATLAB's interp1() might be something to look at, as Walter said.

If you have the Curve Fit Toolbox, that will provide you with still more options than interp1. If you don't have the Curve Fit toolbox, but you do have uniformly spaced data. My interpMatrix tool can provide more flexibility than interp1:

http://www.mathworks.com/matlabcentral/fileexchange/26292-regular-control-point-interpolation-matrix-with-boundary-conditions

Subject: Fitting Data to N-number of points

From: ms

Date: 25 Jan, 2010 01:34:56

Message: 6 of 14

On Jan 24, 8:24 am, dpb <n...@non.net> wrote:
> ms wrote:
> > I am trying to represent data as a function of % of a particular cycle
> > and would like the x axis to be %(0-100).  However, some of the data
> > are less than 100 points and some are more than 100 points.  Is there
> > a common way this is handled?  That is, for less than 100 points is
> > data interpolated and more than 100 points data downsampled/
> > resampled?  I would like to have this for all of my different samples
> > to ultimately graph them.  Hope this makes sense.  Thanks.
>
> In addition to Matt J's response, iiuc you'll need to either do
> something like you outline above or (probably my approach) simply
> normalize based on the number of samples in the data set instead and
> plot the actual data instead of worrying about getting precisely 100 points.
>
> ie., something like
>
> plot(100*x./x(end), y);
>
> hth...
>
> --

Yes, this is what I would normally do. That is, just as you explain
plot the "real" data along a normalized, x-axis. The problem is, the
people I am working on these data want to have 0-100 data points for
each variable. I have seen programs that export this type of data
before, but can't recall how they did it. Thanks for the help, please
let me know if you have any other suggestions.

Subject: Fitting Data to N-number of points

From: ms

Date: 25 Jan, 2010 01:37:07

Message: 7 of 14

On Jan 24, 8:21 am, Walter Roberson <rober...@hushmail.com> wrote:
> ms wrote:
> > I am trying to represent data as a function of % of a particular cycle
> > and would like the x axis to be %(0-100).  However, some of the data
> > are less than 100 points and some are more than 100 points.  Is there
> > a common way this is handled?  That is, for less than 100 points is
> > data interpolated and more than 100 points data downsampled/
> > resampled?
>
> interp() is used for interpolation. It has a number of options as to how
> the interpolation is done; you will have to choose the most realistic
> match to the characteristics of your function.

Have any idea what to do for too many points?

Subject: Fitting Data to N-number of points

From: dpb

Date: 25 Jan, 2010 01:40:22

Message: 8 of 14

ms wrote:
> On Jan 24, 8:24 am, dpb <n...@non.net> wrote:
>> ms wrote:
>>> I am trying to represent data as a function of % of a particular cycle
>>> and would like the x axis to be %(0-100). However, some of the data
>>> are less than 100 points and some are more than 100 points. Is there
>>> a common way this is handled? That is, for less than 100 points is
>>> data interpolated and more than 100 points data downsampled/
>>> resampled? I would like to have this for all of my different samples
>>> to ultimately graph them. Hope this makes sense. Thanks.
>> In addition to Matt J's response, iiuc you'll need to either do
>> something like you outline above or (probably my approach) simply
>> normalize based on the number of samples in the data set instead and
>> plot the actual data instead of worrying about getting precisely 100 points.
>>
>> ie., something like
>>
>> plot(100*x./x(end), y);
>>
>> hth...
>>
>> --
>
> Yes, this is what I would normally do. That is, just as you explain
> plot the "real" data along a normalized, x-axis. The problem is, the
> people I am working on these data want to have 0-100 data points for
> each variable. I have seen programs that export this type of data
> before, but can't recall how they did it. Thanks for the help, please
> let me know if you have any other suggestions.

Then you'll either have to interpolate/decimate or extrapolate
(dangerous, obviously, unless it's always 100 points within the range of
the data in which it is always an interpolation process).

As others have said, interp1() and friends can help here.

If you happen to have signal processing toolbox it implements a function
resample() that could save some effort, perhaps.

--

Subject: Fitting Data to N-number of points

From: dpb

Date: 25 Jan, 2010 02:04:13

Message: 9 of 14

ms wrote:
> On Jan 24, 8:21 am, Walter Roberson <rober...@hushmail.com> wrote:
>> ms wrote:
>>> I am trying to represent data as a function of % of a particular cycle
>>> and would like the x axis to be %(0-100). However, some of the data
>>> are less than 100 points and some are more than 100 points. Is there
>>> a common way this is handled? That is, for less than 100 points is
>>> data interpolated and more than 100 points data downsampled/
>>> resampled?
>> interp() is used for interpolation. It has a number of options as to how
>> the interpolation is done; you will have to choose the most realistic
>> match to the characteristics of your function.
>
> Have any idea what to do for too many points?

Same thing. Just ask for the number and location of points wanted.

--

Subject: Fitting Data to N-number of points

From: ms

Date: 25 Jan, 2010 02:45:54

Message: 10 of 14

On Jan 24, 8:46 am, "Matt J " <mattjacREM...@THISieee.spam> wrote:
> ms <silvert...@gmail.com> wrote in message <f4dd57f5-78bc-4b0e-a8b2-51fa236a8...@36g2000yqu.googlegroups.com>...
> > I am trying to represent data as a function of % of a particular cycle
> > and would like the x axis to be %(0-100).  However, some of the data
> > are less than 100 points and some are more than 100 points.  Is there
> > a common way this is handled?  That is, for less than 100 points is
> > data interpolated and more than 100 points data downsampled/
> > resampled?  I would like to have this for all of my different samples
> > to ultimately graph them.  Hope this makes sense.  Thanks.
>
> ======================
>
> It would appear that you're assuming that your data contains at least 1 point equal to 100% and another that is 0%. It would also appear that sampling at integer intervals between 0% and 100% would be sufficiently fine sampling for what you're trying to do.
>
> Without these assumptions it is not remotely clear why <100 points implies the need to interpolate or why >100 points implies the need to downsample.
>
> Anyway, the bottom line is, in the cases where you have more than enough points to cover the desired interval, I don't see why you would need to throw data away.
>
> In the cases where you don't have enough points in the interval covered by your data, you need to interpolate using an interpolation function that is sensible for the function you are trying to reconstruct. MATLAB's interp1() might be something to look at, as Walter said.
>
> If you have the Curve Fit Toolbox, that will provide you with still more options than interp1. If you don't have the Curve Fit toolbox, but you do have uniformly spaced data. My interpMatrix tool can provide more flexibility than interp1:
>
> http://www.mathworks.com/matlabcentral/fileexchange/26292-regular-con...

Thank you Matt! As I mentioned in the previous reply, the idea was to
have data points to be plotted from 0-100 (101 points total). I
agree, that plotting the real data on a normalized x-axis is much
better (not loosing or creating data). I think the idea for having
the specified amount is for plotting purposes...showing an averaged
data point (and standard deviation) for each point of the 0-100% x-
axis.

I will try the interpolation functions as mentioned. It is my
understanding that interpolation is "creating" data( ie, when there is
not enough points), and not when you are "decreasing" points (ie, more
than 101 points of data). Is this correct?

Thanks!

Subject: Fitting Data to N-number of points

From: Matt J

Date: 25 Jan, 2010 03:07:03

Message: 11 of 14

ms <silvertonm@gmail.com> wrote in message <4d0f03bb-fae2-4829-b776-2d627b6344a4@22g2000yqr.googlegroups.com>...

> I will try the interpolation functions as mentioned. It is my
> understanding that interpolation is "creating" data( ie, when there is
> not enough points), and not when you are "decreasing" points (ie, more
> than 101 points of data).
===============

"Interpolation" means to derive a new function sample in the interval covered by your given data from the data to the left and right of the sample point. If you need to generate data outside the interval covered by your data, it's called extrapolation.

Reducing points would be called different things depending on what method you're using to do the reduction. There's no reason why interpolation couldn't be a method for reducing points as well. If you have a million points covering your 0%-100% interval, you could interpolate between these million points at 100 different locations and call these 100 interpolated values your reduced data set...

Subject: Fitting Data to N-number of points

From: ms

Date: 9 Feb, 2010 13:27:42

Message: 12 of 14

On Jan 24, 6:04 pm, dpb <n...@non.net> wrote:
> ms wrote:
> > On Jan 24, 8:21 am, Walter Roberson <rober...@hushmail.com> wrote:
> >> ms wrote:
> >>> I am trying to represent data as a function of % of a particular cycle
> >>> and would like the x axis to be %(0-100).  However, some of the data
> >>> are less than 100 points and some are more than 100 points.  Is there
> >>> a common way this is handled?  That is, for less than 100 points is
> >>> data interpolated and more than 100 points data downsampled/
> >>> resampled?
> >> interp() is used for interpolation. It has a number of options as to how
> >> the interpolation is done; you will have to choose the most realistic
> >> match to the characteristics of your function.
>
> > Have any idea what to do for too many points?
>
> Same thing.  Just ask for the number and location of points wanted.
>
> --

I have tried using interp1 and spline function in Matlab and do not
get the results similar to the original data. The data is 185x1 and I
would like to make it 101x1. I used the following:

y=data(:,1);%this is the data I would like to interpolate (186,1)
x=0:185;%same length as y
xx=0:101;% new length I would like the data
yy=interp1(x,y,xx);
plot(xx,yy);

This does not produce a similar curve as the original data. The
original data has an inverted U shape...(starts negative, goes
positive, returns negative) and the inpert1 data starts negative, then
positive, and plateaus positive (never returns negative). Is there a
way to preserve the beginning and end values?

Subject: Fitting Data to N-number of points

From: dpb

Date: 9 Feb, 2010 15:35:40

Message: 13 of 14

ms wrote:
> On Jan 24, 6:04 pm, dpb <n...@non.net> wrote:
>> ms wrote:
>>> On Jan 24, 8:21 am, Walter Roberson <rober...@hushmail.com> wrote:
>>>> ms wrote:
>>>>> I am trying to represent data as a function of % of a particular cycle
>>>>> and would like the x axis to be %(0-100). However, some of the data
>>>>> are less than 100 points and some are more than 100 points. Is there
>>>>> a common way this is handled? That is, for less than 100 points is
>>>>> data interpolated and more than 100 points data downsampled/
>>>>> resampled?
>>>> interp() is used for interpolation. It has a number of options as to how
>>>> the interpolation is done; you will have to choose the most realistic
>>>> match to the characteristics of your function.
>>> Have any idea what to do for too many points?
>> Same thing. Just ask for the number and location of points wanted.
>>
>> --
>
> I have tried using interp1 and spline function in Matlab and do not
> get the results similar to the original data. The data is 185x1 and I
> would like to make it 101x1. I used the following:
>
> y=data(:,1);%this is the data I would like to interpolate (186,1)
> x=0:185;%same length as y
> xx=0:101;% new length I would like the data
> yy=interp1(x,y,xx);
> plot(xx,yy);
>
> This does not produce a similar curve as the original data. The
> original data has an inverted U shape...(starts negative, goes
> positive, returns negative) and the inpert1 data starts negative, then
> positive, and plateaus positive (never returns negative). Is there a
> way to preserve the beginning and end values?

Well, your xx vector doesn't cover the range of values in x.

interp1 is _interpolation_ so you would need to have a vector xx that
spans the desired range but w/ different spacing if that is the objective.

 >> xxend=100;
 >> dx=x(end)/xxend;
 >> xx=[0:dx:x(end)];
 >> xx(end)
ans =
    185
 >> length(xx)
ans =
    101
 >> yy = interp1(x,y,xx);

Alternatively, the Signal Processing toolbox has additional methods
implemented such as resample that use various higher-order filtering
algorithms

--

Subject: Fitting Data to N-number of points

From: Matt J

Date: 9 Feb, 2010 15:39:04

Message: 14 of 14

ms <silvertonm@gmail.com> wrote in message <886c94f3-14d5-4f6f-9a2e-6cfe19026979@a5g2000prg.googlegroups.com>...

> I have tried using interp1 and spline function in Matlab and do not
> get the results similar to the original data. The data is 185x1 and I
> would like to make it 101x1. I used the following:
>
> y=data(:,1);%this is the data I would like to interpolate (186,1)
> x=0:185;%same length as y
> xx=0:101;% new length I would like the data
> yy=interp1(x,y,xx);
> plot(xx,yy);
>
> This does not produce a similar curve as the original data. The
> original data has an inverted U shape...(starts negative, goes
> positive, returns negative) and the inpert1 data starts negative, then
> positive, and plateaus positive (never returns negative). Is there a
> way to preserve the beginning and end values?
=====================

yy=interp1(x,y, linspace(0, 185, 102) );

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com