예제 #1
0
파일: Tests.py 프로젝트: lc316353/GP1
def test_fourier():

    tmin = 100.
    tmax = 500.
    tstep = 0.2
    freq = 0.123

    t = np.arange(tmin, tmax, tstep)
    y = np.cos(2. * np.pi * freq * t)

    figure()
    subplot(2, 1, 1)
    title('Daten')
    plot(t, y, '.')
    xlabel('$t$ / s')
    ylabel('amp')
    grid()

    subplot(2, 1, 2)
    title('Fourierspektrum')
    freq, amp = analyse.fourier(t, y)
    freq_fft, amp_fft = analyse.fourier_fft(t, y)
    plot(freq, amp, '.', color='blue', label="Fourier")
    amp_fft = np.max(amp) / np.max(amp_fft) * amp_fft
    plot(freq_fft, amp_fft, '.', color='red', label="FFT")
    xlabel('$f$ / Hz')
    ylabel('amp')
    grid()
    legend()

    fpeak = analyse.peakfinder_schwerpunkt(freq, amp)
    fpeak_fft = analyse.peakfinder_schwerpunkt(freq_fft, amp_fft)
    axvline(fpeak, color='blue')
    axvline(fpeak_fft, color='red')
    xlim(0., np.max(freq))
    ylim(0., max(np.max(amp), np.max(amp_fft)) * 1.1)

    show()
예제 #2
0
def fft_analysis(groesse, hoehe, nummer):
    #Daten mit Korrektur
    dataname = groesse + '_' + hoehe + '_' + nummer

    data = cassy.CassyDaten('daten/' + dataname + '.lab')
    time = data.messung(1).datenreihe('t').werte
    pres = data.messung(1).datenreihe('p_A1').werte

    #Signale abschneiden
    time, pres = analyse.untermenge_daten(time, pres, 0, tgrenz[dataname])

    fourier = analyse.fourier_fft(time, pres)
    freq = fourier[0]
    amp = fourier[1]
    peak = analyse.peakfinder_schwerpunkt(freq[3:100], amp[3:100])
    delta = korrektur(time, pres)
    return (2 * np.pi * peak, delta)
예제 #3
0
    subplot(2, 1, 2)
    plot(t, U2)
    ylabel('$U$ / V')
    xlabel('t/s')
    xlim(0, 0.04)
    title('zweiter Schwingkreis')
    grid()

    subplots_adjust(hspace=0.5)
    savefig('Images/Rohdaten_' + n[0] + 'sinnig.pdf')
    plt.figure()

    #FFT + Plot
    w1_array, A1 = analyse.fourier_fft(t, U1)
    w1 = analyse.peakfinder_schwerpunkt(w1_array, A1)  #Hauptfrequenz1
    print("Frequenz 1 aus fft: ", w1)

    plt.plot(w1_array, A1 / max(A1))
    plt.axvline(x=w1, color="darkred", linestyle="--")
    plt.text(w1, 0.5, 'Max: {} Hz'.format(round(w1, 3)))
    plt.title('FFT Schwingung 1')
    plt.xlim(0, 4000)
    plt.xlabel('Frequenz / Hz')
    plt.ylabel('rel. Häufigkeiten')
    plt.savefig(n[0] + 'sinnig_FFT1')
    plt.figure()

    w2_array, A2 = analyse.fourier_fft(t, U2)
    w2 = analyse.peakfinder_schwerpunkt(w2_array, A2)  #Hauptfrequenz2
    print("Frequenz 2 aus fft: ", w2)
예제 #4
0
subplot(2, 1, 1)
plot(timeValues, voltage)
grid()
xlabel('Zeit / s')
ylabel('Spannung / V')
einhuellende = analyse.exp_einhuellende(timeValues, voltage, voltageError)
plot(timeValues, +einhuellende[0] * exp(-einhuellende[2] * timeValues))
plot(timeValues, -einhuellende[0] * exp(-einhuellende[2] * timeValues))

subplot(2, 1, 2)
fourier = analyse.fourier_fft(timeValues, voltage)
frequency = fourier[0]
amplitude = fourier[1]
plot(frequency, amplitude)
grid()
xlabel('Frequenz / Hz')
ylabel('Amplitude')

