Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
87 views

DSP Lab Python Tutorial

This document provides instructions and questions for a tutorial on digital signal processing (DSP) lab. Students are asked to complete coding questions in Python, either from scratch or using packages like NumPy and SciPy. Questions cover topics like lists, vectors, matrices, algorithms, and signal processing. Students should submit their individual solutions by a specified due date.

Uploaded by

ameencet
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views

DSP Lab Python Tutorial

This document provides instructions and questions for a tutorial on digital signal processing (DSP) lab. Students are asked to complete coding questions in Python, either from scratch or using packages like NumPy and SciPy. Questions cover topics like lists, vectors, matrices, algorithms, and signal processing. Students should submit their individual solutions by a specified due date.

Uploaded by

ameencet
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

College of Engineering Trivandrum

Tutorial 1, S5-ECE
EC 333: DSP LAB

1 Instructions
1. This tutorial is mainly aimed at developing your coding skills in python and therefore questions are
not all technical.
2. You can either code it from scratch or can use any packages like numpy,scipy etc

3. You can code in batches of 4,dividing the total number of questions between the members.Each member
in the group is expected to submit individually at-least 6 questions and the batch as a whole should
solve all the questions.
4. Feel free to contact any of the faculties/TA students of the lab if you require any help.
5. This tutorial submission will be evaluated as a part of continuous evaluation of the lab.50% marks will
be awarded when you submit and rest 50% for your explanation of the code.
6. Its fine to take help from internet sources or from your group members or other students in your
class.But everyone is expected to have individual solutions.Plagiarism in any form will result in award-
ing zero marks.

7. Submit this on the lab-hour of 17/12/2021 or 21/12/2021.

2 Questions
1. Define list1=[23,45,12,32,89,67,54,34,76,90,56,21,73]

1. Find the numbers between 25 and 50 in the given list:


2. Find the maximum and minimum values in the list without using inbuilt functions
3. Find the first two smallest numbers from the list
2. Create a vector spanning the range from 0 to 2π, containing 100 equally spaced components, so that the
first value is 0, and the last value is 2π.

3. a) Create two different lists of the same length with random values and add them.
b) Now subtract them.
c) Perform element-by-element multiplication on them.
d) Perform element-by-element division on them.
e) Raise one of the list to the second power.
f) Create a 3x3 matrix and display the first row and the second column on the screen
4. Generate two matrices A and B. Find the following:
1)A+B 2)AB 3)A-B 4)AB T 5)BAT .
Note:Select the size of the matrices in such a way that all the above operations are possible.

5. Write a program in Python to execute the Bubble sort algorithm.


6. Write a python function loops to find the first N smallest numbers along with their positions in a list.The
function should input the list and should return first N smallest number.
7. Create an example to demonstrate that the following equation holds; (ABC)T = C T B T AT
8. Find the value of cos(x) for x=0.8 using the series expansion:

x2 x4 x6
cos(x) = 1 − + − + .... (1)
2! 4! 6!

9. Construct a 3 × 3 matrix with (i, j)th entry as i2 + j 2 . Construct a vector of size 3 × 1 with entries as
all 1’s. Perform the matrix vector product using loops. Verify the matrix vector product using dot().
10. Write a program to Multiply two matrices A and B using loops. Matrix A is of size 4 × 5 with (i, j)th
entry is (i + j). Matrix B is of size 5 × 10 with (i, j)th entry is i ∗ j. Verify your result of matrix
multiplication using dot() function in numpy.
11. Find the solution for the following system of equations:

a + 2b + 3c = 14
4a + 5b + 6d = 16
7a + 8b + 12c + 14d = 20
3a+2b+42c = 32

Verify your results using solve function in numpy.


12. The n-by-n Hilbert matrix H, has as its entries
1
Hi,j = i, j = 1, 2, . . . , n
(i + j–1)
.
Create a double “for loop” to generate the 15-by-15 Hilbert matrix.
Extract the submatrix which contains 2nd and 3rd rows of the matrix.Also plot second row against third
row
13. Write a NumPy program to compute an element-wise indication of the sign for all elements in a given
array.
14. Find and display all integers between 1 and 10000 which divide by 37.
15. Plot the function using if-else command

