How To Find Frequency Of A Signal
What you're looking for is known as the Fourier Transform
A bit of background
Let'due south kickoff with the formal definition:
The Fourier transform (FT) decomposes a function (often a function of time, or a signal) into its constituent frequencies
This is in essence a mathematical performance that when applied over a point, gives you an idea of how nowadays each frequency is in the time serial. In order to get some intuition behind this, information technology might be helpful to look at the mathematical definition of the DFT:
Where 1000
here is swept all the way up t Northward-1
to calculate all the DFT
coefficients.
The first affair to notice is that, this definition resembles somewhat that of the correlation of two functions, in this case x(n)
and the negative exponential function. While this may seem a little bit abstruse, by using Euler's formula and by playing a fleck effectually with the definition, the DFT can be expressed as the correlation with both a sine wave and a cosine moving ridge, which will account for the imaginary and the existent parts of the DFT
.
So keeping in mind that this is in essence computing a correlation, whenever a corresponding sine or cosine from the decomposition of the circuitous exponential matches with that of x(due north)
, there will be a tiptop in Ten(One thousand)
, pregnant that, such frequency is present in the indicate.
How can nosotros practise the same with numpy?
And so having given a very cursory theoretical background, let's consider an example to see how this tin can be implemented in python. Lets consider the following signal:
Fs = 150.0; # sampling rate Ts = i.0/Fs; # sampling interval t = np.arange(0,one,Ts) # fourth dimension vector ff = fifty; # frequency of the bespeak y = np.sin(two*np.pi*ff*t) plt.plot(t, y) plt.xlabel('Time') plt.ylabel('Aamplitude')
Now, the DFT can be computed past using np.fft.fft
, which as mentioned, will be telling y'all which is the contribution of each frequency in the signal at present in the transformed domain:
due north = len(y) # length of the betoken one thousand = np.arange(n) T = north/Fs frq = 1000/T # ii sides frequency range frq = frq[:len(frq)//2] # one side frequency range Y = np.fft.fft(y)/n # dft and normalization Y = Y[:n//2]
Now, if we plot the actual spectrum, yous will see that nosotros become a peak at the frequency of 50Hz, which in mathematical terms it will be a delta part centred in the fundamental frequency of 50Hz. This can be checked in the post-obit Table of Fourier Transform Pairs table.
So for the in a higher place indicate, nosotros would get:
plt.plot(frq,abs(Y)) # plotting the spectrum plt.xlabel('Freq (Hz)') plt.ylabel('|Y(freq)|')
Source: https://stackoverflow.com/questions/55283610/how-do-i-get-the-frequencies-from-a-signal
Posted by: ashfordtered1955.blogspot.com
0 Response to "How To Find Frequency Of A Signal"
Post a Comment