maximumIndex = amplitude.argmax()
xlim(frequency[max(0, maximumIndex - 10)],
     frequency[min(maximumIndex + 10, len(frequency))])
peak = analyse.peakfinder_schwerpunkt(frequency, amplitude)
axvline(peak)

L = 0.667
g = ((2 * np.pi * peak)**2) * L

print('g = %f m/s^2' % g)

show()
예제 #5
0
    i = 0
    while i < len(ind) - 1:
        dis = dis + v[ind[i + 1]] - v[ind[i]]
        i = i + 1

    dis = dis / (len(ind) - 1)
    return dis


data = cassy.CassyDaten('Gleichsinnig/gleich.koppl.eisen.lab')
U1 = data.messung(1).datenreihe('U_B1').werte
U2 = data.messung(1).datenreihe('U_B2').werte
t = data.messung(1).datenreihe('t').werte

w1, A1 = analyse.fourier_fft(t, U1)
w1 = analyse.peakfinder_schwerpunkt(w1, A1)
print("Frequenz 1 aus fft: ", w1)

w2, A2 = analyse.fourier_fft(t, U2)
w2 = analyse.peakfinder_schwerpunkt(w2, A2)
print("Frequenz 2 aus fft: ", w2)

w_mean = (w1 + w2) / 2
w_std = np.sqrt((w1 - w_mean)**2 + (w2 - w_mean)**2)
print("mittlere Frequenz aus fft", w_mean, "+-", w_std)

fig = figure()

subplot(2, 1, 1)
plot(t, U1)
ylabel('$U$ / V')
예제 #6
0
fourier3 = analyse.fourier_fft(time3, volt3)

fre1 = fourier1[0]
amp1 = fourier1[1]
fre2 = fourier2[0]
amp2 = fourier2[1]
fre3 = fourier3[0]
amp3 = fourier3[1]

# Neagtive Frequenzen wegschneiden
fre1, amp1 = analyse.untermenge_daten(fre1, amp1, 0, 5000)
fre2, amp2 = analyse.untermenge_daten(fre2, amp2, 0, 5000)
fre3, amp3 = analyse.untermenge_daten(fre3, amp3, 0, 5000)

# Peaks
peak1 = analyse.peakfinder_schwerpunkt(fre1, amp1)
peak2 = analyse.peakfinder_schwerpunkt(fre2, amp2)
peak3 = analyse.peakfinder_schwerpunkt(fre3, amp3)

f = [0, 5000]

# Plot
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, sharex=True, figsize=(12, 12))

ax2.set_ylabel('Amplitude')
ax3.set_xlabel('$f$ / Hz')

for i in range(75):
    if i % 2 == 0:
        ax1.axvline(x=peak1 * i, color='red', alpha=0.5, linestyle='dotted')
    else:
예제 #7
0
# Frequenzspektrum
data1 = cassy.CassyDaten('daten/fundamental_3.lab')
time1 = data1.messung(1).datenreihe('t').werte
vol1_1 = data1.messung(1).datenreihe('U_A1').werte
vol1_2 = data1.messung(1).datenreihe('U_A2').werte
fre1_1, amp1_1 = analyse.fourier_fft(time1, vol1_1)
fre1_2, amp1_2 = analyse.fourier_fft(time1, vol1_2)

data2 = cassy.CassyDaten('daten/fundamental_2.lab')
time2 = data2.messung(1).datenreihe('t').werte
vol2_1 = data2.messung(1).datenreihe('U_A1').werte
vol2_2 = data2.messung(1).datenreihe('U_A2').werte
fre2_1, amp2_1 = analyse.fourier_fft(time2, vol2_1)
fre2_2, amp2_2 = analyse.fourier_fft(time2, vol2_2)

peak1_1 = analyse.peakfinder_schwerpunkt(fre1_1[5:600], amp1_1[5:600])
peak1_2 = analyse.peakfinder_schwerpunkt(fre1_2[5:600], amp1_2[5:600])
peak2_1 = analyse.peakfinder_schwerpunkt(fre2_1[5:600], amp2_1[5:600])
peak2_2 = analyse.peakfinder_schwerpunkt(fre2_2[5:600], amp2_2[5:600])


fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2,2, sharex='col', sharey='row',figsize=(12,6))

ax1.plot(fre1_1[0:600], amp1_1[0:600])
ax1.set_ylabel('Amplitude')
ax1.axvline(x=peak1_1, color='black', linestyle='--')
ax1.axvline(x=peak2_1, color='gray', linestyle='--')
ax1.text(100,1000,s='peak ='+"{0:.2f}".format(peak1_1)+' Hz',fontsize='13')

ax2.plot(fre1_2[0:600], amp1_2[0:600])
ax2.axvline(x=peak1_2, color='black', linestyle='--')
예제 #8
0
## FFT mit Peakfinder


# Schwebung 1
data1 = cassy.CassyDaten('daten/schwebung_1.lab')
time1 = data1.messung(1).datenreihe('t').werte
volt1 = data1.messung(1).datenreihe('U_A1').werte

fourier1 = analyse.fourier_fft(time1,volt1)
fre1 = fourier1[0]
amp1 = fourier1[1]

fre1_1, amp1_1 = analyse.untermenge_daten(fre1, amp1, 142, 145)
fre1_2, amp1_2 = analyse.untermenge_daten(fre1, amp1, 145, 148)

fS1_1 = analyse.peakfinder_schwerpunkt(fre1_1, amp1_1)
fS1_2 = analyse.peakfinder_schwerpunkt(fre1_2, amp1_2)


# Schwebung 2
data2 = cassy.CassyDaten('daten/schwebung_2.2.lab')
time2 = data2.messung(1).datenreihe('t').werte
volt2 = data2.messung(1).datenreihe('U_A1').werte

fourier2 = analyse.fourier_fft(time2,volt2)
fre2 = fourier2[0]
amp2 = fourier2[1]

fre2_1, amp2_1 = analyse.untermenge_daten(fre2, amp2, 144, 145.5)
fre2_2, amp2_2 = analyse.untermenge_daten(fre2, amp2, 145.5, 147.5)
예제 #9
0
dic_fre = {1: np.array([57,67,70,78]), 2:np.array([64,68,68,72]), 3:np.array([20,29,40,49])}

freqs = np.array([])
amps = np.array([])

for i in range(1,4,1):
    data = cassy.CassyDaten('daten/schwebung_' + dic_file[i] + '_1.lab')
    time = data.messung(1).datenreihe('t').werte
    vol = data.messung(1).datenreihe('U_A1').werte
    vol2 = data.messung(1).datenreihe('U_A2').werte
    
    freq, amp = analyse.fourier_fft(time, vol)
    freq2, amp2 = analyse.fourier_fft(time, vol2)
    (freq, amp) = analyse.untermenge_daten(freq, amp, 0, 50000)
    (freq2, amp2) = analyse.untermenge_daten(freq2, amp2, 0, 50000)
    peak1 = analyse.peakfinder_schwerpunkt(freq[dic_fre[i][0]:dic_fre[i][1]], amp[dic_fre[i][0]:dic_fre[i][1]])
    peak2 = analyse.peakfinder_schwerpunkt(freq[dic_fre[i][2]:dic_fre[i][3]], amp[dic_fre[i][2]:dic_fre[i][3]])
    ymax1 = amp[dic_fre[i][0]:dic_fre[i][1]].argmax()
    ymax2 = amp[dic_fre[i][2]:dic_fre[i][3]].argmax()
    
    fplus = np.concatenate((fplus, np.array([peak1, np.abs(peak1-freq[dic_fre[i][0]+ymax1])])))
    fminus = np.concatenate((fminus, np.array([peak2, np.abs(peak2-freq[dic_fre[i][2]+ymax2])])))
    
    amps = np.concatenate((amps, amp))
    freqs = np.concatenate((freqs, freq))

''' 
# FFT der verschiedenen Konfigurationen  
plt.figure(figsize=(12,6))    
    
plt.plot(freqs[4002:6002], amps[4002:6002], color='green', label='Schwebung 3')