Starting from:

$30

EE235 Lab 1 Introduction to python and Signals Solved

you will work through a series of exercises to introduce you to Python with an emphasis on the basics that you need to know for working with signals. You will learn to use variables, perform basic operations, and write your own scripts to run in Jupyter Notebook.

 

 Turn-in Checklist  
•      Pre-lab: Show that you have installed or can access the necessary software by creating a Jupyter notebook that demonstrates basic Python functions and uploading it to canvas.

•      5 check-offs with TA

•      Lab 1 Jupyter notebook with code for each assignment in individual cells and with markdown cells used for the lab overview and response to report questions.

Create a Jupyter notebook (prelab1.ipynb) that demonstrates the use of print, playing audio, and creating documentation using a markdown cell to your TA, as outlined in section 3 of the Background document. You will need to download the audio file provided on the Lab 1 assignment web page and save it in the same directory as your Lab 1 notebook. Save the prelab1 notebook and submit the file to the lab 1 assignment on Canvas.

Download the template notebook for lab 1 (TemplateL1.ipynb) and rename it Lab1-XYZ, where XYZ are the initials of the lab partners. Your Lab 1 notebook should be organized according to this template.  

: Creating and Manipulating Arrays
Read Section 4 of the Background document. This assignment will have four parts, A-D, each of which should be indicated with comments, following the guidelines in the Lab 1 template. In creating arrays, you should use numpy, so don’t forget to import it.

A.    Create an array y1 with values 4, 6, 2.  

B.     Extract the value 6 from y1 to store in ca. In cb, store the last two elements of y1. In d, store the number of elements in y1. Print ca, cb and d.  

C.     Create two arrays of length 5. The first (x1) should have all elements take the value 2, and the second (x2) should range from [-2,2]. Use the ones and arange attributes of numpy. Print x1 and x2.

D.    Create arrp = x1+x2, and arrc as the concatenation of x1 and x2. Print arrp and arrc.  

Run the code in this cell and verify that the results are what you expect.

 Amplitude Operations on Signals
Read Section 5.0-5.2 of the Background document. Again, following the guidelines in the Lab 1 template, start a new cell and write a script to meet the following specifications.

A. Create digital versions x and y of the functions below over 0 ≤ t ≤ 3, with a sampling frequency fs = 2.

   x(t) = 0.5t                   y(t) = t2   

B. Assign z to be the digital version of z(t) = x(t) – 2y(t)

C.  In w1, store the value of z(t) at t = 2. Print w1.

D.  Store the values of z for 0 ≤ t ≤ 1.5 in w2. Print w2.

Note: You may need to cast your indices to integers. Use index = int(index)

Show that your output matches the below:

 Working with Sound Files
Read Section 5.3 of the Background document. Start a new cell following the guidelines in the Lab 1 template, dividing it into Parts A-D.  

A. Read in the files “train32.wav” and “tuba11.wav” using either the scipy wavfile package or simpleaudio, saving the audio vectors and sampling frequencies in variables y1, y2, fs1, fs2, respectively. Print the number of channels to confirm that the train file has 1 channel and the tuba file has 2.

B. Play the two sounds in their correct form and then with the sampling frequencies swapped.

C.Determine the length of the two signal and extract a section of the longer one that is the same length as the shorter one, called y3. Add two equal-length, single-channel signals to create y4. Play and write out y4 using sampling frequency fs1. 

D.    Concatenate the signals in y1 and y2, adding a 4 second pause between them. Call the new signal y5. Play the new signal and write it out to a file using sampling frequency fs1.  

Plotting Comparisons
Read Section 6 of the Background document. Start a new cell following the guidelines in the Lab 1 template, dividing it into Parts A and B.

A.Define a time vector signal over -2 ≤ t ≤ 4, let fs = 5. Then create digital versions of the following signals for this time span:

w(t) = |t| x(t) = 2 – t  y(t) = -0.5t2

B. Plot all three signals in one figure with a grid and a legend. Be sure to label the time axis and title the figure.

 

Read the plot documentation and explain how you would change the command to distinguish the signals using different line styles (solid, dashed, dotted) to make the figure easier to read for someone who is color blind. 

 Plotting Sound Files in Subplots
Start a new cell following the guidelines in the Lab 1 template, dividing it into Parts A and B.  

A.    Create time sample vectors for the audio signals from Assignment 3 (y1 and y2) using the original sampling frequency for each, and name them t1 and t2. (You will need to use the signal lengths you found in that assignment.)  

B.    Plot the two signals side by side using a 1x2 subplot. Adjust the x and y axis limits to have the same ranges in both plots. Be sure to title the plots and label axes appropriately. For the time axis, you should plot time in msec, for which you will need to multiple the time array by 1000 as in the example in the Background document. Do not use grids on the subplots. Adjust the spacing to avoid overlap.
 

More products