From 3a8f61b7b2bdf87ddec1aeeea577193e7c19f9a2 Mon Sep 17 00:00:00 2001 From: jens Date: Mon, 21 Dec 2020 16:05:54 +0100 Subject: [PATCH] - fixed delay --- components/plant/delay.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/components/plant/delay.py b/components/plant/delay.py index 6bd0e40..16a04cb 100644 --- a/components/plant/delay.py +++ b/components/plant/delay.py @@ -4,15 +4,15 @@ import numpy as np class Delay: def __init__(self, dt, delay): nd = int(delay/dt + 0.5) - self.delay_line = np.zeros(nd) + self.delay_line = np.zeros(nd+1) self.ri = 0 self.wi = 0 def put(self, data): - if self.wi >= self.delay_line.size: - self.wi = 0 self.delay_line[self.wi] = data self.wi += 1 + if self.wi >= self.delay_line.size: + self.wi = 0 def get(self): self.ri += 1 @@ -20,12 +20,11 @@ class Delay: self.ri = 0 result = self.delay_line[self.ri] - return result if __name__ == '__main__': - d = Delay(1, 10) + d = Delay(1, 1) for i in range(1, 20): d.put(i)