-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnyquist.py
More file actions
31 lines (23 loc) · 748 Bytes
/
nyquist.py
File metadata and controls
31 lines (23 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# import dos modulos necessarios para rodar o script
import numpy as np
import matplotlib.pyplot as plt
# tamanho do sinal
size = 1
f0 = 20 # frequencia do sinal
A = 1 # amplitude do sinal
# funcao lambda para geracao do sinal que
# sera amostrado. Nesse caso uma funcao senoidal
# de frequencia f0 e amplitude A
signal = lambda t : A*np.sin(2*np.pi*f0*t)
s_rate = [10, 20, 40]
for i, N in enumerate(s_rate):
n = np.linspace(0, int(size), N)
plt.subplot(2, len(s_rate), i+1)
plt.plot(n, signal(n), 'r')
plt.stem(n, signal(n))
X = np.fft.fft(signal(n))
f = np.fft.fftfreq(len(X), 1/N)
plt.subplot(2, len(s_rate), len(s_rate)+i+1)
plt.plot(f[:len(X)//2], np.abs(X)[:len(X)//2])
plt.xlim([0,20])
plt.show()