def show_wav(): wave = thinkdsp.read_wave(sys.argv[1]) #wave.normalize() # 归一化 #wave.apodize() # 渐入渐出 #segment = wave.segment(start=0, duration=2/440) #segment.plot() wave.plot() plt.show() # 频谱 spectrum = wave.make_spectrum() spectrum.plot() plt.show()
def plot(self, frame_rate=11025): duration = self.period * 3 wave = self.make_wave(duration, start=0, frame_rate=frame_rate) wave.plot()
def plot(self, framerate=11025): duration = self.period() * 3 wave = self.make_wave(duration, start=0, framerate=framerate) wave.plot()
PI2 = 2 * np.pi class SawtoothChirp(Chirp): def evaluate(self, ts): freqs = np.linspace(self.start, self.end, len(ts)) dts = np.diff(ts, prepend=0) dphis = PI2 * freqs * dts phases = np.cumsum(dphis) cycles = phases / PI2 frac, _ = np.modf(cycles) ys = normalize(unbias(frac), self.amp) return ys signal = SawtoothChirp(start=220, end=880) wave = signal.make_wave(duration=0.1, framerate=4000) wave.apodize() wave.write(filename="output3-2.wav") plt.subplot(1, 2, 1) plt.title("SawtoothChirp") wave.plot() sp = wave.make_spectrum(256) plt.subplot(1, 2, 2) sp.plot() plt.xlabel("时间") plt.ylabel("频率") plt.title("频谱") plt.show()
def noiseRemoval(): data = wave.load('A00269') wave.plot(data, title="A00269") data = wave.discardNoise(data) wave.plot(data, title="A00269 - After noise removal") level = 6 omission = ([1,2], True) # 5-40 hz rebuilt = wave.decomp(data, 'sym5', level, omissions=omission) wave.plot(rebuilt, title="A00269 - After wavelet decompisition") data = wave.load('A00420') wave.plot(data, title="A00420") data = wave.discardNoise(data) wave.plot(data, title="A00420 - After noise removal") rebuilt = wave.decomp(data, 'sym5', level, omissions=omission) wave.plot(rebuilt, title="A00420 - After wavelet decompisition") data = wave.load('A00550') wave.plot(data, title="A00550") data = wave.discardNoise(data) wave.plot(data, title="A00550 - After noise removal") rebuilt = wave.decomp(data, 'sym5', level, omissions=omission) wave.plot(rebuilt, title="A00420 - After wavelet decompisition")
#x=0 #for i in range(0, len(records)): # print('working record:' + records[i]) # x+=1 # data = wave.load(records[i]) # sig = Signal(records[i],data) # # RR_interval = wave.RR_interval(sig.RPeaks) # # RR_interval_diff = wave.interval(RR_interval) # # bin_RR_intervals = wave.RR_interval_bin(RR_interval) # print (bin_RR_intervals) """ # Testing QS points data = wave.load('A00857') wave.plot(data) signal = Signal('A00857', data) signal.plotRPeaks() fig = plt.figure(figsize=(60, 6)) ax = fig.add_subplot(111) ax.plot(signal.data) ax.set_xlim(0, signal.data.size) ax.plot(*zip(*signal.QSPoints), marker='o', color='r', ls='') fig.savefig('/Users/samy/Downloads/graph.png') plt.close() """