def plot(ax, times, torques, compensations): #plt.xlim([0,100]) ax.set_xlim([-0.5, 100]) ax.set_ylim([-0.002, 0.35]) Fv, P1 = mathutil.getOneSidedFFT(times, torques) Fv, P3 = mathutil.getOneSidedFFT(times, compensations) #plt.plot(Fv, P2, label='Pulsating torque', linewidth=0.8, color='darkorange') ax.plot(Fv, P3, label='Compensation torque', linewidth=1.0, color='green', alpha=0.5) ax.plot(Fv, P1, label='Actual torque', linewidth=1.0, color='red', alpha=0.8) ax.legend() #ax.text(0, 0.01, s='0th', horizontalalignment='center', verticalalignment='bottom', fontsize=16) #ax.text(4, getGreater(P1[idx1], P3[idx1]), s='1st', horizontalalignment='center', verticalalignment='bottom', fontsize=16) #ax.text(8, getGreater(P1[idx2], P3[idx2]), s='2nd', horizontalalignment='center', verticalalignment='bottom', fontsize=16) #ax.text(24, getGreater(P1[idx3], P3[idx3]), s='6th', horizontalalignment='center', verticalalignment='bottom', fontsize=16) #ax.text(48, getGreater(P1[idx4], P3[idx4]), s='12th', horizontalalignment='center', verticalalignment='bottom', fontsize=16) ax.tick_params(labelsize=16) ax.set_ylabel('Torque amplitude [Nm]', fontsize=16) ax.set_xlabel('Harmonic order no.', fontsize=16) #plt.savefig(filename + ".svg") ax.grid(True) pos = np.arange(0, 200, step=1) labels = np.arange(0, 200, step=1) ax.set_xticks(pos[0::24]) ax.set_xticklabels(labels[0::6]) minor_locatorx = AutoMinorLocator(6) minor_locatory = AutoMinorLocator(2) ax.xaxis.set_minor_locator(minor_locatorx) ax.yaxis.set_minor_locator(minor_locatory)
def amplitudeSpectrum(filename, times, torques, dpi): # Compute FFT Fv, P1 = mathutil.getOneSidedFFT(times, torques) # Plot plt.figure(filename, figsize=(16,10), dpi=dpi) ax = plt.gca() ymax = max(P1[1:]) # Find max harmonic amplitude (exclude dc) ax.set(xlim=(0, 250), ylim=(0, ymax + 0.05)) plt.ylabel("Amplitude") plt.xlabel("Frequency [Hz]") plt.plot(Fv, P1)
def amplitudeSpectrum(filename, times, torques, dpi): # Compute FFT Fv, P1 = mathutil.getOneSidedFFT(times, torques) # Plot plt.figure('2.' + filename, figsize=(16, 10), dpi=dpi) plt.yscale('log') #plt.ylim([0.1,10**3]) ax = plt.gca() ymax = max(P1[1:]) # Find max harmonic amplitude (exclude dc) #ax.set(ylim=(ymax)) # ymax + 0.05 xlim=(0, 250) plt.ylabel("Amplitude") plt.xlabel("Frequency [Hz]") plt.plot(Fv, P1)
def getInterestingHarmonics(time, y, speed_nom, poles): Fv, P1 = mathutil.getOneSidedFFT(time, y) frequencies = mathutil.getHarmonicFrequencies(speed_nom, poles) # Harmonic may not be exactly at calculated location, so # Search for the max from neighborhood. indices = [] for harmonic in frequencies: idx1 = mathutil.findNearestIdx(Fv, harmonic) idx2 = np.argmax(P1[idx1 - 5:idx1 + 5]) indices.append(idx1 + (idx2 - 5)) x = (Fv[indices[0]], Fv[indices[1]], Fv[indices[2]], Fv[indices[3]]) y = (P1[indices[0]], P1[indices[1]], P1[indices[2]], P1[indices[3]]) print("Harmonic frequencies: ", ['%.3f' % elem for elem in frequencies]) print("Matched frequencies: ", ['%.3f' % elem for elem in x]) return x, y
from dataprocess import datautil from matplotlib.ticker import (MultipleLocator, FormatStrFormatter, AutoMinorLocator) # Load the data BASE_PATH = ".\\simulation-data\\FEM\\" data1 = pd.read_csv(BASE_PATH + "FEM-current-measurement-error.csv", skiprows=1, delimiter=';', names=['time', 'speed', 'torque']) # Get time array in seconds time1 = datautil.convertToSeconds(data1.time.to_numpy(), 'ms') # Compute FFT f, P = mathutil.getOneSidedFFT(time1, data1.torque.to_numpy()) harmonic_frquencies, orders = mathutil.getSignificantHarmonicFrequencies( 3100, 6) # nominal op. indices = [] N = 2 f2 = [] P2 = [] for freq in harmonic_frquencies: idx = mathutil.findNearestIdx(f, freq) f2.append(freq) P2.append(P[idx]) indices.append(idx) f2 = f2[::3] # plot integer harmonics only
delimiter=';', names=['time', 'speed', 'torque']) data5 = pd.read_csv(BASE_PATH + "960rpm.csv", skiprows=1, delimiter=';', names=['time', 'speed', 'torque']) # Get time array in seconds time1 = datautil.convertToSeconds(data1.time.to_numpy(), 'ms') time2 = datautil.convertToSeconds(data2.time.to_numpy(), 'ms') time3 = datautil.convertToSeconds(data3.time.to_numpy(), 'ms') time4 = datautil.convertToSeconds(data4.time.to_numpy(), 'ms') time5 = datautil.convertToSeconds(data5.time.to_numpy(), 'ms') # Compute FFT f1, P1 = mathutil.getOneSidedFFT(time1, data1.torque.to_numpy()) f2, P2 = mathutil.getOneSidedFFT(time2, data2.torque.to_numpy()) f3, P3 = mathutil.getOneSidedFFT(time3, data3.torque.to_numpy()) f4, P4 = mathutil.getOneSidedFFT(time4, data4.torque.to_numpy()) f5, P5 = mathutil.getOneSidedFFT(time5, data5.torque.to_numpy()) # Combine, so we can stop copy-pasting already f = [f1, f2, f3, f4, f5] P = [P1, P2, P3, P4, P5] rpms = [60, 120, 240, 480, 960] harmonics_1 = [] harmonics_2 = [] harmonics_6 = [] harmonics_12 = [] harmonics_24 = []