summaryrefslogtreecommitdiff
path: root/day1
diff options
context:
space:
mode:
authorPuneeth Chaganti2010-07-28 19:50:00 +0530
committerPuneeth Chaganti2010-07-28 19:50:00 +0530
commiteac9a591944261c354be17e6779cb9c51adb61f7 (patch)
tree35e5a299aefebe5790bf6775091e4d45b9bf46e0 /day1
parentc4a5344924a16484a9bf53c53666f0af82f696e2 (diff)
downloadworkshops-more-scipy-master.tar.gz
workshops-more-scipy-master.tar.bz2
workshops-more-scipy-master.zip
Added FFT stuff to day1/cheatsheet6.HEADmaster
--HG-- branch : scipy2010
Diffstat (limited to 'day1')
-rwxr-xr-xday1/cheatsheet6.tex62
1 files changed, 61 insertions, 1 deletions
diff --git a/day1/cheatsheet6.tex b/day1/cheatsheet6.tex
index 5d3cfdf..f08b206 100755
--- a/day1/cheatsheet6.tex
+++ b/day1/cheatsheet6.tex
@@ -126,7 +126,67 @@ To solve the ODE, we call the \typ{odeint} function with three arguments - the f
\begin{lstlisting}
In []: y = odeint(f, y0, t)
\end{lstlisting}
-Note: To solve a system of ODEs, we need to change the function to return the right hand side of all the equations and the system and the pass the required number of initial conditions to the \typ{odeint} function.
+Note: To solve a system of ODEs, we need to change the function to
+return the right hand side of all the equations and the system and the
+pass the required number of initial conditions to the \typ{odeint}
+function.
+
+\section{FFT}
+\begin{itemize}
+ \item We have a simple signal $y(t)$
+ \item Find the FFT and plot it
+\end{itemize}
+\begin{lstlisting}
+In []: t = linspace(0, 2*pi, 500)
+In []: y = sin(4*pi*t)
+
+In []: f = fft(y)
+In []: freq = fftfreq(500, t[1] - t[0])
+
+In []: plot(freq[:250], abs(f)[:250])
+In []: grid()
+\end{lstlisting}
+\begin{itemize}
+ \item We now calculate the inverse Fourier transform.
+ \item Then, verify the solution obtained.
+\end{itemize}
+\begin{lstlisting}
+In []: y1 = ifft(f) # inverse FFT
+In []: allclose(y, y1)
+Out[]: True
+\end{lstlisting}
+\begin{itemize}
+\item Let us add some noise to the signal
+\end{itemize}
+\begin{lstlisting}
+In []: yr = y + random(size=500)*0.2
+In []: yn = y + normal(size=500)*0.2
+
+In []: plot(t, yr)
+In []: figure()
+In []: plot(freq[:250],
+ ...: abs(fft(yn))[:250])
+\end{lstlisting}
+\begin{itemize}
+ \item \typ{random}: produces uniform deviates in $[0, 1)$
+ \item \typ{normal}: draws random samples from a Gaussian
+ distribution
+ \item Useful to create a random matrix of any shape
+\end{itemize}
+
+\begin{itemize}
+\item Now, we filter the noisy signal using a Wiener filter
+\end{itemize}
+\begin{lstlisting}
+In []: from scipy import signal
+In []: yc = signal.wiener(yn, 5)
+In []: clf()
+In []: plot(t, yc)
+In []: figure()
+In []: plot(freq[:250],
+ ...: abs(fft(yc))[:250])
+\end{lstlisting}
+
\section{Links and References}
\begin{itemize}
\item Documentation for Numpy and Scipy is available at:\\ http://docs.scipy.org/doc/