trying to do something right!
This commit is contained in:
parent
3d23539094
commit
1c4119a8a0
48
Piezokonstante_plot.py
Normal file
48
Piezokonstante_plot.py
Normal file
@ -0,0 +1,48 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
k_L = 2e-10
|
||||
|
||||
spannung_10 = np.array([412, 284, 360, 548, 280, 304, 380, 312, 278, 444]) / 1000 / 2
|
||||
spannung_20 = np.array([960, 960, 992, 968, 936, 952, 1160, 1200, 1010, 1000]) / 1000 / 2
|
||||
spannung_50 = np.array([1180, 2020, 1120, 1260, 1240, 1580, 1140, 2340, 1700, 1060]) / 1000 / 2
|
||||
spannung_100 = np.array([4080, 5280, 5160, 5080, 3520, 4280, 4800, 5120, 4400, 4240]) / 1000 / 2
|
||||
|
||||
ladung_10 = spannung_10 * k_L * 1e12 # Convert to pC
|
||||
ladung_20 = spannung_20 * k_L * 1e12
|
||||
ladung_50 = spannung_50 * k_L * 1e12
|
||||
ladung_100 = spannung_100 * k_L * 1e12
|
||||
|
||||
gewichte = [10, 20, 50, 100]
|
||||
ladungen = [ladung_10, ladung_20, ladung_50, ladung_100]
|
||||
|
||||
plt.figure(figsize=(10, 6))
|
||||
|
||||
for i, _ in enumerate(gewichte):
|
||||
plt.scatter(np.full_like(ladungen[i], gewichte[i]), ladungen[i], color='royalblue')
|
||||
|
||||
mittelwerte = [np.mean(ladung) for ladung in ladungen]
|
||||
plt.errorbar(gewichte, mittelwerte, yerr=np.std(ladungen, axis=1), fmt='o', color='fuchsia', label='Mittelwert ± Standardabweichung')
|
||||
|
||||
z = np.polyfit(gewichte, mittelwerte, 1) # Linear Regression
|
||||
p = np.poly1d(z)
|
||||
plt.plot(gewichte, p(gewichte), "r--", label='Bestgerade')
|
||||
|
||||
plt.xlabel('Gewicht m [g]')
|
||||
plt.ylabel('Ladung Q [pC]')
|
||||
plt.xticks(gewichte)
|
||||
plt.xlim(5, 105)
|
||||
plt.ylim(0, np.max(ladungen) * 1.1)
|
||||
|
||||
plt.legend(loc='upper left')
|
||||
plt.grid(True)
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
|
||||
#Mittelwerte
|
||||
for i, mittelwert in enumerate(mittelwerte):
|
||||
print(f"Mittelwert für Gewicht {gewichte[i]} g: {mittelwert:.2f} pC")
|
||||
|
||||
#Standardabweichung
|
||||
for i, std in enumerate(np.std(ladungen, axis=1)):
|
||||
print(f"Standardabweichung für Gewicht {gewichte[i]} g: {std:.2f} pC")
|
||||
@ -45,8 +45,8 @@ def analyze_paper_breakdown(lengths, voltages, ed_standard_values):
|
||||
|
||||
|
||||
|
||||
ax1.set_ylabel("Spannung [kV]")
|
||||
ax1.set_title("Durchschlageigenschaften in Abhängigkeit von Materialstärke")
|
||||
ax1.set_ylabel("Spannung U [kV]")
|
||||
#ax1.set_title("Durchschlageigenschaften in Abhängigkeit von Materialstärke")
|
||||
|
||||
handles1, labels1 = ax1.get_legend_handles_labels()
|
||||
by_label = dict(zip(labels1, handles1))
|
||||
@ -58,8 +58,8 @@ def analyze_paper_breakdown(lengths, voltages, ed_standard_values):
|
||||
for i, ed_standard in enumerate(ed_standard_values):
|
||||
ax2.plot(lengths, np.full_like(lengths, ed_standard), label=f"ED (Erwartung, {ed_standard} kV/mm)", linestyle='--', color=colors[i])
|
||||
|
||||
ax2.set_xlabel("Materialstärke [mm]")
|
||||
ax2.set_ylabel("Durchschlagsfeldstärke [kV/mm]")
|
||||
ax2.set_xlabel("Materialstärke l [mm]")
|
||||
ax2.set_ylabel("Durchschlagsfeldstärke E [kV/mm]")
|
||||
ax2.legend(loc='lower left')
|
||||
ax2.grid(True)
|
||||
|
||||
|
||||
@ -26,8 +26,7 @@ ax1.plot(x, u2, label="U..kV (3kV/mm)", marker='x', linestyle='--') # Unterschie
|
||||
ax1.fill_between(x, u1, u2, color='red', alpha=0.3, label="Abweichung")
|
||||
|
||||
# Beschriftungen und Titel für den ersten Subplot setzen
|
||||
ax1.set_ylabel("Spannung (kV)") # Deutlichere Beschriftung
|
||||
ax1.set_title("Spannung und Abweichung in Abhängigkeit des Luftspalts")
|
||||
ax1.set_ylabel("Spannung U [kV]") # Deutlichere Beschriftung
|
||||
ax1.legend()
|
||||
ax1.grid(True)
|
||||
|
||||
@ -35,8 +34,8 @@ ax1.grid(True)
|
||||
ax2.plot(x, ed_real, label="ED-Real", marker='o', color='green', linestyle='-')
|
||||
|
||||
# Beschriftungen für den zweiten Subplot setzen
|
||||
ax2.set_xlabel("Länge (mm)")
|
||||
ax2.set_ylabel("ED-Real (kV/mm)") # Korrekte Einheit hinzugefügt!
|
||||
ax2.set_xlabel("Länge l [mm]")
|
||||
ax2.set_ylabel("Feldstärke ED [kV/mm]") # Korrekte Einheit hinzugefügt!
|
||||
ax2.legend()
|
||||
ax2.grid(True)
|
||||
|
||||
|
||||
30
piezo konstante.py
Normal file
30
piezo konstante.py
Normal file
@ -0,0 +1,30 @@
|
||||
import numpy as np
|
||||
|
||||
|
||||
def umwandlung_ladung(spannung, k_L = 2e-10):
|
||||
return spannung * k_L
|
||||
|
||||
|
||||
def mittelwert(messerte):
|
||||
return np.sum(messerte) / len(messerte)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# immer durch zwei, weil gefalten, siehe Angabe
|
||||
spannung_10 = np.array([412, 284, 360, 548, 280, 304, 380, 312, 278, 444]) / 1000 / 2
|
||||
spannung_20 = np.array([960, 960, 992, 968, 936, 952, 1160, 120, 1010, 1000]) / 1000 / 2
|
||||
spannung_50 = np.array([1180, 2020, 1120, 1260, 1240, 1580, 1140, 2340, 1700, 1060]) / 1000 / 2
|
||||
spannung_100 = np.array([4080, 5280, 5160, 5080, 3520, 4280, 4800, 5120, 4400, 4240]) / 1000 / 2
|
||||
|
||||
ladnung_10 = umwandlung_ladung(spannung_10)
|
||||
ladnung_20 = umwandlung_ladung(spannung_20)
|
||||
ladnung_50 = umwandlung_ladung(spannung_50)
|
||||
ladnung_100 = umwandlung_ladung(spannung_100)
|
||||
|
||||
print()
|
||||
|
||||
print(ladnung_10(spannung_10))
|
||||
print(ladnung_20(ladnung_10))
|
||||
print(ladnung_50(ladnung_20))
|
||||
print(mittelwert(ladnung_50))
|
||||
print(mittelwert(ladnung_100))
|
||||
@ -11,22 +11,23 @@ data_100g = [4080, 5280, 5160, 5080, 3520, 4280, 4800, 5120, 4400, 4240]
|
||||
data = [data_10g, data_20g, data_50g, data_100g]
|
||||
labels = ['10g', '20g', '50g', '100g']
|
||||
means = [np.mean(d) for d in data]
|
||||
stds = [np.std(d) for d in data]
|
||||
|
||||
# Violin Plots
|
||||
# Violin Plots mit Standardabweichung
|
||||
plt.figure(figsize=(8, 6))
|
||||
ax = sns.violinplot(data=data, inner="box")
|
||||
|
||||
# X-Achsen-Ticks und Beschriftungen anpassen
|
||||
x_coords = ax.get_xticks() # X-Koordinaten der Ticks abrufen
|
||||
x_coords = ax.get_xticks()
|
||||
new_labels = []
|
||||
for i, label in enumerate(labels):
|
||||
new_labels.append(f"{label}\n⌀ {means[i]:.2f} mV") # Neue Beschriftungen mit Durchschnitt
|
||||
new_labels.append(f"{label}\n⌀ {means[i]:.2f} mV\nσ {stds[i]:.2f}")
|
||||
|
||||
ax.set_xticks(x_coords) # Ticks setzen
|
||||
ax.set_xticklabels(new_labels) # Neue Beschriftungen setzen
|
||||
ax.set_xlabel('Gewicht')
|
||||
ax.set_ylabel('Ergebnis [mV]')
|
||||
ax.set_title('Messwert Aufteilung der gemessenen Spannungen pro Gewicht')
|
||||
ax.set_xticks(x_coords)
|
||||
ax.set_xticklabels(new_labels)
|
||||
ax.set_xlabel('Gewicht m [g]')
|
||||
ax.set_ylabel('Spannung U [mV]')
|
||||
#ax.set_title('Messwert Aufteilung der gemessenen Spannungen pro Gewicht')
|
||||
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
173
plot Frequenzabhängige Kapazität.py
Normal file
173
plot Frequenzabhängige Kapazität.py
Normal file
@ -0,0 +1,173 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import math
|
||||
from matplotlib.ticker import ScalarFormatter
|
||||
|
||||
|
||||
def parse_file(filename):
|
||||
# Listen für die Daten
|
||||
frequencies = []
|
||||
capacitances = []
|
||||
resistances = []
|
||||
|
||||
# Datei Zeile für Zeile lesen
|
||||
with open(filename, 'r') as file:
|
||||
for line in file:
|
||||
if line.strip(): # Leere Zeilen überspringen
|
||||
parts = line.split()
|
||||
|
||||
if parts[7] == "INVALID":
|
||||
continue
|
||||
|
||||
# if float(parts[4]) < 0:
|
||||
# continue
|
||||
|
||||
# Frequenz und Konvertierung in Hz
|
||||
freq_value = float(parts[1])
|
||||
freq_unit = parts[2]
|
||||
if freq_unit == "kHz":
|
||||
freq_value *= 1e3
|
||||
elif freq_unit == "MHz":
|
||||
freq_value *= 1e6
|
||||
elif freq_unit == "Hz":
|
||||
freq_value *= 1
|
||||
else:
|
||||
print("Fehler freq")
|
||||
frequencies.append(freq_value)
|
||||
|
||||
# Kapazität und Konvertierung in Farad
|
||||
cap_value = float(parts[4])
|
||||
cap_unit = parts[5]
|
||||
if cap_unit == "pF":
|
||||
cap_value *= 1e-12
|
||||
elif cap_unit == "nF":
|
||||
cap_value *= 1e-9
|
||||
elif cap_unit == "uF":
|
||||
cap_value *= 1e-6
|
||||
# elif cap_unit == "F":
|
||||
# cap_unit *= 1
|
||||
else:
|
||||
print("Fehler freq")
|
||||
capacitances.append(cap_value) # Pikofarad zu Farad
|
||||
|
||||
# Widerstand und Konvertierung in Ohm
|
||||
res_value = float(parts[7])
|
||||
res_unit = parts[8]
|
||||
if res_unit == "kOHMS":
|
||||
res_value *= 1e3
|
||||
elif res_unit == "MOHMS":
|
||||
res_value *= 1e6
|
||||
elif res_unit == "mOHMS":
|
||||
res_value *= 1e-3
|
||||
elif res_unit == "OHMS":
|
||||
res_unit *= 1
|
||||
else:
|
||||
print("Fehler res", res_unit)
|
||||
resistances.append(res_value)
|
||||
|
||||
# Umwandlung in numpy-Arrays
|
||||
frequencies = np.array(frequencies)
|
||||
capacitances = np.array(capacitances)
|
||||
resistances = np.array(resistances)
|
||||
|
||||
return frequencies, capacitances, resistances
|
||||
|
||||
|
||||
def plot_data(frequencies, y_values):
|
||||
plt.figure(figsize=(10, 6))
|
||||
plt.plot(frequencies, y_values, label="Y-Werte (Platzhalter)", marker="o")
|
||||
plt.xscale("log") # Logarithmische Skalierung der x-Achse
|
||||
plt.xlabel("Frequenz (Hz)")
|
||||
plt.ylabel("Y-Werte")
|
||||
plt.title("Logarithmischer Plot der Frequenz")
|
||||
plt.grid(which="both", linestyle="--", linewidth=0.5)
|
||||
plt.legend()
|
||||
plt.show()
|
||||
|
||||
|
||||
def plot_Kapazität(capacitances_1, capacitances_2, capacitances_3, frequencies_1, frequencies_2, frequencies_3,
|
||||
filename):
|
||||
# Plot
|
||||
plt.figure(figsize=(10, 7.5))
|
||||
|
||||
# Mehrere Linien plotten
|
||||
# plt.plot(frequencies_1, capacitances_1, label='Keramikkondensator 1 nF', linestyle='-', color='blue')
|
||||
plt.plot(frequencies_2, capacitances_2, label='Folienkondensator 100 µF', linestyle='-', color='green')
|
||||
plt.plot(frequencies_3, capacitances_3, label='Elektrolytkondensator 100 µF)', linestyle='-', color='red')
|
||||
|
||||
# Logarithmische Achsen
|
||||
plt.xscale('log') # Logarithmische Skalierung der Frequenz
|
||||
# plt.yscale('log') # Optional: Logarithmische Skalierung der Kapazität
|
||||
|
||||
# Achsentitel und Beschriftungen
|
||||
plt.xlabel('f / Hz')
|
||||
plt.ylabel('C / F')
|
||||
# plt.title('Frequenzabhängige Kapazitäten')
|
||||
|
||||
formatter = ScalarFormatter()
|
||||
formatter.set_powerlimits((-3, 3)) # Format wird bei Werten außerhalb von 10^-3 und 10^3 angewendet
|
||||
plt.gca().yaxis.set_major_formatter(formatter) # Wendet den Formatierer auf die y-Achse an
|
||||
|
||||
# Gitter und Legende
|
||||
plt.grid()
|
||||
# plt.grid(which='both', linestyle='--', linewidth=0.5)
|
||||
plt.legend()
|
||||
plt.tight_layout()
|
||||
|
||||
# Anzeige des Plots
|
||||
# plt.show()
|
||||
plt.savefig(filename, dpi=600)
|
||||
|
||||
|
||||
def plot_Impedanz(impedanz_betrag_1, impedanz_betrag_2, impedanz_betrag_3, frequencies_1, frequencies_2, frequencies_3, filename):
|
||||
# Plot
|
||||
plt.figure(figsize=(10, 6))
|
||||
|
||||
# Mehrere Linien plotten
|
||||
# plt.plot(frequencies_1, impedanz_betrag_1, label='Keramikkondensator 1 nF', linestyle='-', color='blue')
|
||||
plt.plot(frequencies_2, impedanz_betrag_2, label='Folien 100 µF', linestyle='-', color='green')
|
||||
plt.plot(frequencies_3, impedanz_betrag_3, label='Elektrolyt 100 µF)', linestyle='-', color='red')
|
||||
|
||||
# Logarithmische Achsen
|
||||
plt.xscale('log') # Logarithmische Skalierung der Frequenz
|
||||
plt.yscale('log') # Optional: Logarithmische Skalierung der Kapazität
|
||||
|
||||
# Achsentitel und Beschriftungen
|
||||
plt.xlabel('Frequenz f [Hz]')
|
||||
plt.ylabel('Impedanz |Z| [Ohm]')
|
||||
# plt.title('Frequenzabhängige Kapazitäten')
|
||||
|
||||
formatter = ScalarFormatter()
|
||||
formatter.set_powerlimits((-3, 3)) # Format wird bei Werten außerhalb von 10^-3 und 10^3 angewendet
|
||||
plt.gca().yaxis.set_major_formatter(formatter) # Wendet den Formatierer auf die y-Achse an
|
||||
|
||||
# Gitter und Legende
|
||||
plt.grid()
|
||||
# plt.grid(which='both', linestyle='--', linewidth=0.5)
|
||||
plt.legend()
|
||||
plt.tight_layout()
|
||||
|
||||
# Anzeige des Plots
|
||||
# plt.show()
|
||||
plt.savefig(filename, dpi=600)
|
||||
|
||||
|
||||
print("was mache ich mit negativen Kapazitäten?")
|
||||
# Beispiel: Datei einlesen und plotten
|
||||
filename_1 = "1nF.txt" # Ersetzen durch den tatsächlichen Dateinamen
|
||||
filename_2 = "100muF Folien vermutlich.txt" # Ersetzen durch den tatsächlichen Dateinamen
|
||||
filename_3 = "100muF Elektrolyt vermutlich.txt" # Ersetzen durch den tatsächlichen Dateinamen
|
||||
frequencies_1, capacitances_1, resistances_1 = parse_file(filename_1)
|
||||
frequencies_2, capacitances_2, resistances_2 = parse_file(filename_2)
|
||||
frequencies_3, capacitances_3, resistances_3 = parse_file(filename_3)
|
||||
|
||||
# Platzhalter für Y-Werte
|
||||
impedanz_betrag_1 = resistances_1 / ((2 * math.pi * frequencies_1 ** 2 * resistances_1 ** 2 * capacitances_1 ** 2 + 1) ** 0.5)
|
||||
impedanz_betrag_2 = resistances_2 / ((2 * math.pi * frequencies_2 ** 2 * resistances_2 ** 2 * capacitances_2 ** 2 + 1) ** 0.5)
|
||||
impedanz_betrag_3 = resistances_3 / ((2 * math.pi * frequencies_3 ** 2 * resistances_3 ** 2 * capacitances_3 ** 2 + 1) ** 0.5)
|
||||
|
||||
# Daten plotten
|
||||
# plot_Kapazität(capacitances_1, capacitances_2, capacitances_3, frequencies_1, frequencies_2, frequencies_3, "Frequenzabhängige_Kapazität_100muF.png")
|
||||
# plot_Kapazität(capacitances_1, capacitances_2, capacitances_3, frequencies_1, frequencies_2, frequencies_3, "Frequenzabhängige_Kapazität_1nF.png")
|
||||
|
||||
plot_Impedanz(impedanz_betrag_1, impedanz_betrag_2, impedanz_betrag_3, frequencies_1, frequencies_2, frequencies_3, "Frequenzabhängige_Kapazität_Betrag Z.png")
|
||||
Loading…
Reference in New Issue
Block a user