Rowan-Classes/8th-Semester-Spring-2025/clinic-consultant/labs/lab-1/lab1q4.py

31 lines
736 B
Python

"""
ECE 09351 - Digital Signal Processing
Lab 1 Question 4
Translated from MATLAB by Aidan Sharpe
Last Modified: January 18, 2025
"""
import numpy as np
import matplotlib.pyplot as plt
def main():
f_s = 4 # Sample frequency 4[Hz]
T_s = 1/f_s # Period is reciprocal of frequency
n = np.arange(100) # Sample indicies (0 to 99)
t = n*T_s # Conversion between index and time
x = np.cos(2*np.pi*t/5) + np.sin(4*np.pi*t/7) + np.cos(16*np.pi*t/9)
plt.stem(n, x) # Plot samples against index on stem plot
plt.xlabel("n")
plt.ylabel("x(n)")
plt.show() # Show the plot
if __name__ == "__main__":
main()