Plot the Fourier transform of for frequency below 50 Hz.
using the fft function of the module numpy.fft.
The power spectral density (PSD) is defined as the square of the modulus of the Fourier transform of a signal divided by the integration time. It is defined only for positive frequencies.
Write a function in Python that calculates the PSD for a given signal (numpy array). This function will return two arrays : the frequencies and the corresponding PSD.
- What is the unit of the PSD ?
- Which parameter should we add in order to get the correct freuqencies ?
- What is the minimal (non zero) and maximal frequency ?
In the given file, we have synthetized a 10 second sound (son/data.dat). It consists of a noise. After 3 seconds, there is a distinct sound during 4 seconds.
When the duration of the sample is not a multiple of the period of the signal we want to look at, the DFT will not give a single peak. If the amplitude of the signal is small compared to the noise or to another signal, it can be hidden.
In order to reduce this problem, we should use a window function (apodization). It will concentrate the energy onto the central frequency.
There are different kinds of window function (see http://en.wikipedia.org/wiki/Window_function for a complete description with comparison). We will use the Hamming window function. In python it can written as
def Hamming(N):
\"\"\" Hamming window
input : N, number of points
output : window
\"\"\"
#Valeurs des coefficients
a0 = 0.54
a1 = 0.46
n = arange(N)
w_Hamming = a0 - a1*cos(2*pi*n/(N-1))
return w_Hamming/sqrt(sum(w_Hamming**2)/N)