Rowan-Classes/8th-Semester-Spring-2025/clinic-consultant/labs/lab-2/lab2q2.py
Aidan Sharpe 82b435b6a2 Week 3
2025-02-14 22:27:10 -05:00

45 lines
860 B
Python

import numpy as np
import matplotlib.pyplot as plt
def main():
# Define the samples axis (0 to 51, excluding 51)
n = np.arange(51)
# Define the four frequencies used
f_1 = 1/7
f_2 = 1/21
f_3 = 1/17.5
f_4 = 1/(7*np.pi)
# Convert frequencies to angular frequency
omega_1 = 2*np.pi*f_1
omega_2 = 2*np.pi*f_2
omega_3 = 2*np.pi*f_3
omega_4 = 2*np.pi*f_4
# Sample a cosine of each of the
x_1 = np.cos(omega_1*n)
x_2 = np.cos(omega_2*n)
x_3 = np.cos(omega_3*n)
x_4 = np.cos(omega_4*n)
# Plot each of the cosines in a separate subplot
plt.subplot(411)
plt.stem(n, x_1)
plt.subplot(412)
plt.stem(n, x_2)
plt.subplot(413)
plt.stem(n, x_3)
plt.subplot(414)
plt.stem(n, x_4)
plt.xlabel("n")
plt.show()
if __name__ == "__main__":
main()