Corrected faulty RMS calculation.

Updated Example.
This commit is contained in:
Hoenen 2022-10-10 15:21:06 +02:00
parent 7c0eb7c9be
commit fefce0f40e

View File

@ -10,7 +10,6 @@ __email__ = "l.hoenen@posteo.de", "lennart.hoenen@stud.uni-heidelberg.de"
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from scipy.fft import rfft, rfftfreq from scipy.fft import rfft, rfftfreq
from scipy.signal.windows import blackman
from scipy.integrate import simps from scipy.integrate import simps
import scipy.io.wavfile as wavfile import scipy.io.wavfile as wavfile
import json import json
@ -37,7 +36,7 @@ def Average_Fourier_Uniform(Data, Samplingrate):
return xf, yf_av 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. 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 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 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. a closest match is found and selected.
""" """
res = max(LSD) res = max(Frequencies)
index = len(LSD) index = len(Frequencies)
for i in range(len(LSD)): for i in range(len(Frequencies)):
if res > np.abs(maxFreq - LSD[i]): if res > np.abs(maxFreq - Frequencies[i]):
res = np.abs(maxFreq - LSD[i]) res = np.abs(maxFreq - Frequencies[i])
index = 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, ".") 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(y_Final_av[0:index]**2, x_Final_av[0:index]) PowerNoiseRMS = simps(LSD[0:index]**2, Frequencies[0:index])
return PowerNoiseRMS 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. 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) VoltageNoiseRMS = np.sqrt(PowerNoiseRMS)
return VoltageNoiseRMS return VoltageNoiseRMS
@ -106,30 +105,38 @@ data = data.T
""" """
EXAMPLE: 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. 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 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") samplingrateprototype, dataprototype = wavfile.read("Z:/Users/Lenny/Power Supply Mk.2/Noise Measurements/NoiseDensityHHCoilPrototypeBatteryInput.wav")
datashielding = datashielding*0.4/2**16 dataprototype = dataprototype*0.4/2**16
datashieldingshaped = np.reshape(datashielding, [10,2000000]) 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_Final_av, y_Final_av = Average_Fourier_Uniform(dataFinalshaped, samplingrateFinal)
x_shielding_av, y_shielding_av = Average_Fourier_Uniform(datashieldingshaped, samplingrateshielding) x_prototype_av, y_prototype_av = Average_Fourier_Uniform(dataprototypeshaped, samplingrateprototype)
print(Calc_Voltage_Noise_RMS(x_Final_av, 25000)) 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["figure.figsize"] = [7,5]
plt.rcParams["font.size"] = 12 plt.rcParams["font.size"] = 12
plt.figure(1, figsize=[12,7]) plt.figure(2, 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_background_av, y_background_av, linewidth=1, label="Background Noise in Lab", alpha=0.7)
plt.loglog(x_shielding_av, y_shielding_av, linewidth=1, label="Noise Prototype with Shielding", 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.loglog(x_DC1V_av, y_DC1V_av, linewidth=1, label="Noise with FreqGen and Shielding", alpha=0.7)
plt.legend() plt.legend()
plt.grid(which="major") plt.grid(which="major")
plt.grid(which="minor", alpha=0.2) plt.grid(which="minor", alpha=0.2)
plt.xlabel("Frequency [Hz]") plt.xlabel("Frequency [Hz]")
plt.ylabel(r"Voltage Noise Spectrum [$V/ \sqrt{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.show()
plt.close() plt.close()