From 81a896836a47f3a5f4e12cd353215429f45bebd5 Mon Sep 17 00:00:00 2001 From: MigAP Date: Wed, 25 Nov 2020 11:56:22 +0100 Subject: [PATCH] first functional FFT analysis of the data --- module3/exo3/exercice_python_fr.org | 113 +++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 3 deletions(-) diff --git a/module3/exo3/exercice_python_fr.org b/module3/exo3/exercice_python_fr.org index 4ff1861..9847c91 100644 --- a/module3/exo3/exercice_python_fr.org +++ b/module3/exo3/exercice_python_fr.org @@ -145,18 +145,22 @@ On possède des données toutes les semaines. # Conversion of the data to numpy array co2 = np.array(concentration) + + #Remove mean value + co2 = co2 - np.mean(co2) # Concentration FFT concentrationFFT = np.fft.fft(co2) # We take the norm of the FFT - concentrationFFTNorm = np.absolute(concentrationFFT) + concentrationFFTNorm = np.absolute(concentrationFFT) + concentrationFFTAngle = np.angle(concentrationFFT) # Frequency axis N = co2.shape[0] # Number of samples Te = 1 # Sampling interval t = np.arange(N) # time reference - freq = np.arange(N)/(N*Te) - #freq = np.fft.fftfreq(N) + #freq = np.arange(N)/(N*Te) + freq = np.fft.fftfreq(N)*N*(1/N*Te) plt.figure(figsize=(10,5)) @@ -169,3 +173,106 @@ On possède des données toutes les semaines. #+RESULTS: [[file:dataFFT.png]] + +** FFT zoom + +On effectue un zoom sur la partie positive du graphique pour tenter de +caractériser les différérentes fréquences d'oscillations du signal. + +#+begin_src python :results file :session :var matplot_lib_filename="fftZoom.png" :exports both + startIndx = 10 + fftzoomIndx = int(N/6) + + plt.figure(figsize=(10,5)) + plt.plot(freq[startIndx:fftzoomIndx],concentrationFFTNorm[startIndx:fftzoomIndx]) + plt.tight_layout() + + plt.savefig(matplot_lib_filename) + matplot_lib_filename +#+end_src + +#+RESULTS: +[[file:fftZoom.png]] + +On remarque que les "petites" oscillations ont une amplitude +d'environ 1400. On tentera de filtrer donc le signal au dessus de ce +seuil. +** Filtrage des grandes oscillations + +On élimine toutes les valeurs au dessus du seuil établit précédemment. + +#+begin_src python :results file :session :var matplot_lib_filename="smallOsillations.png" :exports both + # Extraction of the small oscillations + smallAmplitude = 1400 + smallNorm = np.copy(concentrationFFTNorm) + smallNorm[smallNorm > smallAmplitude] = 0 + + plt.figure(figsize=(10,5)) + plt.plot(freq,smallNorm) + #plt.plot(freq[startIndx:fftzoomIndx],small[startIndx:fftzoomIndx]) + plt.tight_layout() + + plt.savefig(matplot_lib_filename) + matplot_lib_filename +#+end_src + +#+RESULTS: +[[file:smallOsillations.png]] + +** Reconstruction du signal : petites oscillations + +#+begin_src python :results file :session :var matplot_lib_filename="smallOsillationsTime.png" :exports both + smallFreqSignal = smallNorm*np.exp(1j*concentrationFFTAngle) + smallSignal = np.fft.ifft(smallFreqSignal) + smallSignal = np.real(smallSignal) + + plt.figure(figsize=(10,5)) + plt.plot(t,smallSignal) + plt.tight_layout() + + plt.savefig(matplot_lib_filename) + matplot_lib_filename +#+end_src + +#+RESULTS: +[[file:smallOsillationsTime.png]] + +** Filtrage des petites oscillations + +On élimine toutes les valeurs au dessus du seuil établit précédemment. + +#+begin_src python :results file :session :var matplot_lib_filename="bigOsillations.png" :exports both + # Extraction of the big oscillations + bigAmplitude = 1400 + bigNorm = np.copy(concentrationFFTNorm) + bigNorm[bigNorm < bigAmplitude] = 0 + + plt.figure(figsize=(10,5)) + plt.plot(freq,bigNorm) + #plt.plot(freq[startIndx:fftzoomIndx],big[startIndx:fftzoomIndx]) + plt.tight_layout() + + plt.savefig(matplot_lib_filename) + matplot_lib_filename +#+end_src + +#+RESULTS: +[[file:bigOsillations.png]] + +** Reconstruction du signal : grandes oscillations + +#+begin_src python :results file :session :var matplot_lib_filename="bigOsillationsTime.png" :exports both + bigFreqSignal = bigNorm*np.exp(1j*concentrationFFTAngle) + bigSignal = np.fft.ifft(bigFreqSignal) + bigSignal = np.real(bigSignal) + + plt.figure(figsize=(10,5)) + plt.plot(t,bigSignal) + plt.tight_layout() + + plt.savefig(matplot_lib_filename) + matplot_lib_filename +#+end_src + +#+RESULTS: +[[file:bigOsillationsTime.png]] -- 2.18.1