# 2) Plot Signal With Respect To The Time.: # Imports
# 2) Plot Signal With Respect To The Time.: # Imports
# 2) Plot Signal With Respect To The Time.: # Imports
import soundfile
import sounddevice
import numpy as np
import matplotlib.pyplot as plt
Data
filename = 'chirp.wav'
y, fs = soundfile.read(filename)
1) Find the number of samples (𝑁0), the duration of the signal (𝑇0), and
sampling interval (𝑇)
N = len(y) # number of samples (𝑁0) in the audio file
print(f"The number of samples is {N}")
Ts = 1 / fs # the sampling interval (𝑇)
print(f"The sampling interval is {Ts}")
T = N * Ts # the duration of the signal (𝑇0)
print(f"The duration of the signal is {T}")
[<matplotlib.lines.Line2D at 0x199d7a99280>]
3) Compute and plot the DFT of signal 𝑦.
X = np.fft.fft(y) # Compute the DFT of signal 𝑦
plt.figure(figsize=(20,10))
plt.grid()
plt.xlabel('Frequency')
plt.ylabel('Magnitude of Signal DFT(y)')
plt.plot(freq, abs(X)) # Plot the magnitude of the DFT
[<matplotlib.lines.Line2D at 0x199d7af52e0>]
[<matplotlib.lines.Line2D at 0x199d7e3c7c0>]
6) Compute and plot DFT of 𝑦1
X1 = np.fft.fft(y1) # Compute the DFT of signal 𝑦1
[<matplotlib.lines.Line2D at 0x199d7ed97f0>]
How has the signal 𝑦1 and its spectrum changed compared to the original
signal?
???
7) To listen to the audio signal, use the command sounddevice.play(x, fs) . Play
both signals and see how the original audio signal has changed after
subsampling.
play1 = sounddevice.play(y, fs)
8) Change the sampling rate in step (4) to 5 and explain how the audio signal
and its spectrum change.
y2 = y[::5]
[<matplotlib.lines.Line2D at 0x199da1a0400>]