I'm trying to calculate the frequency of the following signal that has an offset: Signal

So I first try to center it around 0 :

m = max(signal);
mi = min(signal);
n = signal - (mi + (m-mi)/2);


However as the signal fades over time, it eventually falls below 0 towards the end, resulting in a large maxima at 0 on the Fourier transform.

Although the second largest maxima does give me the correct frequency, Is there a better way to center the signal so that it doesn't fall below zero?

  • $\begingroup$ Do you know if the drift is linear? $\endgroup$ – A_A Mar 1 at 16:21
  • $\begingroup$ I think I can assume it is. I know the signal strength is always decreasing, however with a different amount each time. $\endgroup$ – Tejas Kale Mar 1 at 16:24

To calculate the frequency you don't need to worry about the offset. To get rid of the offset and get a "clean" damped sine wave you can calculate the amplitude of the first and final peaks and calculate the an offset line. Then just subtract this line to your initial signal.

  • $\begingroup$ I ended up doing something similar. Subtracting a moving average with a window size of approximately 1f seems to work well. $\endgroup$ – Tejas Kale Mar 1 at 19:32

It is a common pre-processing step in harmonic analysis to remove long term trends prior to assessing the periodic part.

This is known as detrending and there are lots of methods to detrend a time series, depending on its characteristics.

But if you know that the trend is linear then the task is straightforward. All that you have to do is "fit a line" through your data, invert it and then remove its effect.

While you can do this simply by fitting a first degree polynomial (for example), there are also functions in platforms like MATLAB or Python (and others) that will handle the complete detrending process and return to you the detrended waveform.

Hope this helps.

  • $\begingroup$ Thanks, pointed me in the correct direction. $\endgroup$ – Tejas Kale Mar 1 at 19:30

You already have some answers. Here is a quick thought about the frequency:

  • Use the autocorrelation of the signal and see where there is the first minimum and the first maximum after the minimum. From this shift you get an estimate for the frequency.

  • Use a simple peak-detection algorithm (eg by a sliding window of a size $N$ where you fit a parabola to the $N$ points. Detecting the apex from the coefficient of the squared term should be easy.

  • Use an empirically determined model and non-linear least-squares fit it to your signal.


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.