import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
import numpy as np
from scipy.optimize import curve_fit
from matplotlib import pyplot
from scipy import signal
%matplotlib inline
data=np.genfromtxt('data/NewFile2.CSV',delimiter=",",skip_header=2) #Hier der Pfad zu Euren Daten eintragen
print(data)
t=data[:,0:1] #Zeit
Int=data[:,1:2] #Intensitaet
print(t)
print(np.shape(t))
print(Int)
Int=Int[:, 0] #in 1D-array wandeln
t=t[:, 0]
print(np.shape(Int))
print(np.shape(t))
plt.figure(figsize=(8,6))
plt.plot(t,Int, color='red', linewidth=1)
plt.xlabel('Zeit / '+'s')
plt.ylabel('Intensitaet / '+' b.E.')
plt.title('Interferogramm einer LED')
plt.axis([-0.05, 0.11, -0.42, 0.42])
peakind = signal.find_peaks_cwt(Int, np.arange(1,30),noise_perc=20)
plt.plot(t[peakind], Int[peakind],marker='o',linewidth=0)
plt.plot(t,Int, color='red', linewidth=1)
plt.xlabel('Zeit / '+'s')
plt.ylabel('Intensitaet / '+' b.E.')
plt.title('Interferogramm einer LED')
plt.axis([-0.02, 0.08, -0.42, 0.42])
#Fitfunktion Gauss
def fitFunc(t, a, mu, sig):
return a/np.sqrt(2*np.pi)/sig*np.exp(-(t-mu)**2/(2*sig**2))
init_vals = [0.002, 0.032, 0.015]
fitParams, fitCovariances = curve_fit(fitFunc, t[peakind], Int[peakind],p0=init_vals)
x=np.linspace(0,0.065,100) #x-Werte fuer die Fitfunktion
plt.plot(x, fitFunc(x, fitParams[0], fitParams[1], fitParams[2]))
plt.plot(t[peakind], Int[peakind],marker='*', linewidth=0)
plt.xlabel('Zeit / '+'s')
plt.ylabel('Intensitaet / '+' b.E.')
plt.title('Interferogramm einer LED (Gaußfit)')
plt.axis([-0.05, 0.11, 0, 0.42])
print("Sigmabreite=",fitParams[2],"s")
print("Halbwertsbreite=",2.355*fitParams[2],"s")
#Fitfunktion Lorentz
def lorentz(t, a, gamma, omega):
return a/(2*np.pi)*gamma/((t-omega)**2+gamma**2/4)
init_vals = [0.002, 0.02, 0.035]
fitParamsLorentz, fitCovariances = curve_fit(lorentz, t[peakind], Int[peakind],p0=init_vals)
x=np.linspace(-0.04,0.1,100) #x-Werte fuer die Fitfunktion
plt.plot(x, lorentz(x, fitParamsLorentz[0], fitParamsLorentz[1], fitParamsLorentz[2]))
plt.plot(t[peakind], Int[peakind],marker='*', linewidth=0)
plt.xlabel('Zeit / '+'s')
plt.ylabel('Intensitaet / '+' b.E.')
plt.title('Interferogramm einer LED (Lorentzfit)')
plt.axis([-0.05, 0.11, 0, 0.42])
print("Halbwertsbreite=",fitParamsLorentz[1],"s")
x=np.linspace(-0.04,0.1,100) #x-Werte fuer die Fitfunktion
plt.plot(x, lorentz(x, fitParamsLorentz[0], fitParamsLorentz[1], fitParamsLorentz[2]),label="Lorentz")
plt.plot(x, fitFunc(x, fitParams[0], fitParams[1], fitParams[2]),label="Gauß")
plt.legend()
plt.plot(t[peakind], Int[peakind],marker='*', linewidth=0)
plt.xlabel('Zeit / '+'s')
plt.ylabel('Intensitaet / '+' b.E.')
plt.title('Interferogramm einer LED (Vergleich Gauß- Lorentzfit)')
plt.axis([-0.05, 0.11, 0, 0.42])