2
0
forked from awendt/pyrelacs

[dataio/test] adding a sin producer for testing

This commit is contained in:
wendtalexander
2024-10-07 13:51:46 +02:00
parent 52a0821601
commit aaa42db2ae
3 changed files with 92 additions and 14 deletions

View File

@@ -0,0 +1,53 @@
from math import sin
import time
from PyQt6.QtGui import QAction
import numpy as np
import matplotlib.pyplot as plt
from IPython import embed
from pyrelacs.dataio.circbuffer import CircBuffer
from pyrelacs.util.logging import config_logging
log = config_logging()
# stopbutton: QAction
class SinProducer:
def __init__(
self,
buffer: CircBuffer,
) -> None:
self.buffer = buffer
# self.stopbutton = stopbutton
def produce_sin(
self,
*args,
**kwargs,
) -> None:
AMPLITUDE = 2
FREQUENCY = 10
log.debug("producing Sin")
start_time = time.time()
t = 0
while time.time() - start_time < 2:
s = AMPLITUDE * np.sin(2 * np.pi * FREQUENCY * t)
self.buffer.append(s)
t += 1 / self.buffer.samplerate
time.sleep(1 / self.buffer.samplerate)
data = self.buffer.get_all()
log.debug(data.shape[0])
log.debug(data.shape[0] / self.buffer.samplerate)
# plt.plot(np.arange(data.size) / self.buffer.samplerate, data)
# plt.show()
if __name__ == "__main__":
buf = CircBuffer(1_000_000, 1, samplerate=10000)
pro_sin = SinProducer(buf)
pro_sin.produce_sin()