Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Logarithmic binning of data points

105 views
Skip to first unread message

Philipp Steffen

unread,
Nov 19, 2010, 3:56:05 PM11/19/10
to
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

Walter Roberson

unread,
Nov 19, 2010, 4:05:04 PM11/19/10
to

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.

Philipp Steffen

unread,
Nov 19, 2010, 5:27:04 PM11/19/10
to
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 <robe...@hushmail.com> wrote in message <ic6oqb$suu$1...@canopus.cc.umanitoba.ca>...

Walter Roberson

unread,
Nov 19, 2010, 5:41:13 PM11/19/10
to
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);

Philipp Steffen

unread,
Nov 23, 2010, 7:42:03 AM11/23/10
to
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 <robe...@hushmail.com> wrote in message <ic6uek$85c$1...@canopus.cc.umanitoba.ca>...

0 new messages