EE314 - Digital Signal Processing
Lab exercises
Session: 1
Related topics:
-
•
Discrete-time sequences
-
Task 1:
Write a python script to generate and plot it using stem method.
-
Task 2:
Write a python script to generate and plot .
-
Task 3:
Write a python script to generate and plot for (i) , (ii) , (iii) and (iv) . Use subplots.
-
Task 4:
Write a python script to generate and plot for
. Use subplots.
Session: 2
Related topics:
-
•
time-shifting, upsampling, downsampling, time-inverse
-
•
Convolution
-
Task 1:
Write a python script to generate from a given sequence and user-provided input .
Verify your answer for
-
Task 2:
Write a python script to perform convolution of two sequences in the conventional way, i.e.,
Verify your answer for the mentioned in the previous question and the following
-
Task 3:
Write a python script to perform convolution using matrix multiplication. Represent the input sequence as a column vector, , and multiply with the matrix , obtained from the impulse response , i.e., , where is the column vector representation of the output sequence .
Session: 3
Related topics:
-
•
Convolution
-
•
Connection between DTFT and CTFS and DTFT and CTFT
Note: Please use line (continuous) plots while plotting continuous-time signals. Also, unlike discrete-time signals where index takes only integer values, the axis of continuous-time signals can have rational and irrational numbers.
-
Task 1:
Write a python script to verify that accumulator and forward difference are inverse of each other by forming matrices of appropriate sizes corresponding to those two systems.
-
Task 2:
Write a python script to verify (a) duality of DTFT and CTFS, (b) connection between DTFT and CTFT.
For part (a), consider a periodic signal and find its Fourier series coefficients. Form a discrete-time signal from those coefficients while ensuring that the indices of coefficients remain same in the discrete-time sequence. Now calculate the DTFT of the sequence you obtained and visually compare it with the plot of over a suitable interval and list your observations.
For part (b), consider a continuous time signal . First, find its Fourier transform and then find the Fourier transform of after sampling it with a pulse train. Form a discrete-time signal from those samples and calculate its DTFT. Visually, compare the Fourier transform of the sampled signal and the DTFT, and list your observations.
-
Task 3:
Write a python script to demonstrate Gibb’s phenomenon for discrete-time idea low-pass filter.
Consider the impulse response of an ideal lowpass filter with cut-off frequency ,
Now to demonstrate Gibb’s Phenomenon, plot for different values of . For example, , where
Session: 4
Related topics:
-
•
z-transform
-
Task 1:
Plot for the following sequences and then extract the values corresponding to to plot on a linear scale and then compare with the DTFT of the corresponding
(i) where
(ii) where
(iii)
Session: 5
Related topics:
-
•
z-transform
-
Task 1:
Write a python script to perform convolution by multiplying two polynomials in . Verify your answer for the sequences mentioned in the Lab sessions: 2 and 3.
-
Task 2:
Write a python script to plot poles and zeros of a rational transfer function on the -plane. Show your plots for the following transfer functions:
-
(a)
-
(b)
-
(c)
-
(a)
Session: 6
Related topics:
-
•
Block diagram representation
-
•
DFT
-
Task 1:
Generate the DFT matrix discussed in the class. Multiply the sequence given in Lab session: 2 to find its DFT. Compare your output with the numpy’s fft function’s output.
-
Task 2:
Simulate the following systems on Simulink by creating their block diagram representation
-
(a)
Moving average filter:
-
(b)
Auto-regression filter:
-
(c)
Auto-regression moving average (ARMA):
-
(a)
Session: 7
Related topics:
-
•
DFT, IDFT
-
•
Circular & Linear convolution
-
•
Circulant matrices
-
Task 1:
Write a python script that performs point circular convolution of two sequences. Note that must be equal to or larger than the length of both sequences. Use this script to perform linear convolution of two given sequences. Consider the sequences given in Lab sessions 2 and 3.
-
Task 2:
Perform linear convolution by first calculating the DFT of two given sequences and then inverse DFT of the element-wise product of resultant sequences, i.e.,
Verify your answer by comparing it with the results obtained from other methods you have learned in the earlier sessions.
-
Task 3:
Verify that the inverse DFT matrix is indeed the eigenvector matrix of a circulant matrix and the eigenvalues are the DFT of the sequence from which the circulant matrix is formed. Generate a random sequence of length and the corresponding inverse DFT matrices for this task.
Session: 8
Related topics:
-
•
FFT
-
•
CTFT, DTFT
-
Task 1:
Write a python script that finds point DFT of a given sequence using the decimation-in-time algorithm and find the DFT of the following sequences
(1) (2) Note that you need to pad zeros to both sequences before applying and point FFT algorithms, respectively.
Cross-check your answers against the output of numpy.fft.fft(). Find the norm of the differences of the sequences returned by your algorithm and the numpy’s fft algorithm. It should be a very small quantity, in the range of or lower, if both the sequences are identical.
-
Task 2:
Repeat the above tasks for decimation-in-frequency algorithm.
-
Task 3:
Redo the Task 2(b) of Session#3. Find the frequency that encompasses 95% of the spectrum of the given signal and use that to find the Nyquist rate.
Session:9
Related topics:
-
•
Sampling
-
•
Discrete-time processing of continuous-time signals
-
•
Continuous-time processing of discrete-time signals
-
Task 1:
Consider the signal mentioned in Tasks 2(b) of Session#3, i.e., . In the previous lab session, you have identified the Nyquist rate for this signal (albeit after truncating it to a band-limited signal). Now, reconstruct the signal from its samples taken at the Nyquist rate by adding appropriately time-shifted and amplitude-scaled functions, i.e.,
where is the sampling period chosen according to the Nyquist-Shannon theorem to avoid aliasing.
-
Task 2:
Write a python code to perform low-pass filtering of a continuous-time signal using a discrete-time low-pass filter. Either use the signal mentioned in the Task 1 or a sum sinusoids with three frequencies .
At first, find the cut-off frequency of the continuous-time low-pass filter. Then, calculate the cut-off frequency of the discrete-time low-pass filter. Convolve the samples with the impulse response of the discrete-time low-pass filter. Reconstruct the continuous-time signal from the samples obtained after convolution. Compare the continuous-time signals (input and output) to verify whether the filtering is done correctly.
-
Task 3:
Change the cut-off frequency of the (effective) continuous-time low-pass filter by changing the sampling interval and apply on the sum of sinusoids mentioned in the previous task.
Session: 10
Related topics:
-
•
Sampling, Resampling
-
•
Audio signal processing
Note: You need to install sox to execute the commands mentioned in the tasks listed below. The installation file (Windows) is included in the directory where codes are located.
-
Task 1:
Reading & plotting of a .wav file
Python: Download the file “readPlayPlotAudio.py” from the shared cloud directory and modify it to the read audio files in the “WavFiles” cloud directory.
MATLAB: Download the file “readPlayPlotAudio.m” from the shared cloud directory and modify it to the read audio files in the “WavFiles” cloud directory.
Sox: Read the info of the file using
>sox.exe --info <filename>
(Sox doesn’t have any plotting or playing functionality. You may use sounder.exe, included in the same directory that contains MATLAB, Python codes, to play an audio file. The command to play an audio file is sounder.exe <file_name>).
-
Task 2:
Synthesizing an audio file – single and multitone signals
Generate synthetic audio files and combine them to create a song. Use the following frequencies to generate synthetic audio files:
Notation Frequency (Hz) Note 220 a 246.94 b 523.25 c 585.93 d 657.68 e Table 1: Table of frequencies for different notes. Then combine them in the following order: [a, b, c, d, e]. Repeat the Task 1 for the generated audio file.
Python: Download the file “syntheticAudioFileGeneration.py” from the shared cloud directory and modify it to accomplish the task mentioned above.
MATLAB: Download the file “syntheticAudioGen.m” from the shared cloud directory and modify it to accomplish the task mentioned above.
Sox: Use the following commands to synthesize and combile audio files:
sox -n -b 16 output.wav synth 2.25 sine 300 // generates a 2.25 second sine wave at 300Hz with 16-bit precision
sox file1.wav file2.wav combined.wav // concatenate two files to create a single file
-
Task 3:
Processing audio files – filtering, resampling
Write Python/MATLAB codes to resample, filter the shared audio files and repeat the Task 1 to observe changes in the processed file.
Use the following commands to resample and filter audio files:
sox input.wav output.wav lowpass 100.0 // Apply a 100 Hz low pass filter on the input file to generate the output file.
sox input.wav -r 22050 -b 8 output.wav // Change the sampling rate to 22050 and the precision to 8-bit
Session: 11
Related topics:
-
•
Window sequences
-
•
Spectral analysis using DFT
-
•
Short-time Fourier transform
-
Task 1:
Plot the following windows in the time domain and their frequency spectrum in to range using MATLAB’s wvtool, and document your observations
(a) rectangular, (b) Bartlett, (c) Hamming, (d) Hann, (e) Blackman, (f) Kaiser
-
Task 2:
Spectrum analysis using DFT
Write a python script that estimates the frequency spectrum of a continuous time signal from its samples by first splitting them into smaller blocks by windowing and then calculating their DFT.
Consider different types of windows mentioned in the Task 1 and observe their effects on the estimated spectrum. Pad zeros to blocks you obtained earlier and find the DFT of the zero padded blocks. Does zero padding help in getting a better estimation?
Test your script on the following signals:
(a) (refer to the Task 1 of Session: 9)
(b)
-
Task 3:
Time-dependent Fourier transform or Short-time Fourier transform (STFT)
Write a python script to find the STFT of the signals mentioned in the Task 2. You have to compute the DFT of the shifted windowed signal to find the samples of the DTFT and plot them in a 3D plot.
In addition to the two signals mentioned earlier, find the STFT of and plot it with respect to time index () sampled frequency ().
Session: 12
Related topics:
-
•
Frequency response of discrete-time systems
-
Task 1:
Plot pole-zero plots, Magnitude and phase response of the following systems using MATLAB™’s freqz(), zplane() functions and comment on what kind of filter (lowpass, highpass, bandpass, bandstop etc.) they represent.
-
(a)
Difference equation:
Use
-
(b)
Moving average filter:
Use
-
(c)
Auto-regression filter:
Consider the following values for the parameters
1 0.5 1 1 0.1 5 3 (1/3, 1/3, 1/3) 1 3 (1/2, 1/4, 1/8) 1 -
(d)
Auto-regression moving average (ARMA):
Consider the following values for the parameters
(1,3) 0.5 (1,1,1) (3,3) (1/3, 1/3, 1/3) (1,1/2,1/4) (3,3) (1/3, 1/3, 1/3) (1/3, 1/3, 1/3) (3,3) (1/2, 1/4, 1/8) (1,1/2,1/4)
-
(a)
Session: 13
Related topics:
-
•
Frequency response of LTI system
-
•
Filter design
-
Task 1:
Plot the normalised frequency response of the following systems (review the “firstorder” and “secondorder” MATLAB files and make necessary changes )
(a) A single pole/zero located at
(b) A pair of complex-conjugate poles/zeros located at and
(c) An allpass system with complex-conjugate poles and
-
Task 2:
Minimum, mixed and Maximum phase systems
Review the MATLAB file with name “minimumphase” and modify it to observe the changes in the phase response due to the positioning of the two zeros of the transfer function. What happens when (i) both the zeros are inside the unit circle, (ii) both are outside the unit circle, (iii) one is inside and the other one is outside. Note that the provided MATLAB file has codes corresponding to a single zero system.
-
Task 3:
Filter design
(a) Explore MATLAB’s filterDesigner app and design a Butterworth, a Chebyshev-I, a Chebyshev-II, a Elliptic, an FIR lowpass filter with the following specification
Note down your observations about the magnitude, phase response, filter orders of the filters designed with the app.
(b) Use the MATLAB functions butter, buttord, cheby1, cheby1ord, cheby2, cheby2ord, ellip, ellipord, fir1, fir2 to design a filter with the specifications mentioned in the part (a).
References
-
•
Alan V. Oppenheim, Ronald W. Schafer, John R. Buck, “Discrete-time signal processing” 2nd Ed, Prentice Hall
-
•
John G. Proakis, Dimitris G. Manolakis., “Digital Signal Processing – Principles, Algorithms, and Applications” Fourth Edition, Pearson 2007.
- •
- •
- •
- •
- •
- •
-
•
https://ccrma.stanford.edu/~jos/JFB/JFB_2up.pdf Slide nos. 3 and 4, Source: CCRMA,Stanford University
-
•
https://www.cs.cornell.edu/courses/cs6220/2017fa/CS6220_Lecture3.pdf Lecture notes, Cornell University
-
•
https://in.mathworks.com/help/signal/ref/convmtx.html MATLAB convolution matrix