


Measure frequency of values in statplus how to#
Common interpolation methods to find a more precise frequency estimate are 3-point parabolic and Sinc convolution (which is nearly the same as using a zero-padded longer FFT).Īssuming you use a discrete Fourier transform to look at frequencies, then you have to be careful about how to interpret the normalized frequencies back into physical ones (i.e. So you may have to interpolate to better estimate the frequency peak. Note that unless the wavelength of the data is an exact integer submultiple of the FFT length, the actual peak will be between bins, thus distributing energy among multiple nearby FFT result bins. Make sure to work out your proper units within the above equation (to get units of cycles per second, per fortnight, per kiloparsec, etc.) Frequency_of_Peak = Data_Sample_Rate * Bin_number_of_Peak / Length_of_FFT If the FFT result bin numbers start at 0 (zero), then the frequency of the sinusoidal component represented by the bin in the bottom half of the FFT result is most likely. Those two peaks both represent the same spectral peak and same frequency (for strictly real data).
Measure frequency of values in statplus plus#
If you are looking at the magnitude results from an FFT of the type most common used, then a strong sinusoidal frequency component of real data will show up in two places, once in the bottom half, plus its complex conjugate mirror image in the top half. Now the frequency is located at the largest peak. # now create the frequency axis: it runs from 0 to the sampling rate /2įreq_fftx = np.linspace(0,2/dt,len(fftx)) # now discard anything that we do not need. X = x - mean(x) # make sure the average is zero, so we don't get a huge DC offset.įftx = np.fft.fft(x) # the frequency transformed part X = np.random.rand(100) # create 100 random numbers of which we want the fourier transform In code: (I've written it in python, but it should be equally simple in c#): import numpy as np (Beware that this offset is usually much more than 0, so the other frequency components might get dwarved by it.) Furthermore, the first element in the array is a dc-offset, so the frequency is 0. It is located after the positive frequency part. So, to get to a frequency, can discard the negative frequency part. Then you'll get two peaks, one at a frequency corresponding to f, and one at a frequency corresponding to -f. If you have a signal with one frequency (for instance: y = sin(2 pi f t) To find the frequency, you just take f=1/T. You can actually be a little more clever in which peak you pick, but for most purposes this should be enough. This is the strongest periodicity of the waveform. This is effectively taking the autocorrelation.įind the largest peak in the iFFT. Replace all coefficients of the FFT with their square value (real^2+imag^2). If the FFT size is only the size of the window, you will effectively be taking the circular autocorrelation, which is not what you want. Take the FFT (however, make sure the FFT size is twice as big as the window, with the second half being padded with zeroes. 3 times as large will give better results). The window should be at least twice as large as the largest period you want to detect.

Window the signal, using a smooth window (a cosine will do. There's a lot of cool math behind it, look it up if you are interested, but if you just want it to work, just do this: So if you find a peak in the autocorrelation, that would indicate that the signal matches up well with itself when shifted over that amount. This will essentially give you a measure of how self-similar the signal is to itself after being shifted over by a certain amount. So most likely what you want is the autocorrelation. That is, the interval at which the signal becomes most like itself. What you are probably more interested in is the periodicity of the signal. However, the FFT of this signal will detect the magnitude of 0 for the frequency 5. For example, if you sum sin(2*pi*10x)+sin(2*pi*15x)+sin(2*pi*20x)+sin(2*pi*25x), you probably want to detect the "frequency" as 5 (take a look at the graph of this function). When you talk about computing the frequency of a signal, you probably aren't so interested in the component sine waves.
