Instructions | Deliverables | Walkthrough | References

Detailed Instructions (Recommended Steps in Python)

  1. Create a function y=feedforward(x,d,s) that adds one feedforward echo to a signal. This function should create an output signal y that is as long as the input signal, and whose values are given by y[n] = x[n] + sx[n-d]. You might write something like
    def feedforward(x,d,s):
    y=x.copy()
    for n in range(d,len(x)):
    y[n] += s*x[n-d]
    return y
    Create impulse responses that add echo to the input signal, with three different echo lengths:
    delta=np.zeros(256)
    delta[0]=1
    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
    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])
    In figure 1, create six subfigures (perhaps use
    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))
    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.
  2. Download the sample TIMIT sentence from https://catalog.ldc.upenn.edu/LDC93S1. Load it using wav.read, e.g., using this code:
    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')
    The TIMIT sentence is sampled at F_s=16000Hz. We want to test three very different types of feedforward delays: a delay of d=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 of d=int(0.03*F_s) will sound like a reverberant room, and a delay of d=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. Use plt.subplot(4,1,1)
    t,f,sgram = scipy.signal.spectrogram(LDC93S1,fs=Fs) plt.imshow(t,f,sgram,vmax=0.001*np.amax(sgram))
    plt.title('Original Signal')
    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 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.
  3. Create three different impulse responses: a rectangle of length 6, a rectangle with alternating signs, and a rectangle with block-3 alternating signs:
    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)
    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.
  4. 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:

  1. Four images, from the four parts listed above.
  2. A program that generates your figures.

Walkthrough

Here is the video walkthrough for lab 6.

References