You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
750 B
Python

from pylab import subplot, plot, title, savefig, figure, arange, sin, random #@UnresolvedImport
from sg_filter import calc_coeff, smooth
figure(figsize=(7,12))
# generate chirp signal
tvec = arange(0, 6.28, .02)
signal = sin(tvec*(2.0+tvec))
# add noise to signal
noise = random.normal(size=signal.shape)
signal += (2000.+.15 * noise)
# plot signal
subplot(311)
plot(signal)
title('signal')
# smooth and plot signal
subplot(312)
coeff = calc_coeff(8, 4)
s_signal = smooth(signal, coeff)
plot(s_signal)
title('smoothed signal')
# smooth derivative of signal and plot it
subplot(313)
coeff = calc_coeff(8, 1, 1)
d_signal = smooth(signal, coeff)
plot(d_signal)
title('smoothed derivative of signal')
# show plot
savefig("savitzky.png")