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 39 40 41 42 43 44 45 46 47
|
<HTML>
<HEAD>
<link rel="stylesheet" href="pygments.css"/>
</HEAD>
<BODY>
# Pweave Example - Frequency response of a moving average filter
[Matti Pastell](http://mpastell.com/)
Create 11 point moving average filter and plot its frequency response and print the values.
<<>>=
from pylab import *
import scipy.signal as signal
#A function to plot frequency and phase response
def mfreqz(b,a=1):
w,h = signal.freqz(b,a)
h = abs(h)
return(w/max(w), h)
@
Make the impulse response function and use terminal formatted output.
<<term = True>>=
n = 11.
n
b = repeat(1/n, n)
b
@
Calculate the frequency response and plot it:
<<fig = True, caption = 'Frequency response of an 11 point moving average filter'>>=
w, h = mfreqz(b)
#Plot the function
plot(w,h,'k')
ylabel('Amplitude')
xlabel(r'Normalized Frequency (x$\pi$rad/sample)')
show()
@
</BODY>
</HTML>
|