2

Apologies if the term regularity is improper, I cannot find what the actual term I am looking for is.

I'm looking for a method for calculating how "regular" rhythms are for musical notes.

Although, more generally, I'm looking for a method for calculating how "regular" the gaps are between numerical values.

I have data in the form of an array, which contains the milisecond occurences of the notes, i.e.

[1000, 2000, 3000, 4000, 4500, 5000]

I have tried (unsuccessfully) methods such as getting the difference in time between a note and the next note, then calculating the standard deviation of that data.

However, this produces nonsense answers, especially in cases where there are breaks, for example.

[1000, 10000, 11000, 12000] // 2178.013025842761
[1000, 1333, 1500, 1666, 2000] // 73.030815413769

So this is definitely not the way about it.

In the top example, all of the deltas share common multiples. However, in the bottom example, significantly less do.

I'm asking as I'm wondering if there is some statistical term for the measurement I am looking for, and also if there are any solutions to this problem (perhaps involving common multiples).

I do not have a very advanced background in statistics, and what I'm asking for could be completely incoherent. Apologies, and thanks in advance.

zkldi
  • 21
  • 2
  • 1
    Could you please explain your data a little more. In both your example the data seems to be non-stationary. Also by regularity, if you mean if there is a pattern of recurrence of a particular numerical value of your series then autocorrelation and/or spectrum analysis may be what you are looking for. – Dayne Jul 04 '20 at 11:43
  • Hi, My data is the amount of miliseconds elapsed since the start of the song, with that timestamp being when the note occurs. I do think a pattern of recurrence is what i'm looking for, or rather how much something the data could be described as patternical. The data itself is only the miliseconds of a note occuring since the start of the song, there is no audio files involved (i already have that parsed). – zkldi Jul 04 '20 at 19:54
  • 1
    Okay. So are we looking at data of one particular note in a song or any note? Sorry if my question does not make sense, I have no knowledge of music. – Dayne Jul 05 '20 at 03:08
  • the pitches or sounds of the notes are completely ignored, infact the fact that it's music can be ignored too kinda; a note is played at x miliseconds, and i'm looking for how regularly dispersed those values are musically. this data is all for the same song. – zkldi Jul 05 '20 at 03:22

2 Answers2

1

You can compute the differences of time between all your notes, then your problem is to see whether your data is very spread out or not while ignoring the very big time intervals (outliers) caused by pauses. Then, what you want is to compute a robust estimator of spread and for example, to do that, an easy way is to use a trimmed standard deviation : you take out the extremal 5% (or more) of the data (that will correspond to the pauses) and then you compute the standard deviation of the rest. This way you threshold your data but in an adaptive manner.

EDIT : you can also look toward the discrepency of a sequence, see also low discrepancy sequence, this is a completely deterministic measure of regularity and maybe this is more adequate for what you want.

TMat
  • 716
  • 1
  • 10
  • Hi, This doesn't really resolve any other issues with using standard deviation to describe the "regularity" of the set. Correlations in the data are still missed (such as [1000, 1250, 2000] vs [1000, 1333, 2000]) – zkldi Jul 04 '20 at 19:56
  • I don't understand what you mean, the regularity is taken into account no ? the correlation is computed because we do the standard deviation of the differences, in your example we have standard deviation of [250,750] vs standard deviation of [333,777] and we have that the second is more "regular" than the first. – TMat Jul 05 '20 at 08:19
  • 1
    +1 for the edit in the answer. I found this quite interesting. But still may not solve the problem of breaks. – Dayne Jul 07 '20 at 04:53
  • For the problem of breaks you have to take it out one way or the other. For example you could use a moving average and detect by detecting when the average is larger than a certain threshold but you can't expect a measure of regularity to consider that the breaks are regular. – TMat Jul 07 '20 at 08:30
  • Thank you, the links about discrepency of a sequence seem to be what I'm looking for. – zkldi Jul 09 '20 at 08:56
1

To be frank I am still not very clear about your data but here are some points that you may find helpful:

Your data is a time series, call it $X_t$.

  1. First identify the random variable(s) of interest. Your question seems to suggest that the time lapse between notes has some randomness and you probably want get some sense of measure of the spread of this/these random variable(s).

  2. So the variable of interest is $\Delta X_t := X_t-X_{t-1}$. At this point, knowing your data you should think whether you from theory expect $\Delta X_t$ to be independent and identically distributed random variables, or distinct RVs correlated to each other in some way. For example, you may be expecting a pattern that after every 4 time lapses the fifth time lapse should be more or less same as the first one or uou may not expecting a pattern at all and expect that each of the time interval should be more or less same (i.e. independent).

  3. Strictly speaking you can skip the above step and simple model the time series, $Z_t=\Delta X_t$. For example ARIMA modeling or spectrum estimation. But step 2 can help you save time.

Measuring regularity: If $Z_t$ is indeed i.i.d., then sd is a good measure. Smaller the sd, more closer (amd thus regular) are the time elapses between notes.

If not, then the autocovariance function plots or the periodogram may be more insightful for checking regularity.

Hope this helps. If not better to paste the plot of $Z_t$ here for our understanding.

Dayne
  • 2,113
  • 1
  • 7
  • 24