−x x≤0
f (x) =
x x>0

16. Find the maxima and minima (if any) of the polynomial function f (x) = x3 − x2 − 3x. Plot the function
and the maxima and minima (if any) using a ‘o’ for each minimum and a ‘*’ for each maximum.
17. find the approximate root of the equation using numpy: 0.5(x − 2)3 − 40sin(x) = 0 within the interval
[2,4].
18. Write a short function in python to find out whether a given number (up to 1,000,000) is a prime number.
The function should return true or false. Bear in mind that 1 is not considered a prime number. (Hint:
Use the brute force approach and divide the number (K) by all integers from 2 to K-1. Check the
remainders for 0s) Subsequently, apply this function to list all prime numbers between 1 and 100
19. The Taylor Series for the exponential function is ex = 1 + x + x2 /2! + x3 /3! + ...... + xn /n!
a) Using a for loop, compute and display the error of the Taylor series when using 12 and 15 terms, each
as compared to the exponential function when evaluated at x = 2.
b) Compute and display the number of terms necessary for this function to have an error within your
allowed range of 0.001 when evaluated at x = 3. Display this error.

Page 2
20. Generate an m by n matrix ,A, of elements randomly chosen between 1 and 100.Generate three vectors
B,C D which contains elements in A with value less than 35, elements in A with value between 35 and
70 ,elements in A with value between 70 and 100.
21. Gradient descent with momentum:Consider a convex function,f(X):R → R such that f (x) = (x+5)2 .
Find argminx f (x) using using gradient descent with momentum.
Choose the initial value, x0 = 8 and step size, γ = 0.1.
(k+1) (k) (k+1)
Algorithm: xd = βxd + γ.∆f (x)x(k+1) = x(k) + xd .
Here ∆f (x) = 2(x + 5) and choose β = 1 − γ
22. Write a program using a while loop that asks the user for a number, and prints a countdown from that
number to zero.
23. Zeller’s Algorithm. Zeller’s algorithm computes the day of the week on which a given date will fall
(or fell). Zeller’s algorithm is defined as follows:
Let A, B, C, D denote integer variables that have the following values:
A = the month of the year, with March having the value 1, April the value 2, . . ., December the
value 10, and January and February being counted as months 11 and 12 of the preceding year (in which
case,subtract 1 from C)
B = the day of the month (1, 2, 3, . . . , 30, 31)
C = the year of the century (e.g. C = 89 for the year 1989)
D = the century (e.g. D = 19 for the year 1989)
Note: if the month is January or February, then the preceding year is used for computation. This is
because there was a period in history when March 1st, not January 1st, was the beginning of the year.
Let W, X, Y, Z, R also denote integer variables. Compute their values in the following order using
integer arithmetic:
W = (13*A - 1) / 5
X=C/4
Y=D/4
Z = W + X + Y + B + C - 2*D
R = the remainder when Z is divided by 7
The value of R is the day of the week, where 0 represents Sunday, 1 is Monday, 2, is Tuesday, ... , 6 is
Saturday. If the computed value of R is a negative number, add 7 to get a non negative number between
0 and 6.
Write a python program to simulate this algorithm.Run some test cases- try today’s date, your birth
date etc
24. Write a python program to illustrate Fourier series expansion of a square wave.Generate the sine-waves
with the fundamental frequency and its harmonics,with each amplitude of the sine- waves specified by
corresponding Fourier series coefficients.Add all the sine-waves together and plot the result.
25. Simulate an Election: With some help from the random module and a little condition logic, you can
simulate an election between two candidates. Suppose two candidates, Candidate A and Candidate B,
are running for mayor in a city with three voting regions. The most recent polls show that Candidate A
has the following chances for winning in each region:
Region 1: 87% chance of winning
Region 2: 65% chance of winning
Region 3:17% chance of winning
Write a program that simulates the election 100000, times and prints the percentage of where Candidate
A wins. To keep things simple, assume that a candidate wins the election is they win in at least two of
the three regions.

Page 3

You might also like