I am running some tests where I am recording accelerometer measurements. I am looking to use elements of signal processing on this signal, but I am unsure about where to begin, or what my approach should be.

My ultimate goal is to be able to monitor the acceleration readings in real-time, and then display a notification when the event occurs. As you can see around the 150,000 sample time, an event occurs.

  • If I am monitoring this data in real time, what sort of signal processing techniques could be implemented to react to this event?
  • Would a Short-Time Fourier Transform (STFT) be an option?

I am monitoring my data in Python, and they have a decent STFT function.

The arguments of this function are as follows:

scipy.signal.stft(x, fs=1.0, window='hann', nperseg=256, noverlap=None, nfft=None, 
detrend=False, return_onesided=True, boundary='zeros', padded=True, axis=-1)
  • How do I determine optimal parameters to use to process this signal?

  • Are there any other methods that you folks think may help me in identifying when the event occurs in real-time (as opposed to just using the magnitude of the acceleration)?

https://dsp.stackexchange.com/users enter image description here


My STFT has been added above.


2 Answers 2


I'm wondering why the STFT pops out. To me, wouldn't a simple threshold on the signal itself or on its envelope do better / just as well, after removal of the g offset?

Once you decide what "measure" is best to detect your event, you can apply the work of Basseville and Nikiforov, that I answered here.

The classic reference for that problem is Detection of Abrupt Changes - Theory and Application by Basseville and Nikiforov. The whole book is available as a PDF download.

My recommendation is that you read Chapter 2.2 on the CUSUM (cumulative sum) algorithm.

  • $\begingroup$ Thanks for your comment! I added a photo of the STFT output above. Now, I simply ran the STFT function without much thought to the function parameters. My acceleration is being collected at a sampling frequency of 500 Hz. Can I use that to assist in my methods? $\endgroup$
    – Gary
    Jul 24, 2017 at 15:40
  • 2
    $\begingroup$ @Gary Thanks for adding the plot. I'm looking at the high frequency additions that appear, but I still think the increase in amplitude appears easier to catch --- provided it captures all the versions of you event that you want to detect. See Fat32's answer for an example of what I'm talking about. $\endgroup$
    – Peter K.
    Jul 24, 2017 at 15:46
  • $\begingroup$ Hey Peter, how do you interpret the STFT plot, and put it into layman's terms. My frequency is on the y-axis and time is on the x-axis. So, what can I say about the frequency what is occurring at the 2.0 time-mark? $\endgroup$
    – Gary
    Jul 24, 2017 at 20:08
  • $\begingroup$ @Gary : There are two things for me: a) the appearance of harmonic content (subharmonics to the main peak before that time) and b) some widespread, non-harmonic high frequency noise. I'd look at trying to filter out that high frequency content and use it to see if it helped identifying your event. $\endgroup$
    – Peter K.
    Jul 24, 2017 at 20:13
  • $\begingroup$ The STFT occurs to you because it lets you develop a CFAR receiver when the background has steady state tones $\endgroup$
    – user28715
    Jul 25, 2017 at 2:31

If this graphics represents the most typical application scenario, then I would go for some simple short window variance estimation and perform thresholding afterwards;

$$ \sigma_x^2 = \frac{1}{N} \sum_{n=0}^{N-1} x_{ac}[n]^2$$

Where $x_{ac}[n]$ is the DC removed input signal; i.e., $x_{ac}[n] = x[n] - \bar{x}[n]$ where $\bar{x}[n]$ is the DC (mean) value of the input $x[n]$ which can locally be estimated by $$\bar{x}[n] = \frac{1}{N} \sum_{n=0}^{N-1} x[n]$$ You could also use a DC blocking notch filter to eliminate any DC build up instead of estimating it.

Select a small enough window size $N$ appropriate for your application. You can perform the decision of the event based on a comparison of the standard deviation (square root of this computed variance estimate) to a properly selected threshold.

This will easily be computed in real-time with much less computational burden compared to a frequency domain analysis. Note that in real time application your summation indices should go backwards from the current sample (instead of the above fomulas which use a noncausal summation)

As a second efficient alternative, you could also implement a time domain envelope detection (followed by thresholding) to trigger the event.

  • $\begingroup$ “short window variance” is correct, i.e. $x[n]$ in your formula should actually mean $x[n] - \overline{x}$. Or, more or less equivalently, the signal could be high-pass filtered before further processing. $\endgroup$ Jul 24, 2017 at 21:52
  • $\begingroup$ @leftaroundabout What is the best method of determining the cutoff frequency to build my HPF for? $\endgroup$
    – Gary
    Jul 25, 2017 at 13:54
  • $\begingroup$ @leftaroundabout the paragraph below the formula actually states that but I think it's lost in the verbose. So it seems I have to make it clear. $\endgroup$
    – Fat32
    Jul 25, 2017 at 13:57
  • $\begingroup$ @Gary what HPF is that? where will you use it? $\endgroup$
    – Fat32
    Jul 25, 2017 at 14:19
  • $\begingroup$ @Fat32 Sorry, I just read through your edited comment. I like your suggestion for time domain envelope detection. I will investigate this option. $\endgroup$
    – Gary
    Jul 25, 2017 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.