Spike Count from Time Series Data Sets

UseLessFuel

New Member
Joined
Dec 22, 2012
Messages
37
Hi - in need of help again. I require to count the number of large spikes per week from over two years of, mostly hourly, timestamped data from around 50 data sets. Some sets are in half-hourly intervals. Unfortunately there are cases of missing data, ranging from 1 record up to 140 records or more, and one full 24-hour period may consist of 23 to 25 records, so any collating would have to be based on times rather than Row numbers (I think!).

The time-stamps (dd-mmm-yyyy hh:mm:ss) start in cell A2 while the spike data starts in cell B2. The total number or Rows, ranges from around 5,800 to 22,000 per data set.

A large spike is characterised by increasing values over a period of at least 3 hours (i.e. 3 data points in an hourly dataset, 6 points in a half-hourly dataset). Each large spike rises by at least “1” over the 3 hours, so my thought is to identify (and count) the number of occurrences when the data first rises by "> or = 1" over any 3 hour period. There is, at most, only one large spike per day, so
there can only be 0 to 7 spikes per week.

Data example:


05-Oct-2011 15:13:1521.1
05-Oct-2011 16:13:2721
05-Oct-2011 17:13:4121
05-Oct-2011 18:13:5420.8
05-Oct-2011 19:14:0621.6
05-Oct-2011 20:14:1922.6
05-Oct-2011 21:14:33
24.3
05-Oct-2011 22:14:4825.7

<tbody>
</tbody>


No spike is detected between 15:13:15 and 18:13:54 (a 3 hour period), but a large spike would be detected between 18:13:54 and 21:14:33 (with 24.3 – 20.8 = 3.5 which is >1). There are smaller spikes which I am not interested in, which never increase by 1 over 3 hours.

It would be ideal if the number of spikes for each week could be tabulated at the top of the Worksheet (eg starting at cell D1).

I have tried a moving average over 24 and 12 hour periods, but a spike is not readily distinguished this way and copying the formula down, at irregular row-intervals, is too time-consuming. A 6-hour moving average may work, since most spikes rise for between 5 to 7 hours, but is, again, too time consuming to copy down for each dataset.

Is there an array formula (eg Countifs) or <acronym title="visual basic for applications">VBA</acronym> code that could distinguish and possibly tabulate the number of large spikes for each week, given the data supplied?

I hope I have included enough information – let me know if not. Any help would be very much appreciated. My research is on real-time energy use in households. Regards, UseLessFuel
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
As an update to above question, I have found a simple, but clunky method to determine and count the spikes by using IF(AND(.... and COUNTIF(... functions.

To identify the spike in the above Table as the entry at 21:14:33 which is in cell B118, I used the following combined functions:

=IF(AND(B116>B115,B117>B116,B118>B117,(B118-B115)>1,C117<>1,C116<>1,C115<>1,C114<>1,C113<>1,C112<>1),1,"No SPIKE")

The formula requires that the previous three cells, before B118, that is cells B117, B116 and B115 were each higher in magnitude than the previous cell AND that cell B118 was at least 1 more than 3 hours (which is three cells) previously AND that no 1 appeared in the previous 6 cells. This works good, but will involve lots of Copying down and perhaps a COUNTIF(range"=1") at the top and maybe some tweeking.

If anyone can see a quicker way, using VBA or macro, I'd be delighted to know.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top