"Dave Robinson" <dave.robinson@somewhere.biz> wrote in message <h444f8$4pk$1@fred.mathworks.com>...
> "R L" <rcwlhk@hotmail.com> wrote in message <h441sm$fl4$1@fred.mathworks.com>...
> > Hi everybody!
> >
> > I'm sure there must be a very simple way to solve this problem but I'm still a relative novice to Matlab so I'd appreciate any help on this! Thanks in advance to all!
> >
> > Suppose I have some time series data with an uneven sampling frequency in the form:
> >
> > A = [2008 12 2 9 31 33 1.94 2500; ...
> > 2008 12 2 9 35 18 2 100; ...
> > 2008 12 2 9 35 19 2 100; ...
> > 2008 12 2 9 35 31 1.98 100; ...
> > 2008 12 2 9 38 14 1.94 150; ...
> > 2008 12 2 9 48 49 1.90 500; ...
> > 2008 12 2 9 49 38 1.89 100; ...
> > 2008 12 2 9 49 52 1.91 100; ...
> > 2008 12 2 9 50 8 1.89 100; ...
> > 2008 12 2 9 50 12 1.89 100; ...
> > 2008 12 2 9 50 27 1.88 100]
> >
> > where effectively,
> > A = [yyyy mo dd mm ss price vol]
> >
> > yyyy  year
> > mo  month
> > dd  day
> > mm  minute
> > ss  second
> > price  price
> > vol  volume
> >
> > I have also created a matrix, say, B such that
> >
> > B = [2008 12 2 9 30 x1 y1; ...
> > 2008 12 2 9 35 x2 y2; ...
> > 2008 12 2 9 40 x3 y3; ...
> > 2008 12 2 9 45 x4 y4; ...
> > 2008 12 2 9 50 x5 y5; ...
> > 2008 12 2 9 55 x6 y6 ; ...
> > 2008 12 2 9 0 x7 y7 ; ...
> > 2008 12 2 10 5 x8 y8 ; ...
> > 2008 12 2 10 10 x9 y9 ; ...]
> >
> > Where x_i and y_j are just blanks right now but I’ve showed them here on this forum for clarity.
> >
> > My goal is to “down sample” my uneven sampled data from matrix A to the evenly sampled matrix B. Specifically, I’m interested in picking the “last” price and the “sum” of the volume. As an illustration, I want to somehow make the records
> > [9 35 18 2 100],
> > [9 35 19 2 100],
> > [9 35 31 1.98 100]
> > from A such that the corresponding entry in B would select
> >
> > [9 35 x2 y2]
> > x2 = last entry = 1.98;
> > y2 = sum = 100 + 100 + 100 + 100 = 400
> >
> > That is, all the entries in A right now correspond to the times (in hh:mm:ss) 9:35:18, 9:35:19, 9:34:19 and 9:35:31. Since all of these times fall into the 35th minute of the 9th hour (regardless of second), I would like the last price entry of these three to be inserted into the corresponding 35th minute of the 9th hour in matrix B; similarly, I would like the sum of these three volumes to be inserted in the same fashion. I would like to add that I would regard a time like 9:35:59 to be regarded to be still in the 35th minute and note "rounded up" to the 36th minute.
> >
> > I think the biggest challenge (at least to a novice like me) is to somehow set the rule such that the hours, minutes and the seconds from A matches up correctly in that of matrix B. Notice that in matrix B I have dropped the seconds column.
> >
> > I would appreciate any help in doing this! It would be a fantastic and great help! Thank you in advance!
> >
> > R L
>
> One of the standard ways of tackling this problem is to attempt to interpolate between your samples  cubic splines are often used. Once you have the interpolated waveform you can then provide a virtual uniform sample rate, and then use the Matlab function
>
> help resample > needs the signal process toolbox I believe
>
> to provide the new rate that you require. This function supplies the all of the anti aliasing filtering you need, if you are downsampling, and is probably a safer way to go rather than simply cherry picking down your interpolated data to form your newly sampled signal.
>
> Hope this helps
>
> Dave Robinson
Thanks for the advice Dave! Much appreciated!
However, for the purpose of my project, it is suffice to just "cherry pick" the data points as I had indicated above; in fact, for my purpose, it is much desired over an interpolation technique that is offered by the resample function of Matlab.
Can somebody please help? Thanks again in advance!
