Instructions | Deliverables | Walkthrough | References

Detailed Instructions (Recommended Steps in Python)

  1. In this lab, you'll use the numpy.convolve function to find the outputs of several different linear systems. First, create three different inputs: a delayed impulse, a rectangle, and a sine wave. Try
    import numpy as np
    import matplotlib.pyplot as plt
    import math
    x=np.zeros((3,20))
    x[0,3]=1
    for n in range(5,10):
    x[1,n]=1
    for n in range(0,20):
    x[2,n]=math.sin(2*math.pi*n/5)
    plt.subplot(3,1,1)
    plt.stem(x[0,:])
    plt.title('PUT A TITLE SAYING WHAT TYPE OF FUNCTION IT IS')
    plt.subplot(3,1,2)
    plt.stem(x[1,:])
    plt.title('PUT A TITLE SAYING WHAT TYPE OF FUNCTION IT IS')
    plt.subplot(3,1,3)
    plt.stem(x[2,:])
    plt.title('PUT A TITLE SAYING WHAT TYPE OF FUNCTION IT IS')
    plt.show()
    plt.savefig('lab5fig1.png')
  2. Create three different impulse responses, each containing five samples, though not all of them are nonzero: one should be a three-sample averager, one should be an Euler backward difference, and one should be a second-differencer.
    h=np.zeros((3,5))
    for n in range(0,3):
    h[0,n]=0.33333
    h[1,0]=1
    h[1,1]=-1
    h[2,0]=1
    h[2,1]=-2
    h[2,2]=1
    plt.subplot(3,1,1)
    plt.stem(h[0,:])
    plt.title('PUT A TITLE SAYING WHAT TYPE OF FUNCTION IT IS')

    plt.subplot(3,1,2)
    plt.stem(h[1,:])
    plt.title('PUT A TITLE SAYING WHAT TYPE OF FUNCTION IT IS')

    plt.subplot(3,1,3)
    plt.stem(h[2,:])
    plt.title('PUT A TITLE SAYING WHAT TYPE OF FUNCTION IT IS')

    plt.show()
    plt.savefig('lab5fig2.png')
  3. Use np.convolve to convolve each of your three inputs with each of the three impulse responses. Create three subfigures. In the first subfigure, show all of the different outputs in response to the first input, and so on.
    y=np.zeros((3,3,24))
    t=np.linspace(0,23,24)
    for xtype in range(0,3):
    for htype in range(0,3):
    y[xtype,htype,:]=np.convolve(x[xtype,:],h[htype,:])
    for xtype in range(0,3):
    plt.subplot(3,1,xtype+1)
    plt.plot(t,y[xtype,0,:],t,y[xtype,1,:],t,y[xtype,2,:])
    plt.title('Responses of Three Systems to x{}'.format(xtype))
    plt.show()
    plt.savefig('lab5fig3.png')

Deliverables (Required)

By 2/28/2017 23:59, upload to compass a zip file named MYNAME_LAB5.ZIP containing the following things:

  1. Three images: inputs (three subfigures), impulse responses (three subfigures), outputs (three subfigures).
  2. A program that generates your figures.

Walkthrough

Here's the video walkthrough.

References