You are on page 1of 4

MuhammadHarsaRidhan_harsasrg2002@gmail.

com

February 26, 2023

[9]: import numpy as np


import matplotlib.pyplot as plt
plt.style.use('ggplot') # Matplotlib style sheet -␣
↪nicer plots!

plt.rcParams['figure.figsize'] = 45, 5

[10]: #List of signal


sig1 = np.sin(np.linspace(0, 15 * np.pi, 4000))
sig2 = np.cos(np.linspace(0, 10 * np.pi, 4000))
sig3 = np.random.normal(1, 30.8, 4000)
sig4 = np.random.normal(1, 30.8, 4000)
sig5 = np.sin(np.linspace(0, 15 * np.pi, 4000))+np.cos(np.linspace(0, 10 * np.
↪pi, 4000))+np.random.normal(1, 30.8, 4000)

[11]: #List of FFT


fsig1 = np.fft.rfft(sig1, n=4000)
fsig2 = np.fft.rfft(sig2, n=4000)
fsig3 = np.fft.rfft(sig3, n=4000)
fsig4 = np.fft.rfft(sig4, n=4000)
fsig5 = np.fft.rfft(sig5, n=4000)

[12]: #Frequency on x-axis


xf= np.linspace(0, 1, 2000+1)

[13]: #plot fft signal 1


plt.xlim(0,0.01)
plt.plot(xf, 2/4000 * np.abs(fsig1))
plt.xlabel('Frequency [Hz]')
plt.ylabel('Amplitude')
plt.show()

1
[14]: #plot fft signal 2
plt.xlim(0,0.01)
plt.plot(xf, 2/4000 * np.abs(fsig2))
plt.xlabel('Frequency [Hz]')
plt.ylabel('Amplitude')
plt.show()

[15]: #plot fft signal 3


plt.xlim(0,0.01)
plt.plot(xf, 2/4000 * np.abs(fsig3))
plt.xlabel('Frequency [Hz]')
plt.ylabel('Amplitude')
plt.show()

[16]: #plot fft signal 4


plt.xlim(0,0.01)
plt.plot(xf, 2/4000 * np.abs(fsig4))
plt.xlabel('Frequency [Hz]')
plt.ylabel('Amplitude')
plt.show()

[17]: #plot fft signal 5


plt.xlim(0,0.01)
plt.plot(xf, 2/4000 * np.abs(fsig5))
plt.xlabel('Frequency [Hz]')
plt.ylabel('Amplitude')

2
plt.show()

[18]: from scipy import signal


#signal square from scipy
freq = 9.
npts = 602
dt_ = 0.090
length = npts * dt_
t_ = np.linspace(0, length, npts, endpoint=False)
square = signal.square(1 * np.pi * freq * t_)

[19]: plt.plot(t_, square)


plt.xlabel('time [sec]')
plt.ylabel('amplitude')
plt.xlim(0, 2.10)
plt.ylim(-2.5, 2.5)
plt.show()

[20]: xf_square = np.linspace(0.0, 1, 301+1)

[21]: fsig5 = np.fft.rfft(square, n=602)

[22]: #plot fft signal 6


plt.plot(xf_square, 2/602 * np.abs(fsig5))
plt.xlabel('Frequency [Hz]')
plt.ylabel('Amplitude')
plt.show()

3
[ ]:

You might also like