import numpy as np
import matplotlib.pyplot as plt
import IPython.display as ipd
from scipy.signal import fftconvolve
import librosa
sr = 44100
x = np.random.randn(sr) # Make a second of random noise
# Compute the period (spacing) from the note number
note_number = -12
f = 440*(2**(note_number/12))
T = int(sr/f)
# Create an impuse response array big enough to hold 20 pulses
h = np.zeros(T*20+1)
# Evenly space the pulses by the period, using slice notation
h[0::T] = 1
# Do the convolution
y = fftconvolve(x, h)
ipd.Audio(y, rate=sr)
We can also a sound that's not noise, and we get a "robot voice" effect. This is a prelude to assignment 3 on vocoders
x, sr = librosa.load("robot.mp3", sr=sr)
ipd.Audio(x, rate=sr)
y = fftconvolve(x, h)
ipd.Audio(y, rate=sr)