Detailed Instructions (Recommended Steps in Python)
-
Create a function
y=feedforward(x,d,s)
that adds one feedforward echo to a signal. This function should create an output signaly
that is as long as the input signal, and whose values are given byy[n] = x[n] + sx[n-d]
. You might write something like
Create impulse responses that add echo to the input signal, with three different echo lengths:
def feedforward(x,d,s):
y=x.copy()
for n in range(d,len(x)):
y[n] += s*x[n-d]
return y
Create three impulse responses, with echoes of strength -0.9 at 2, 4, and 8 samples, respectively. Compute the frequency response corresponding to each impulse response. Use code something like
delta=np.zeros(256)
delta[0]=1
In figure 1, create six subfigures (perhaps use
impresp=np.zeros((256,3))
freqresp=np.zeros((256,3))
for k in [0,1,2]:
delay=2**(k+1)
impresp[:,k]=feedforward(delta,delay,-0.9)
freqresp[:,k]=scipy.fftpack.fft(impresp[:,k])
to plot the absolute values of the three frequency responses. You need not label the axes, but add a title to each figure specifying the feedforward delay.
for k in [0,1,2]:
plt.subplot(3,2,2*k)
plt.plot(impresp[:,k])
plt.title('Impulse Response {}'.format(k))
plt.subplot(3,2,2*k+1)
plt.plot(abs(freqresp[:,k]))
plt.title('Frequency Response {}'.format(k))
-
Download the sample TIMIT sentence from
https://catalog.ldc.upenn.edu/LDC93S1.
Load it using
wav.read
, e.g., using this code:
The TIMIT sentence is sampled at
import wave
with wave.open('LDC93S1.wav') as f:
Fs = f.getframerate()
nchan = f.getnchannels()
nbytes = f.getsampwidth()
LDC93S1bytes = f.readframes(f.getnframes())
LDC93S1 = np.frombuffer(LDC93S1bytes,'int16')
F_s=16000
Hz. We want to test three very different types of feedforward delays: a delay ofd=int(0.001*F_s)
will change the timbre of the sound somewhat (because the frequency response will have a zero, right at 1/0.001=1000 Hertz), a delay ofd=int(0.03*F_s)
will sound like a reverberant room, and a delay ofd=1/F_s
will sound like two people talking at once. Create three output signals, corresponding to these three different delays, and listen to them. In figure 2, create four subfigures. Useplt.subplot(4,1,1)
to create a spectrogram of the original audio file in the first subfigure (the 0.001*np.amax(sgram) is necessary to force the spectrogram to use the available colors). In each of the other subfigures, use
t,f,sgram = scipy.signal.spectrogram(LDC93S1,fs=Fs) plt.imshow(t,f,sgram,vmax=0.001*np.amax(sgram))
plt.title('Original Signal')
scipy.signal.spectrogram
to plot a spectrogram of one of the reverberated signals (be sure to add a title, specifying which filter output is shown in each one). You may see some frequency filtering in the first reverberated signal, but no time-domain distortion. You should see significant echo speech added to the third reverberated signal. -
Create three different impulse responses: a rectangle of
length 6, a rectangle with alternating signs, and a
rectangle with block-3 alternating signs:
As in part (a), create a figure with six subplots. Show the impulse response in the left-hand column, and the magnitude of the corresponding frequency response in the right-hand column.
h=np.zeros((256,3))
for n in range(0,6):
h[n,0]=1
h[n,1]=(-1)**n
h[n,2]=(-1)**int(n/3)
-
Filter the TIMIT sentence using the three impulse
responses of part (c) (using
np.convolve
). Plot spectrograms of the three results. Be sure to specify, in the title for each figure, which filter output is shown in each figure. Which one is lowpass? Which one is highpass? Which one is bandpass?
Deliverables (Required)
By 3/7/2017 23:59, upload to compass a zip file named MYNAME_LAB5.ZIP containing the following things:
- Four images, from the four parts listed above.
- A program that generates your figures.
Walkthrough
Here is the video walkthrough for lab 6.