import sys sys.path.insert(1, 'dsp-modulo') from thinkdsp import SinSignal from thinkdsp import CosSignal from thinkdsp import decorate import matplotlib.pyplot as plt seno = SinSignal(freq=20, amp=1, offset=0) coseno = CosSignal(freq=50, amp=1.3, offset=0) waveSeno = seno.make_wave(duration=1, start=0, framerate=11025) waveCoseno = coseno.make_wave(duration=1, start=0, framerate=11025) waveResultante = waveSeno + waveCoseno decorate(xlabel="Tiempo (s)") decorate(ylabel="Amplitud") waveSeno.plot() waveCoseno.plot() plt.show() decorate(xlabel="Tiempo (s)") decorate(ylabel="Amplitud") waveResultante.plot() plt.show()
import os import librosa import numpy as np from scipy.io.wavfile import write from thinkdsp import read_wave, CosSignal wave = read_wave('105977__wcfl10__favorite-station.wav') carrier_sig = CosSignal(freq=440) carrier_wave = carrier_sig.make_wave(duration=wave.duration, framerate=wave.framerate) modulated = wave * carrier_wave # amplitude modulation - multiplying the input wave by a carrier wave in the time domain modulated.make_audio() modulated.play('out1.wav') y, sr = librosa.load( '105977__wcfl10__favorite-station.wav', sr=44100) # y is a numpy array of the wav file, sr = sample rate y_shifted = librosa.effects.pitch_shift(y, sr, n_steps=-8) # shifted by n_steps # pitch shift - a step is equal to a semitone write('out2.wav', 44100, y_shifted) print('Writing out2.wav') #combining amplitude modulation and pitch shift together for greater voice modulation y, sr = librosa.load('out1.wav', sr=44100) y_shifted = librosa.effects.pitch_shift(y, sr, n_steps=-8) write('out1_2.wav', 44100, y_shifted)
import matplotlib.pyplot as plt from thinkdsp import TriangleSignal, decorate, SquareSignal, SawtoothSignal, CosSignal signal = CosSignal(4500) duration = signal.period * 5 segment = signal.make_wave(duration, framerate=10000) plt.rcParams['font.sans-serif'] = ['SimHei'] plt.rcParams['axes.unicode_minus'] = False decorate(xlabel='Time (s)') plt.subplot(121) segment.plot() signal = CosSignal(5500) duration = signal.period * 5 segment = signal.make_wave(duration, framerate=10000) decorate(xlabel='Frequency (Hz)') plt.subplot(122) segment.plot() plt.show()
plt.show() spectrum.high_pass(1000) spectrum.plot(high=7000) plt.show() spectrum.band_stop(2500, 1000) spectrum.plot(high=7000) plt.show() cos_sig = CosSignal(freq=440, amp=1.0, offset=0) sin_sig = SinSignal(freq=880, amp=2.0, offset=0) # # 正弦信号和波形 plt.subplot() cos_sig.plot() decorate(xlabel='Time (s)') wave1 = cos_sig.make_wave(duration=1) wave1.apodize() wave1.make_audio() spectrum1 = wave1.make_spectrum() plt.subplot() spectrum1.plot(high=2000) # # 余弦信号和波形 sin_sig.plot() decorate(xlabel='Time (s)') wave2 = cos_sig.make_wave(duration=1) wave2.apodize() wave2.make_audio() spectrum2 = wave2.make_spectrum() plt.subplot()