Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Logarithmic binning of data points

Subject: Logarithmic binning of data points

From: Philipp Steffen

Date: 19 Nov, 2010 20:56:05

Message: 1 of 5

Hi all,

i am wondering if anybody has suggestions how to implement the following problem:

i have around 600 data points that were collected over time (50ms intervals). The first part of the timeseries is most important for the analysis. I therefore would like to bin the data in a way that over time more and more time-points are binned and therefore the measurements averaged. For example:
Datapoints to average:
1
2-3
4-6
7-10
11-15

Is there a way to do this automatically?
Thanks a lot for your suggestions,

Philipp

Subject: Logarithmic binning of data points

From: Walter Roberson

Date: 19 Nov, 2010 21:05:04

Message: 2 of 5

On 10-11-19 02:56 PM, Philipp Steffen wrote:

> i am wondering if anybody has suggestions how to implement the following
> problem:
>
> i have around 600 data points that were collected over time (50ms
> intervals). The first part of the timeseries is most important for the
> analysis. I therefore would like to bin the data in a way that over time
> more and more time-points are binned and therefore the measurements
> averaged. For example:
> Datapoints to average:
> 1
> 2-3
> 4-6
> 7-10
> 11-15
>
> Is there a way to do this automatically?

logspace() to get the boundaries. histc() the times against those boundaries,
throwing away the bin counts and keeping the indices. accumarray() using the
indices as the bin numbers and the sample values as the values to accumulate,
and using @mean as the optional function to apply to the accumulated values.

Subject: Logarithmic binning of data points

From: Philipp Steffen

Date: 19 Nov, 2010 22:27:04

Message: 3 of 5

Hi Walter,
thanks for your response. I know have an idea how to approach my problem. Unfortunately I do not quite understand how I can get the boundaries using logspace and histc. Perhaps you could give me another hint?
Which parameters to use with logspace? How can i use its output for histc?

Thank you,

Philipp

Walter Roberson <roberson@hushmail.com> wrote in message <ic6oqb$suu$1@canopus.cc.umanitoba.ca>...
> On 10-11-19 02:56 PM, Philipp Steffen wrote:
>
> > i am wondering if anybody has suggestions how to implement the following
> > problem:
> >
> > i have around 600 data points that were collected over time (50ms
> > intervals). The first part of the timeseries is most important for the
> > analysis. I therefore would like to bin the data in a way that over time
> > more and more time-points are binned and therefore the measurements
> > averaged. For example:
> > Datapoints to average:
> > 1
> > 2-3
> > 4-6
> > 7-10
> > 11-15
> >
> > Is there a way to do this automatically?
>
> logspace() to get the boundaries. histc() the times against those boundaries,
> throwing away the bin counts and keeping the indices. accumarray() using the
> indices as the bin numbers and the sample values as the values to accumulate,
> and using @mean as the optional function to apply to the accumulated values.

Subject: Logarithmic binning of data points

From: Walter Roberson

Date: 19 Nov, 2010 22:41:13

Message: 4 of 5

On 10-11-19 04:27 PM, Philipp Steffen wrote:
> Hi Walter,
> thanks for your response. I know have an idea how to approach my
> problem. Unfortunately I do not quite understand how I can get the
> boundaries using logspace and histc. Perhaps you could give me another
> hint?
> Which parameters to use with logspace? How can i use its output for histc?

N bins, times from 1 to maxT, data in SampleValues

[unused, binidx] = histc(1:maxT,logspace(log10(1),log10(maxT),N+1));
means = accumarray(binidx.', SampleValues(:), [], @mean);

Subject: Logarithmic binning of data points

From: Philipp Steffen

Date: 23 Nov, 2010 12:42:03

Message: 5 of 5

Hi Walter,

thank you for your help and sorry for my late response. I was able to use your solution and modified it slightly for my purposes. Now I am wondering if you could help me with one more thing:
Thats my function:

function [ logtime logdata ] = LogBinData( time, data, bins )
spacing=logspace(log10(1),log10(length(time)+1),bins);
[~, binidx] = histc(1:length(time),spacing);
timemeans = accumarray(binidx.', time', [], @mean);
if time(1)==0,
    logtime=[0; timemeans(timemeans~=0)];
else
    logtime=timemeans(timemeans~=0);
end
datameans = accumarray(binidx.', data', [], @mean);
logdata=datameans(datameans~=0);
end

If I provide let say 550 datapoints and chose to do the logspace with bins=100 I will end up with 71 log-binned data point.
Thats all right. If my data changes, and I want to bin let say 750 datapoint I would like to get a solution that corresponds to the previous binning of 550 datapoints but just goes beyond that. How could I achieve this? I am not quite clear about the relation of my variable bins that determines the spacing and the number of bins that I end up after getting rid of the zero values.
I would be really thankful for any advice.
Thanks a lot,

Philipp



Walter Roberson <roberson@hushmail.com> wrote in message <ic6uek$85c$1@canopus.cc.umanitoba.ca>...
> On 10-11-19 04:27 PM, Philipp Steffen wrote:
> > Hi Walter,
> > thanks for your response. I know have an idea how to approach my
> > problem. Unfortunately I do not quite understand how I can get the
> > boundaries using logspace and histc. Perhaps you could give me another
> > hint?
> > Which parameters to use with logspace? How can i use its output for histc?
>
> N bins, times from 1 to maxT, data in SampleValues
>
> [unused, binidx] = histc(1:maxT,logspace(log10(1),log10(maxT),N+1));
> means = accumarray(binidx.', SampleValues(:), [], @mean);

Tags for this Thread

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.

Contact us