ECE 4429a – Advanced Digital Signal Processing Fall 2023 Sampling & Quantization MATLAB experiments September 27 and October 13, 2023 NOTES: 1. Lab reports must be submitted individually before the deadline: One week after the lab date (i.e. October 4 and October 20, 11:30 pm). Lab reports must be uploaded to OWL. Email or locker submissions will not be accepted. 2. Get your attendance marked by TA. Lab reports will not be graded without attendance. 3. Create a folder labeled “Lab1” on your Drop Box space in the course OWL site and upload your report and associated code to that directory. 4. Create a Word document that contains MATLAB figures, results, and your comments for each problem. Upload this document to the Lab1 folder. 5. Check the volume control before playing the signals through the headphones! Sampling Experiments 1. (5 marks) Download the files “Sampling1.m” and “mySpectrogram.m” from the “Course Content” folder. Go through the “Sampling1.m” file and add comments to each line indicating its function. Upload the commented file to the Lab1 folder. Uploaded What happens when you run this MATLAB script? Include in your report sample spectrograms when the sinusoidal frequency is 1000 Hz, 4000 Hz, and 7000 Hz. Discuss these results within the context of sampling theorem. F= 1kHz F= 4kHz F= 7kHz When you run this MATLAB script you find that the frequency as a function of time is plotted for the frequencies from 1kHz to 7kHz in 1kHz interval steps, for the given sine function. At 1kHz, we can observe that the peak amplitude occurs at 1kHz. This means that the function was sampled accurately as 1kHz<4kHz. At 4kHz we have no signal. This can be attributed to: 𝑛 0.25 sin (2𝜋(4000) ∗ 8000) = 0.25 sin(𝜋𝑛) = 0 At 7kHz, we have a max amplitude at 1kHz, and this is due to aliasing as we’re not sampling at the required 14kHz, rather 8kHz. 𝑓𝑎 = 𝑓𝑠 − 𝑓𝑜 = 8𝑘𝐻𝑧 − 7𝑘𝐻𝑧 = 1𝑘𝐻𝑧 2. (5 marks) Write a MATLAB script to generate 100 samples of the two sets of analog signals: a. 𝑥1(𝑡) = sin2(2000 𝜋 𝑡) cos2(2000 𝜋 𝑡), and 𝑦1(𝑡) = 18 − 18 cos(4000 𝜋 𝑡),when the sampling rate is 6000 Hz. b. 𝑥2(𝑡) = 2 sin(4000 𝜋 𝑡) cos3(2000 𝜋 𝑡), and 𝑦2(𝑡) = sin(2000 𝜋 𝑡) + 𝜋 𝑡), when the sample rate is 8000 Hz. sin(6000 Properly name this script file and upload it to the Lab1 folder. Show that the sampled versions of 𝑥1(𝑡) and 𝑦1(𝑡), and 𝑥2(𝑡) and 𝑦2(𝑡) are identical. Explain the result using the sampling theory. Through MATLAB’s command window we can now prove that the signals are identical. Despite starting with two different equations, via introducing an appropriate sampling frequency, we have in turn created a ‘new’ signal. This new signal is identical to its corresponding pair. This is because, we are sampling at an insufficiently high sampling frequency, and are thus introducing aliasing. It is this aliasing that makes the functions appear as equal. Quantization Experiments 1. (5 marks) Write a MATLAB function to return a quantized signal, yq, the quantization error, eq, and the signal-to-quantization noise ratio (SNR in dB). The inputs to this function are the discrete-time analog signal, y, the full-scale range of the quantizer, [xmax and xmin], and the number of bits, m. Upload this file to the Lab1 folder. Uploaded 2. (5 marks) Use the above function to quantize a sinusoid 𝑦(𝑡) = 3 sin (600𝜋𝑡 + 𝜋 ), 4 when the full-scale range is [5 -5], number of bits is 6, and the sample rate is 4000 Hz. Let the duration of the sinusoid be 0.02 seconds. a. Include a plot of the original and quantized sinusoids. b. Report the theoretical and measured SNRs for this example. The difference between the two graphs is hardly noticeable from just visual appearance. This is due to the super low voltage steps of (10/64)V/step. We also got a reported SNR of 34.34dB. This is somewhat similar to the theoretical SNR of 30.00dB, and is within the 5% region of error. Bonus Sampling Question 1. (5 marks) The following MATLAB experiment demonstrates aliasing with a chirp signal. A chirp is a signal whose frequency varies as a function of time. In the analog domain, the equation for generating a linear chirp signal is x(t) = Acos( where • t2+2 f1t) is the sweep rate in Hz/sec and f1 is the starting frequency in Hz. Write the discrete-time equivalent of the above equation when sampled at a frequency, fs. 𝑥[𝑛] = 𝑥(𝑛𝑇𝑠 ) = 𝐴𝑐𝑜𝑠(𝜋𝜇(𝑛𝑇𝑠 )2 + 2𝜋𝑓1 (𝑛𝑇𝑠 ) 1 𝑤ℎ𝑒𝑟𝑒 𝑛 = 𝑑𝑖𝑠𝑐𝑟𝑒𝑡𝑒 𝑡𝑖𝑚𝑒 𝑖𝑛𝑑𝑒𝑥, 𝑎𝑛𝑑 𝑇𝑠 = 𝑓𝑠 • With f1 = 100 Hz, = 2000, A =0.25, and fs = 48 kHz, generate 8 seconds of sampled chirp signal. Use the “spectrogram” command (see #2 in Sampling Experiments section) to display the time-frequency structure of the sampled chirp signal. Include this spectrogram in your report, along with your comments on what you see. Play the sampled chirp signal using the “sound” command and describe what you heard. The signal sounds like it continuously gets higher pitched over the 8 second interval. This makes sense with what we are seeing, as the frequency linearly increases as time goes on, attributing to the increase in pitch that we hear. • Repeat the above step but this time using a sampling frequency of 16 kHz. Provide an explanation based on the sampling theorem as to why the sampled chirp sounds different and its spectrogram looks different with f s = 16 kHz. The sampled chirp sounds different, as in this case the pitch gradually increases to its peak frequency, and then halfway through gradually declines back to its starting frequency of 0. This can be attributed to aliasing of the signal in which a peak frequency of 8kHz is obtained. This makes sense as 2Fmax = 16kHz, upon which we get an aliased signal.