File: ma-tex.texw

package info (click to toggle)
python-pweave 0.30.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 5,064 kB
  • sloc: python: 30,281; makefile: 167
file content (66 lines) | stat: -rw-r--r-- 1,403 bytes parent folder | download
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
\documentclass[a4paper,11pt,final]{article}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{minted}

\begin{document}

\title{Pweave Example - Frequency response of a moving average filter}
\author{Matti Pastell \\
\url{http://mpastell.com}}

\maketitle

\textbf{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)
@ 

\textbf{Make the impulse response function and use terminal formatted output (=doctest block.)}

<<term = True>>=
n = 11.
n
b = repeat(1/n, n)
b
@


\textbf{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()
@ 



\begin{table}
\caption{The first 10 values of the frequency response (w,h) as a table, notice that the code is hidden in the output document.}
\begin{center}
\begin{tabular}{ c | c }
\hline
\textbf{Amplitude} &  \textbf{Frequency} \\ \hline

<<results = 'rst', echo = False>>=
print 
for i in range(10):
    print (round(h[i],2) , '&',  round(w[i],2), r'\\')
@ 
\end{tabular}
\end{center}
\end{table}

\end{document}