def spectrogram(self): #plotting the spectrogram for .wav#### if self.fileName.endswith(".wav"): fig = plot.figure() plot.subplot(111) self.powerSpectrum, self.freqenciesFound, self.time, self.imageAxis = plot.specgram( self.audio2, Fs=self.samplingrate, cmap=self.cmap) plot.colorbar() # plot.ylim(self.min_freq_slider.value(),self.max_freq_slider.value()) plot.xlabel('Time') plot.ylabel('Frequency') fig.savefig('plot.png') plot.close() self.upload() #plotting the spectrogram for csv#### if self.fileName.endswith(".csv"): # Define the list of frequencies self.frequencies = np.arange(5, 105, 5) # Sampling Frequency self.data = pd.DataFrame(pd.read_csv(self.fileName, delimiter=None)) self.Data = self.data.iloc[1:][1:] self.sub2 = self.Data.values.tolist() self.samplingFrequency = 2 * (len(self.sub2)) + 1 # Create two ndarrays self.s1 = np.empty([0]) # For samples self.s2 = np.empty([0]) # For signal # Start Value of the sample self.start = 1 # Stop Value of the sample self.stop = self.samplingFrequency for self.frequency in self.frequencies: self.sub1 = np.arange(self.start, self.stop, 1) self.s1 = np.append(self.s1, self.sub1) self.s2 = np.append(self.s2, self.sub2) self.start = self.stop + 1 self.stop = self.start + self.samplingFrequency # Plot the spectrogram fig = plot.figure() plot.subplot(111) self.powerSpectrum, self.freqenciesFound, self.time, self.imageAxis = plot.specgram( self.s2, Fs=self.samplingFrequency, cmap=self.cmap) plot.xlabel('Time') plot.ylabel('Frequency') plot.colorbar() fig.savefig('plot.png') plot.close() self.upload()
def newsignal(self): mag = np.abs(self.new_yfft) phase = np.angle(self.new_yfft) mod_wave = np.multiply(mag, np.exp(1j * phase)) self.signal = ifft(mod_wave) pen = pg.mkPen(color=(255, 255, 255)) self.sc2.clear() # self.sc.clear() # self.signal=ifft(self.new_yfft) # mag= np.abs(self.signal) # phase= np.angle(self.signal) # mod_wave=np.multiply(mag,np.exp(1j*phase)) # self.sc2.plot(mod_wave[0:].real, pen=pen) self.sc2.plot(self.signal.real, pen=pen) # self.sc.plot(self.audio2[0:], pen=pen) max = self.max_freq_slider.value() min = self.min_freq_slider.value() fig = plot.figure() self.powerSpectrum, self.freqenciesFound, self.time, self.imageAxis = plot.specgram( self.signal.real, Fs=self.samplingrate, cmap=self.cmap, vmin=min, vmax=max) plot.colorbar() # plot.ylim(min,max) plot.xlabel('Time') plot.ylabel('Frequency') fig.savefig('plot.png') plot.close() self.upload()
def savepdf(self): self.combbox() fig = plot.figure() # plot.subplot(2,1,1) # plot.plot(self.audio2[0:],color='black',linewidth=0.005,scalex=True) # plot.title("before") plot.subplot(2, 1, 2) max = self.max_freq_slider.value() min = self.min_freq_slider.value() self.powerSpectrum, self.freqenciesFound, self.time, self.imageAxis = plot.specgram( self.signal.real, Fs=self.samplingrate, cmap=self.cmap, vmin=min, vmax=max) plot.colorbar() plot.xlabel('Time') plot.ylabel('Frequency') plot.subplot(2, 1, 1) plot.plot(self.signal[0:].real, color='blue', linewidth=0.003, scalex=True) plot.title("after") fn, _ = QtWidgets.QFileDialog.getSaveFileName( self, "Export PDF", None, "PDF files (.pdf);;All Files()") if fn: if QtCore.QFileInfo(fn).suffix() == "": fn += ".pdf" fig.savefig(fn) plot.close()
def spectrogram2(self): #plotting the spectrogram#### # Define the list of frequencies self.frequencies = np.arange(5, 105, 5) # Sampling Frequency self.data = pd.DataFrame(pd.read_csv(self.fileName2, delimiter=None)) self.Data = self.data.iloc[1:][1:] self.sub2 = self.Data.values.tolist() self.samplingFrequency = 2 * (len(self.sub2)) + 1 # Create two ndarrays self.s1 = np.empty([0]) # For samples self.s2 = np.empty([0]) # For signal # Start Value of the sample self.start = 1 # Stop Value of the sample self.stop = self.samplingFrequency for self.frequency in self.frequencies: self.sub1 = np.arange(self.start, self.stop, 1) self.s1 = np.append(self.s1, self.sub1) self.s2 = np.append(self.s2, self.sub2) self.start = self.stop + 1 self.stop = self.start + self.samplingFrequency # Plot the spectrogram fig = plot.figure() plot.subplot(111) self.powerSpectrum, self.freqenciesFound, self.time, self.imageAxis = plot.specgram( self.s2, Fs=self.samplingFrequency) plot.xlabel('Time') plot.ylabel('Frequency') fig.savefig('plot2.png') self.upload2()
def savepdf(self): fig = plot.figure() if (self.channel1box.isChecked() == True): if len(self.x) == 0: pass else: plot.subplot(3, 2, 1) plot.plot(self.x, self.y, color='red', linewidth=2, scalex=True) plot.subplot(3, 2, 2) self.powerSpectrum, self.freqenciesFound, self.time, self.imageAxis = plot.specgram( self.s2, Fs=self.samplingFrequency) plot.xlabel('Time') plot.ylabel('Frequency') # if(self.channel2box.isChecked()==True): # if len(self.x1) ==0 : # pass # else: # plot.subplot(3,2,3) # plot.plot(self.x1,self.y1,color='red',linewidth=2,scalex=True) # plot.subplot(3,2,4) # self.powerSpectrum1, self.freqenciesFound1, self.time1, self.imageAxis1 = plot.specgram(self.s2, Fs=self.samplingFrequency) # plot.xlabel('Time') plot.ylabel('Frequency') if (self.channel3box.isChecked() == True): if len(self.x2) == 0: pass else: plot.subplot(3, 2, 5) plot.plot(self.x2, self.y2, color='red', linewidth=2, scalex=True) plot.subplot(3, 2, 6) self.powerSpectrum2, self.freqenciesFound2, self.time2, self.imageAxis2 = plot.specgram( self.s2, Fs=self.samplingFrequency) plot.xlabel('Time') plot.ylabel('Frequency') # plot.show() fig.savefig("x.pdf")