-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer.py
More file actions
38 lines (24 loc) · 822 Bytes
/
Copy pathbuffer.py
File metadata and controls
38 lines (24 loc) · 822 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
32
33
34
35
36
37
38
#Bernadelli 2020; clariton.bernadelli@uftm.edu.br; claritonbernadelli@gmail.com
#Circular buffer
import matplotlib.pyplot as plt
import math
class RingBuffer:
def __init__(self, size):
self.data = [None for i in range(size)]
def append(self, x):
self.data.pop(0)
self.data.append(x)
def get(self):
return self.data[::-1] #inverted list
#return self.data #non-inverted list
n = 100 #buffer size
fs = 2000 #sample frequency
f = 200 #signal frequency
sample = 200 #samples
x = [0] * sample #input signal
buf = RingBuffer(n) #An instance of RingBuffer class
for i in range(sample):
buf.append(math.sin(2 * math.pi * f * i / fs)) #buf.append(x) -> x is the signal input
#print(buf.get())
plt.plot(buf.get())
plt.show()