Pretty much all of Fall 2024
This commit is contained in:
BIN
7th-Semester-Fall-2024/ECOMMS/labs/lab1/ECOMMS_Lab_1.pdf
Normal file
BIN
7th-Semester-Fall-2024/ECOMMS/labs/lab1/ECOMMS_Lab_1.pdf
Normal file
Binary file not shown.
BIN
7th-Semester-Fall-2024/ECOMMS/labs/lab1/Lab1_Part1.png
Normal file
BIN
7th-Semester-Fall-2024/ECOMMS/labs/lab1/Lab1_Part1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 49 KiB |
BIN
7th-Semester-Fall-2024/ECOMMS/labs/lab1/Lab1_Part1b.png
Normal file
BIN
7th-Semester-Fall-2024/ECOMMS/labs/lab1/Lab1_Part1b.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 68 KiB |
BIN
7th-Semester-Fall-2024/ECOMMS/labs/lab1/Rubric Speech .pdf
Normal file
BIN
7th-Semester-Fall-2024/ECOMMS/labs/lab1/Rubric Speech .pdf
Normal file
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 88 KiB |
Binary file not shown.
After Width: | Height: | Size: 59 KiB |
@ -1,5 +1,5 @@
|
||||
import numpy as np
|
||||
import sounddevice as sd
|
||||
#import sounddevice as sd
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
def normalize_signal(signal):
|
||||
@ -10,12 +10,37 @@ def normalize_signal(signal):
|
||||
normalized_signal -= 1
|
||||
return normalized_signal
|
||||
|
||||
snr = 10
|
||||
|
||||
f = 466.16
|
||||
f_s = 16000
|
||||
T_0 = 1/f
|
||||
|
||||
t = np.arange(0,0.01,1/f_s)
|
||||
t = np.arange(0,T_0,1/f_s)
|
||||
s = 0.5 * np.sin(2*np.pi*f*t)
|
||||
|
||||
sd.play(normalize_signal(s), samplerate=f_s, blocking=True)
|
||||
# Convert signal covariance
|
||||
var_s = np.cov(s)
|
||||
|
||||
# Calculate required noise variance
|
||||
var_snr_10 = var_s/(10**(10/10))
|
||||
var_snr_20 = var_s/(10**(20/10))
|
||||
var_snr_30 = var_s/(10**(30/10))
|
||||
|
||||
# Genearate noise
|
||||
noise_snr_10 = (var_snr_10**0.5) * np.random.randn(len(s))
|
||||
noise_snr_20 = (var_snr_20**0.5) * np.random.randn(len(s))
|
||||
noise_snr_30 = (var_snr_30**0.5) * np.random.randn(len(s))
|
||||
|
||||
# Add signal and noise
|
||||
m_snr_10 = s+noise_snr_10
|
||||
m_snr_20 = s+noise_snr_20
|
||||
m_snr_30 = s+noise_snr_30
|
||||
|
||||
plt.plot(t,s, label="Pure A$\sharp$ Tone")
|
||||
plt.plot(t,m_snr_10, label="Corrupted A$\sharp$ Tone (SNR=10dB)")
|
||||
plt.plot(t,m_snr_20, label="Corrupted A$\sharp$ Tone (SNR=20dB)")
|
||||
plt.plot(t,m_snr_30, label="Corrupted A$\sharp$ Tone (SNR=30dB)")
|
||||
plt.legend()
|
||||
plt.title("Pure and Corrupted A$\sharp$ Tones")
|
||||
plt.xlabel("Time (s)")
|
||||
plt.show()
|
||||
#sd.play(normalize_signal(s), samplerate=f_s, blocking=True)
|
||||
|
33
7th-Semester-Fall-2024/ECOMMS/labs/lab1/part2.py
Normal file
33
7th-Semester-Fall-2024/ECOMMS/labs/lab1/part2.py
Normal file
@ -0,0 +1,33 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import scipy as sp
|
||||
|
||||
f_s = 8E3
|
||||
|
||||
T_s = 1/f_s
|
||||
t = np.arange(-5,5,T_s)
|
||||
|
||||
f = np.linspace(0,f_s,len(t))
|
||||
omega = 2*np.pi*f
|
||||
|
||||
def u(t):
|
||||
return np.heaviside(t, 1)
|
||||
|
||||
w = u(t) - u(t-0.6) + u(t-0.7) - u(t-1)
|
||||
|
||||
W_c = 1j*(np.exp(-1j*omega*0.6) + np.exp(-1j*omega) - np.exp(-1j*omega*0.7) - 1)/omega
|
||||
W_d = sp.fft.fft(w)
|
||||
|
||||
print(W_c[:10])
|
||||
print(W_d[:10])
|
||||
|
||||
|
||||
plt.plot(t,w)
|
||||
plt.show()
|
||||
|
||||
|
||||
plt.subplot(211)
|
||||
plt.plot(W_c)
|
||||
plt.subplot(212)
|
||||
plt.plot(W_d)
|
||||
plt.show()
|
54
7th-Semester-Fall-2024/ECOMMS/labs/lab1/part3.py
Normal file
54
7th-Semester-Fall-2024/ECOMMS/labs/lab1/part3.py
Normal file
@ -0,0 +1,54 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import scipy as sp
|
||||
|
||||
f_m = 5E3
|
||||
f_c = 25E3
|
||||
|
||||
f_s = 50*f_c
|
||||
|
||||
T_m = 1/f_m
|
||||
T_c = 1/f_c
|
||||
T_s = 1/f_s
|
||||
|
||||
A_c = 10
|
||||
A_m = 1
|
||||
|
||||
t = np.arange(0,2*T_m,T_s)
|
||||
f = t*f_s/(2*T_m)
|
||||
|
||||
# ===== AM =====
|
||||
s = A_c * (1 + A_m*np.cos(2*np.pi*f_m*t)) * np.cos(2*np.pi*f_c*t)
|
||||
|
||||
var_s = np.cov(s)
|
||||
|
||||
SNR = 10
|
||||
var_snr = var_s/(10**(SNR/10))
|
||||
noise_snr = (var_snr**0.5) * np.random.randn(len(s))
|
||||
m = s+noise_snr
|
||||
|
||||
S = sp.fft.fft(s)
|
||||
M = sp.fft.fft(m)
|
||||
|
||||
plt.subplot(211)
|
||||
plt.stem(f, S)
|
||||
plt.subplot(212)
|
||||
plt.stem(f, M)
|
||||
plt.show()
|
||||
|
||||
# ===== FM =====
|
||||
beta_f = 10
|
||||
s = A_c*np.cos(2*np.pi*f_c*t + beta_f*A_m*np.sin(2*np.pi*f_m*t))
|
||||
|
||||
var_snr = var_s/(10**(SNR/10))
|
||||
noise_snr = (var_snr**0.5) * np.random.randn(len(s))
|
||||
m = s+noise_snr
|
||||
|
||||
S = sp.fft.fft(s)
|
||||
M = sp.fft.fft(m)
|
||||
|
||||
plt.subplot(211)
|
||||
plt.stem(f, S)
|
||||
plt.subplot(212)
|
||||
plt.stem(f, M)
|
||||
plt.show()
|
BIN
7th-Semester-Fall-2024/ECOMMS/labs/lab1/part_3_spectrum.png
Normal file
BIN
7th-Semester-Fall-2024/ECOMMS/labs/lab1/part_3_spectrum.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
Reference in New Issue
Block a user