def segment_violin(start=1.2, duration=0.6): wave = thinkdsp.read_wave('92002__jcveliz__violin-origional.wav') # extract a segment segment = wave.segment(start, duration) segment.normalize() segment.apodize() segment.write('violin_segment1.wav') # plot the spectrum spectrum = segment.make_spectrum() n = len(spectrum.hs) spectrum.plot(high=n/2) thinkplot.Save(root='violin2', xlabel='frequency (Hz)', ylabel='amplitude density') # print the top 5 peaks peaks = spectrum.peaks() for amp, freq in peaks[:10]: print freq, amp # compare the segments to a 440 Hz Triangle wave note = thinkdsp.make_note(69, 0.6, sig_cons=thinkdsp.TriangleSignal, framerate=segment.framerate) wfile = thinkdsp.WavFileWriter('violin_segment2.wav', note.framerate) wfile.write(note) wfile.write(segment) wfile.write(note) wfile.close()
def segment_violin(start=1.2, duration=0.6): wave = thinkdsp.read_wave('92002__jcveliz__violin-origional.wav') # extract a segment segment = wave.segment(start, duration) segment.normalize() segment.apodize() segment.write('violin_segment1.wav') # plot the spectrum spectrum = segment.make_spectrum() n = len(spectrum.hs) spectrum.plot(high=n / 2) thinkplot.Save(root='violin2', xlabel='frequency (Hz)', ylabel='amplitude density') # print the top 5 peaks peaks = spectrum.peaks() for amp, freq in peaks[:10]: print freq, amp # compare the segments to a 440 Hz Triangle wave note = thinkdsp.make_note(69, 0.6, sig_cons=thinkdsp.TriangleSignal, framerate=segment.framerate) wfile = thinkdsp.WavFileWriter('violin_segment2.wav', note.framerate) wfile.write(note) wfile.write(segment) wfile.write(note) wfile.close()
def sin_spectrum(): wave = thinkdsp.make_note(69, 0.5, SinSignal) spectrum = wave.spectrum() spectrum.plot() thinkplot.Show() peaks = spectrum.peaks() print peaks[0] wave2 = spectrum.make_wave() wave2.plot() thinkplot.Show() wave2.write()
def sin_spectrum(): """Plots the spectrum of a sine wave. """ wave = thinkdsp.make_note(69, 0.5, SinSignal) spectrum = wave.spectrum() spectrum.plot() thinkplot.Show() peaks = spectrum.peaks() print(peaks[0]) wave2 = spectrum.make_wave() wave2.plot() thinkplot.Show() wave2.write()