Files
gem/prak5/test2.py
2026-02-02 16:52:12 +01:00

68 lines
1.9 KiB
Python

import numpy as np
from matplotlib import pyplot as plt
def generate_sin_wave(frequency, amplitude, duration, phase_shift=0):
"""
Generate a sine wave with specified parameters.
Parameters:
frequency (float): Frequency of the sine wave in Hz
amplitude (float): Amplitude of the sine wave
duration (float): Duration of the sine wave in seconds (can be fractional)
phase_shift (float): Phase shift in radians (default: 0)
Returns:
tuple: (time_array, sine_wave_array)
"""
# Generate time array with fractional seconds support
sample_rate = 44100 # Standard audio sample rate
num_samples = int(duration * sample_rate)
t = np.linspace(0, duration, num_samples)
# Generate sine wave with phase shift
y = amplitude * np.sin(2 * np.pi * frequency * t + phase_shift)
return t, y
t, v = generate_sin_wave(60, 325, 0.045, 0)
t2, i = generate_sin_wave(60, 0.125, 0.045, 45)
w = np.multiply(v,i)
V = np.divide(230, np.sqrt(2))
I = np.divide(0.125, np.sqrt(2))
P = np.multiply(np.multiply(V,I), np.cos(np.deg2rad(45)))
q = np.multiply(np.multiply(V,I), np.sin(np.deg2rad(45)))
s = np.sqrt(np.square(P) + np.square(q))
S = []
for _ in range(len(t)):
S.append(s)
Q = []
for _ in range(len(t)):
Q.append(q)
# plot a graph with i, v and w over t
plt.plot(np.multiply(t, 1000), v, label='voltage in V')
plt.plot(np.multiply(t2, 1000), np.multiply(i, 1000), label='current in mA')
plt.plot(np.multiply(t, 1000), w, label='Leistung in W')
# plt.plot(np.multiply(t, 1000), P, label='Wirkleistung in W')
plt.plot(np.multiply(t, 1000), Q, label='Blindleistung in W')
# plt.plot(np.multiply(t, 1000), S, label='Scheinleistung in W')
plt.legend()
plt.grid()
plt.xlabel('time in ms')
plt.ylabel('value')
#save plot as svg
# plt.savefig('prak5/glühbirne_verlauf.svg', format='svg')
plt.savefig('prak5/leuchtröhre_verlauf.svg', format='svg')
plt.show()
0x7ffbfe8
0x7ffbff4