Corrected faulty RMS calculation.
Updated Example.
This commit is contained in:
parent
7c0eb7c9be
commit
fefce0f40e
@ -10,7 +10,6 @@ __email__ = "l.hoenen@posteo.de", "lennart.hoenen@stud.uni-heidelberg.de"
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from scipy.fft import rfft, rfftfreq
|
||||
from scipy.signal.windows import blackman
|
||||
from scipy.integrate import simps
|
||||
import scipy.io.wavfile as wavfile
|
||||
import json
|
||||
@ -37,7 +36,7 @@ def Average_Fourier_Uniform(Data, Samplingrate):
|
||||
return xf, yf_av
|
||||
|
||||
|
||||
def Calc_Power_Noise_RMS(LSD, maxFreq):
|
||||
def Calc_Power_Noise_RMS(Frequencies, LSD, maxFreq):
|
||||
"""
|
||||
Calculate the RMS Noise Power over a specified frequency range.
|
||||
As the impedance of the coils acts as a low pass filter, the current and thus the magnetic field cannot follow
|
||||
@ -52,24 +51,24 @@ def Calc_Power_Noise_RMS(LSD, maxFreq):
|
||||
The desired max. frequency might not be part of the list of discrete frequencies in the space of the DFT. Therefore
|
||||
a closest match is found and selected.
|
||||
"""
|
||||
res = max(LSD)
|
||||
index = len(LSD)
|
||||
res = max(Frequencies)
|
||||
index = len(Frequencies)
|
||||
|
||||
for i in range(len(LSD)):
|
||||
if res > np.abs(maxFreq - LSD[i]):
|
||||
res = np.abs(maxFreq - LSD[i])
|
||||
for i in range(len(Frequencies)):
|
||||
if res > np.abs(maxFreq - Frequencies[i]):
|
||||
res = np.abs(maxFreq - Frequencies[i])
|
||||
index = i
|
||||
|
||||
print("You chose the maximum Frequency ", maxFreq, "Hz. The closest matching frequency contained in the DFT is ", LSD[index], "Hz with index ", index, ".")
|
||||
PowerNoiseRMS = simps(y_Final_av[0:index]**2, x_Final_av[0:index])
|
||||
print("You chose the maximum Frequency ", maxFreq, "Hz. The closest matching frequency contained in the DFT is ", Frequencies[index], "Hz with index ", index, ".")
|
||||
PowerNoiseRMS = simps(LSD[0:index]**2, Frequencies[0:index])
|
||||
|
||||
return PowerNoiseRMS
|
||||
|
||||
def Calc_Voltage_Noise_RMS(LSD, maxFreq):
|
||||
def Calc_Voltage_Noise_RMS(Frequencies, LSD, maxFreq):
|
||||
"""
|
||||
See explanation of Calc_Power_Noise_RMS() and Lenny's Thesis 3.4.
|
||||
"""
|
||||
PowerNoiseRMS = Calc_Power_Noise_RMS(LSD, maxFreq)
|
||||
PowerNoiseRMS = Calc_Power_Noise_RMS(Frequencies, LSD, maxFreq)
|
||||
VoltageNoiseRMS = np.sqrt(PowerNoiseRMS)
|
||||
|
||||
return VoltageNoiseRMS
|
||||
@ -106,30 +105,38 @@ data = data.T
|
||||
"""
|
||||
EXAMPLE:
|
||||
"""
|
||||
samplingrateFinal, dataFinal = wavfile.read("Z:/Users/Lenny/Power Supply Mk.2/Noise Measurements/NoiseDensityHHCoilsFinalPowerSupplyWithPIBatteryInput.wav")
|
||||
samplingrateFinal, dataFinal = wavfile.read("Z:/Users/Lenny/Power Supply Mk.2/Noise Measurements/NoiseDensityHHCoil2ndPatchedChannelBatteryInput.wav")
|
||||
dataFinal = dataFinal*0.4/2**16 #Correct conversion from bit values to physical data, for the used Voltae range and precision.
|
||||
dataFinalshaped = np.reshape(dataFinal, [5,4000000]) #Shape one long continuous measurement into 5 shorter measurements to be averaged
|
||||
|
||||
samplingrateshielding, datashielding = wavfile.read("Z:/Users/Lenny/Power Supply/TimeSeriesOP549/FinalMeasurements/NoiseDensitySingleTestCoilWithPIBatteryInputWithShielding.wav")
|
||||
datashielding = datashielding*0.4/2**16
|
||||
datashieldingshaped = np.reshape(datashielding, [10,2000000])
|
||||
samplingrateprototype, dataprototype = wavfile.read("Z:/Users/Lenny/Power Supply Mk.2/Noise Measurements/NoiseDensityHHCoilPrototypeBatteryInput.wav")
|
||||
dataprototype = dataprototype*0.4/2**16
|
||||
dataprototypeshaped = np.reshape(dataprototype, [5,4000000])
|
||||
|
||||
samplingratebackground, databackground = wavfile.read("Z:/Users/Lenny/Power Supply Mk.2/Noise Measurements/NoiseDensityHHCoilsFinalPowerSupplyWithPIBatteryInputBUTEVERYTHINGTURNEDOFF.wav")
|
||||
databackground = databackground*0.4/2**16
|
||||
databackgroundshaped = np.reshape(databackground, [5,4000000])
|
||||
|
||||
x_Final_av, y_Final_av = Average_Fourier_Uniform(dataFinalshaped, samplingrateFinal)
|
||||
x_shielding_av, y_shielding_av = Average_Fourier_Uniform(datashieldingshaped, samplingrateshielding)
|
||||
print(Calc_Voltage_Noise_RMS(x_Final_av, 25000))
|
||||
x_prototype_av, y_prototype_av = Average_Fourier_Uniform(dataprototypeshaped, samplingrateprototype)
|
||||
x_background_av, y_background_av = Average_Fourier_Uniform(databackgroundshaped, samplingratebackground)
|
||||
print(Calc_Voltage_Noise_RMS(x_Final_av, y_Final_av, 30000))
|
||||
print(Calc_Voltage_Noise_RMS(x_prototype_av, y_prototype_av, 30000))
|
||||
print(Calc_Voltage_Noise_RMS(x_background_av, y_background_av, 30000))
|
||||
|
||||
plt.rcParams["figure.figsize"] = [7,5]
|
||||
plt.rcParams["font.size"] = 12
|
||||
plt.figure(1, figsize=[12,7])
|
||||
plt.loglog(x_Final_av, y_Final_av, linewidth=1, label="Noise Final Powersupply in Carton Box", alpha=0.7)
|
||||
plt.loglog(x_shielding_av, y_shielding_av, linewidth=1, label="Noise Prototype with Shielding", alpha=0.7)
|
||||
plt.figure(2, figsize=[12,7])
|
||||
plt.loglog(x_background_av, y_background_av, linewidth=1, label="Background Noise in Lab", alpha=0.7)
|
||||
plt.loglog(x_prototype_av, y_prototype_av, linewidth=1, label="Noise Prototype in carton box", alpha=0.7)
|
||||
plt.loglog(x_Final_av, y_Final_av, linewidth=1, label="Noise Final Powersupply in carton box", alpha=0.7)
|
||||
#plt.loglog(x_DC1V_av, y_DC1V_av, linewidth=1, label="Noise with FreqGen and Shielding", alpha=0.7)
|
||||
plt.legend()
|
||||
plt.grid(which="major")
|
||||
plt.grid(which="minor", alpha=0.2)
|
||||
plt.xlabel("Frequency [Hz]")
|
||||
plt.ylabel(r"Voltage Noise Spectrum [$V/ \sqrt{Hz}$]")
|
||||
plt.title("2 Measurements of 10M Samples at 6.52MHz averaged")
|
||||
plt.title("5 Measurements of 4M Samples at 6.52MHz averaged")
|
||||
plt.show()
|
||||
plt.close()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user