Major progress on VLSI lab 1&2 and ECOMMS lab 1
This commit is contained in:
BIN
7th-Semester-Fall-2024/ECOMMS/labs/lab1/part-3-am-freq.png
Normal file
BIN
7th-Semester-Fall-2024/ECOMMS/labs/lab1/part-3-am-freq.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
BIN
7th-Semester-Fall-2024/ECOMMS/labs/lab1/part-3-am-time.png
Normal file
BIN
7th-Semester-Fall-2024/ECOMMS/labs/lab1/part-3-am-time.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 84 KiB |
BIN
7th-Semester-Fall-2024/ECOMMS/labs/lab1/part-3-fm-freq.png
Normal file
BIN
7th-Semester-Fall-2024/ECOMMS/labs/lab1/part-3-fm-freq.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
BIN
7th-Semester-Fall-2024/ECOMMS/labs/lab1/part-3-fm-time.png
Normal file
BIN
7th-Semester-Fall-2024/ECOMMS/labs/lab1/part-3-fm-time.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 108 KiB |
@ -1,54 +1,93 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib as mpl
|
||||
from cycler import cycler
|
||||
import scipy as sp
|
||||
|
||||
f_m = 5E3
|
||||
f_c = 25E3
|
||||
|
||||
f_s = 50*f_c
|
||||
def add_noise(s, SNR):
|
||||
var_s = np.cov(s)
|
||||
var_noise = var_s/(10**(SNR/10))
|
||||
noise = var_noise**0.5 * np.random.randn(len(s))
|
||||
return s + noise
|
||||
|
||||
T_m = 1/f_m
|
||||
T_c = 1/f_c
|
||||
T_s = 1/f_s
|
||||
def plot_at_snrs(t, f, s_am, s_fm):
|
||||
stem_colors = ['k', 'b', 'r']
|
||||
ci = 0
|
||||
stem_color = stem_colors[ci]
|
||||
|
||||
A_c = 10
|
||||
A_m = 1
|
||||
am_time = plt.figure()
|
||||
am_freq = plt.figure()
|
||||
fm_time = plt.figure()
|
||||
fm_freq = plt.figure()
|
||||
|
||||
t = np.arange(0,2*T_m,T_s)
|
||||
f = t*f_s/(2*T_m)
|
||||
for SNR in range(10,30,10):
|
||||
m_am = add_noise(s_am,SNR)
|
||||
m_fm = add_noise(s_fm,SNR)
|
||||
|
||||
# ===== AM =====
|
||||
s = A_c * (1 + A_m*np.cos(2*np.pi*f_m*t)) * np.cos(2*np.pi*f_c*t)
|
||||
plt.figure(am_time)
|
||||
plt.plot(t, m_am, label=f"SNR = {SNR}")
|
||||
|
||||
var_s = np.cov(s)
|
||||
plt.figure(am_freq)
|
||||
plt.stem(f, abs(sp.fft.fft(m_am)), label=f"SNR = {SNR}", markerfmt=stem_color+"o", linefmt=stem_color+"-")
|
||||
|
||||
SNR = 10
|
||||
var_snr = var_s/(10**(SNR/10))
|
||||
noise_snr = (var_snr**0.5) * np.random.randn(len(s))
|
||||
m = s+noise_snr
|
||||
plt.figure(fm_time)
|
||||
plt.plot(t, m_fm, label=f"SNR = {SNR}")
|
||||
|
||||
S = sp.fft.fft(s)
|
||||
M = sp.fft.fft(m)
|
||||
plt.figure(fm_freq)
|
||||
plt.stem(f, abs(sp.fft.fft(m_fm)), label=f"SNR = {SNR}", markerfmt=stem_color+"o", linefmt=stem_color+"-")
|
||||
|
||||
plt.subplot(211)
|
||||
plt.stem(f, S)
|
||||
plt.subplot(212)
|
||||
plt.stem(f, M)
|
||||
plt.show()
|
||||
ci += 1
|
||||
stem_color = stem_colors[ci]
|
||||
|
||||
# ===== 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))
|
||||
plt.figure(am_time)
|
||||
plt.plot(t, s_am, label="Pure signal")
|
||||
plt.legend(loc="upper right")
|
||||
plt.savefig("part-3-am-time")
|
||||
|
||||
var_snr = var_s/(10**(SNR/10))
|
||||
noise_snr = (var_snr**0.5) * np.random.randn(len(s))
|
||||
m = s+noise_snr
|
||||
plt.figure(am_freq)
|
||||
plt.stem(f, abs(sp.fft.fft(s_am)), label="Pure signal", markerfmt=stem_color+"o", linefmt=stem_color+"-")
|
||||
plt.xlim((0, 2E5))
|
||||
plt.legend(loc="upper right")
|
||||
plt.savefig("part-3-am-freq")
|
||||
|
||||
S = sp.fft.fft(s)
|
||||
M = sp.fft.fft(m)
|
||||
plt.figure(fm_time)
|
||||
plt.plot(t, s_fm, label="Pure signal")
|
||||
plt.legend(loc="upper right")
|
||||
plt.savefig("part-3-fm-time")
|
||||
|
||||
plt.subplot(211)
|
||||
plt.stem(f, S)
|
||||
plt.subplot(212)
|
||||
plt.stem(f, M)
|
||||
plt.show()
|
||||
plt.figure(fm_freq)
|
||||
plt.stem(f, abs(sp.fft.fft(s_fm)), label="Pure signal", markerfmt=stem_color+"o", linefmt=stem_color+"-")
|
||||
plt.xlim((0, 2E5))
|
||||
plt.legend(loc="upper right")
|
||||
plt.savefig("part-3-fm-freq")
|
||||
|
||||
plt.show()
|
||||
|
||||
|
||||
def main():
|
||||
f_m = 5E3
|
||||
f_c = 125E3
|
||||
f_s = 125E4
|
||||
|
||||
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) # Time domain
|
||||
f = t*f_s/(2*T_m) # Frequency domain
|
||||
|
||||
beta_f = 10 # Modulation index
|
||||
|
||||
s_am = A_c * (1 + A_m*np.cos(2*np.pi*f_m*t)) * np.cos(2*np.pi*f_c*t)
|
||||
s_fm = A_c*np.cos(2*np.pi*f_c*t + beta_f*A_m*np.sin(2*np.pi*f_m*t))
|
||||
plot_at_snrs(t, f, s_am, s_fm)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
mpl.rcParams['axes.prop_cycle'] = cycler(color=['k', 'b', 'r'])
|
||||
main()
|
||||
|
1
7th-Semester-Fall-2024/ECOMMS/labs/lab1/part4.py
Normal file
1
7th-Semester-Fall-2024/ECOMMS/labs/lab1/part4.py
Normal file
@ -0,0 +1 @@
|
||||
|
Reference in New Issue
Block a user