본문 바로가기

잡다한 것

AvgFilter.py

728x90
반응형
SMALL
import numpy as np
import matplotlib.pyplot as plt
import random

dt = 0.2
t = np.arange(0, 10 + dt, dt)

Nsamples = len(t)

Avgsaved = np.zeros(Nsamples)
Xmsaved = np.zeros(Nsamples)


def GetVolt():
    w = 0 + 4 * random.random()
    z = 14.4 + w
    return z


def AvgFilter(data):
    return np.mean(data)


for k in range(Nsamples):
    xm = GetVolt()
    Xmsaved[k] = xm

    avg = AvgFilter(Xmsaved[:k + 1])
    Avgsaved[k] = avg

plt.figure()
plt.plot(t, Xmsaved, 'r:*', label='Measured')
plt.plot(t, Avgsaved, 'o-', label='Average')
plt.legend()
plt.show()

 

pip install numpy

pip install matplotlib

 

728x90
반응형
LIST

'잡다한 것' 카테고리의 다른 글

삼성 1 제출 불합격  (1) 2023.06.02
할 게 너무 많아요.  (0) 2023.06.01
DDD OT  (0) 2023.05.21
업보청산 - 4(혐주의)  (2) 2023.05.15
업보청산 - 3(혐주의)  (1) 2023.05.10