%
% File acl2018.tex
%
%% Based on the style files for ACL-2017, with some changes, which were, in turn,
%% Based on the style files for ACL-2015, with some improvements
%%  taken from the NAACL-2016 style
%% Based on the style files for ACL-2014, which were, in turn,
%% based on ACL-2013, ACL-2012, ACL-2011, ACL-2010, ACL-IJCNLP-2009,
%% EACL-2009, IJCNLP-2008...
%% Based on the style files for EACL 2006 by
%%e.agirre@ehu.es or Sergi.Balari@uab.es
%% and that of ACL 08 by Joakim Nivre and Noah Smith

\documentclass[11pt,a4paper]{article}
\usepackage[hyperref]{acl2018}
\usepackage{times}
\usepackage{latexsym}
\usepackage{amsmath}
\usepackage{url}

\usepackage{tabularx}

\usepackage{graphicx}
\graphicspath{ {graphics/} }

\aclfinalcopy % Uncomment this line for the final submission
%\def\aclpaperid{***} %  Enter the acl Paper ID here

%\setlength\titlebox{5cm}
% You can expand the titlebox if you need extra space
% to show all the authors. Please do not make the titlebox
% smaller than 5cm (the original size); we will check this
% in the camera-ready version and ask you to change it back.

\newcommand\BibTeX{B{\sc ib}\TeX}

\title{Spoken Language Understanding Module for Movie Domain \\ Mid-term project}

\author{Andrea Tupini \\
  MAT.  194578 \\
  {\tt andrea.tupini@studenti.unitn.it}}

\date{}

\begin{document}

\maketitle

\begin{abstract}

	In this work, we build a simple tagger that predicts the IOB tags of words in a sentence. The tagger will be a WFST (weighted finite state machine) model composed with an n-gram model. We'll compare its performance when building it with different smoothing methods and n-gram lengths, and see a very simple change we can do to the data that increases the overall performance of the model.
	\\

\end{abstract}

\section{Introduction}

	A concept tagger is an important part in any SLU pipeline since it lets us tag each input word with the proper tag that tells the rest of the system how to process said word and the ones near it. In the specific system we'll be building, the tagger tells us if a word is to one of a number of concepts about the movie domain (name of a movie, actor, etc) or something else. The tags we'll be working with are in IOB notation, which will be explained a bit in section \ref{sec-data-analysis}.

	This work will be mainly dedicated to constructing and comparing the performance of predicting the correct IOB tags with 2 different models. One uses just a plain word to IOB tag transducer plus an n-gram model of the IOB tags in the train set to predict the correct tags of a test sentence, and the other is practically the same except that we try countering the fact that O tags don't offer us much information. A more detailed explanation of the models will be given in the next section.

\section{Models}

	We want to create a model that, given a sequence of words $w_1, ... , w_n$ finds the most probable tag sequence $t_1, ... , t_n$ where:

	$$
	t_1, ... , t_n = \operatorname*{argmax}_{t_1,...,t_n} P(t_1,...,t_n | w_1,...,w_n)
	$$

	If we apply Bayes's theorem, and take the following simplifications:

	\begin{itemize}
		\item We can remove the denominator (evidence) since it doesn't depend on $t_1,...,t_n$
		\item The probability of a word only depends on its own tag and not the tags of other words
		\item The probability of the tags also depends on the tags near it up to a certain degree (n-gram part of the model)
	\end{itemize}

	We get that:

	$$
	 t_1, ... , t_n = \operatorname*{argmax}_{t_1,...,t_n}
	 \prod_{i=1}^{n} P(w_i | t_i) P(t_i | t_{i-1})
	$$

	where \textit{i} denotes the \textit{i'th} word. Here is a breakdown of the model:

	\begin{description}
		\item[$P(w_i|t_i)$] Is the probability of seeing current word given tag
		\item[$P(t_i|t_{i-1})$] Is the probability of seeing current tag given previous tag (note that this is for a bigram model, but we can consider extra, previous tags, to generalize for any n-gram)
	\end{description}

	To calculate these terms we use the following. Note that since we want to treat $P(w_i|t_i)$ as a score we pass also pass it through a $-log$:

	$$
	P(w_i|t_i) = -\log \frac{C(t_i, w_i)}{C(t_i)}
	$$
	$$
	P(t_i|t_{i-1}) = \frac{C(t_{i-1}, t_i)}{C(t_{i-1})}
	$$

	For unknown words the $P(w_i|t_i)$ term gets calculated a bit differently. An unknown word can be tagged with any tag with equal possibility:

	$$
	P(<unk>|t_i) = \frac{1}{C(t)}
	$$

	So, a transition is added from an unknown keyword to a tag $t_i$ and the probability of said transition is $\frac{1}{total\ amount\ of\ tags}$.

	Based on these assumptions, the following three models were produced to predict the IOB tag of words in a sentence:

	\begin{description}
		\item[Baseline] The baseline model is the most basic model possible and is the one against which we evaluate the performance of the other two models. For the baseline model we consider a \textbf{unigram} model with \textbf{no smoothing}
		\item[Basic
		 Model] This model uses the training set as it is, and is trained to produce IOB tags.
		\item[Improved Model] The improved model is trained on a modified version of the training set: all \textit{O} tags are replaced by \textit{O\_\_word}.
	\end{description}

	For creating the models we use the \textit{OpenFst} \cite{openfst} and \textit{OpenGrm} \cite{opengrm} libraries, which give us helping functions for creating and managing n-gram models and transducers.

	When building the \textit{IOB Model} and \textit{Improved Model} we dynamically find what is the best combination of \textit{n-gram lengths} and \textit{smoothing method} by performing a grid search. We only consider n-gram lengths from 1 to 5 (inclusive) and the smoothing methods that are supported by the \textit{OpenGrm} library (which are: \textit{absolute, katz, kneser ney, presmoothed, unsmoothed and witten bell}).

\section{Data Analysis}
\label{sec-data-analysis}

	The provided data is composed of 4 different files in \textit{NL-SPARQL} format. These are composed of multiple sentences and each word in each sentence is tagged with its IOB tag, POS tag, and lemma. Said files are:

	\begin{description}
		\item[NLSPARQL.test] words and IOB tags for testing
		\item[NLSPARQL.train] words and IOB tags for training
		\item[NLSPARQL.test.feats] words, POS tags and lemmas for testing
		\item[NLSPARQL.train.feats] words, POS tags and lemmas for training
	\end{description}

	The models we'll develop will use the \textit{test} and \textit{train} files, but we'll also briefly visit the \textit{train.feats} file to see the distribution of POS tags in the data.

	As said above, the data we'll use is composed of words and IOB tags. IOB tags (Inside-Outside-Beginning) use the concept of a span, which lets us know when a word marks the beginning of a concept (tag B), when it is a word inside of a concept (tag I) and when the word is simply outside of the concept (tag O). Besides this, the tag also tells us what the concept is about: movie name, actor, etc (all tags relating to the movie domain). Following is an example of what a sentence looks like in the dataset:

	\begin{table}[h]
		\begin{tabularx}{198pt}{l | l}
			\centering
	 	 	\textbf{Word} & \textbf{Tag} \\
			\hline
			who & O \\
			plays & O \\
			luke & B-character.name \\
			on & O \\
			star & B-movie.name \\
			wars & I-movie.name \\
			new & I-movie.name \\
			hope & I-movie.name \\
 		\end{tabularx}
		\caption{Example sentence in train set}
		\label{table:example-sentence}
	\end{table}

	In the data, we have a total of \textit{41} different tags, one of which is just the O tag, and the rest are \textit{20} matching B and I tags. Following is a bar plot of the tags ordered by their counts, note that the counts are scaled with \textit{log} so it's easier to see the value of other tags besides the O:

	\hspace*{-0.4cm}\includegraphics[scale=0.5]{barplot_iob_tag_counts}

	As we can see, the great majority of tags is simply O. In the training data there are a total of \textit{21,453} tagged words, of which \textit{15,391} are O tags, that is the \textit{71.74}\% of all tags. This is because most of the words are just filler words that link a concept with another or are words that say what is wanted but don't represent a concept per se. This makes sense but it will be a bit of a problem when we're "training" our tagger since O's don't tell us much about the word itself and a word can appear multiple times and can be tagged with either O, B or I tag, introducing possible errors. In fact, the only difference between the normal model and the improved one is that in the improved model the O's get replaced by \textit{O\_\_word} so that we preserve the word's information in the tag. As we'll see later, this simple change notably improves the performance of the model.

	As for the sentences per se, they're queries like the example sentence presented in \textit{Table \ref{table:example-sentence}} which ask some information about the movie domain. There are a total of \textit{1,728} distinct words in the training set, following we can see a bar plot of the 30 most common words and their counts:

	\hspace*{-0.9cm}\includegraphics[scale=0.7]{barplot_iob&w_tag_counts_onlyW}

	As expected, the list of most common words is a composition between stopwords (the, of, in, is, a, etc), move domain-specific words (movies, movie, show, director, etc) and words that represent a query (who, find, show, how, etc). We can see that the words \textit{the} and \textit{movies} appear quite a bit more times than any other word in the set.

	As mentioned above, we also have access to the POS tags of each word. Below we can see a bar plot which shows all of the POS tags and their counts:

	\hspace*{-0.7cm}\includegraphics[scale=0.6]{barplot_pos_counts}

	We can see that most words are actually nouns (by quite a bit), these are the things we're referring to (ie: names of movies, actors, characters). The second most common tag is the \textit{IN} tag which denotes preposition; these tell us the relation between the objects (nouns). Other important tags which appear very frequently are the \textit{WP} and \textit{VV} tags which denote pronouns of the forms \textit{who, what, which} and verbs like \textit{find, show} respectively; this is to be expected considering that the set is composed of queries about the movie domain.

\section{Evaluation}

	An "evaluation" pipeline was set up to evaluate the performance of the modes. This consists of running the trained model on the test set and generating a file that holds all the predictions, then the actual metrics are computed with the \textit{Conlleval} script\footnote{The Conlleval script was originally created to evaluate the performance of models for the CoNLL-2000 shared task, but we can also use it to evaluate our models.}, which gives us various metrics (specifically the \textit{accuracy, precision, recall, and F1}), but we'll only use the \textit{F1} metric to evaluate the performance.

\subsection{Baseline}

	As said in the \textit{Models} section, the baseline model is just a transducer from word to IOB tag and an unsmoothed, unigram model.

	\begin{description}
		\item[Baseline F1 Score:] \textit{57.07}
	\end{description}

\subsection{Basic Model}

	The IOB model is trained on the training set as it's provided. Multiple models were constructed, one for each combination of n-gram length and smoothing methods. Below is a heatmap with the scores of each combination. The \textit{order} axis represents the n-gram length and the \textit{method} axis the smoothing method used, the value in each cell is the F1 score obtained when evaluating the model's prediction on the test set.

	\hspace*{-1cm}\includegraphics[scale=0.6]{scores_heatmap_w2iob}

	As we can see, the model didn't have a very good performance when using a unigram length, but even so, these are better than the baseline model. For all other n-gram lengths, it seems that the score does not vary so much from one length to the other. There is also no smoothing algorithm that is consistently better than the others, but it seems that for models with higher n-gram lengths tend to perform better. Following are the 3 best F1 scores obtained for the basic model.

	\begin{table}[h]
		\centering
		\begin{tabularx}{155pt}{l | c | c}

			\textbf{Method} & \textbf{Order} & \textbf{F1 Score} \\
			\hline
			kneser ney & 4 & 76.39 \\
			\hline
			witten bell & 2 & 76.37 \\
			absolute & 4 & 76.34 \\

		\end{tabularx}
		\caption{Best \textit{Basic Model} F1 Scores}
		\label{table:basic-method-scores}
	\end{table}

\subsection{Improved Model}

	The improved model was trained on a slightly modified version of the training set. Since plain \textit{O} tags don't give much information to the model about the word they're supposed to 'tag' these have been replaced with \textit{O\_\_word}. Basically, the model predicts all tags, except the O ones, in the same way as the basic model, but instead of predicting O tags it now predicts the word per se (replacing \textit{O} with \textit{O\_\_word} is actually the same as replacing \textit{O} with \textit{word}). By doing this simple change we give much information that the model can leverage during prediction. Below is a heatmap of the scores obtained using this improved model:

	\hspace*{-0.6cm}\includegraphics[scale=0.6]{scores_heatmap_w2iob__w}

	If we compare these scores with the ones obtained by the basic model we can notice that the scores for the unigram length in the improved model are always lower than the ones in the basic model, but all the other scores are higher in the improved model. This makes sense since by replacing the \textit{O} with \textit{O\_\_word} we're introducing more complexity in the data, which can only be properly understood by the model if it considers the context in which said new tags appear. Also, by comparing the improved model's scores with the baseline score we can see that all unigram lengths have a lower F1 but every other combination yields a higher one. Below is a table of the combinations which yielded the best F1 score in the improved model:

	\begin{table}[h]
		\centering
		\begin{tabularx}{155pt}{l | c | c}

			\textbf{Method} & \textbf{Order} & \textbf{F1 Score} \\
			\hline
			kneser ney & 4 & 82.74 \\
			\hline
			kneser ney & 5 & 82.43 \\
			kneser ney & 3 & 82.04 \\

		\end{tabularx}
		\caption{Best \textit{Improved Model} F1 Scores}
		\label{table:improved-method-scores}
	\end{table}

	An interesting thing to note is that, in both models, the best combination stayed the same (\textit{kneser ney} and \textit{4}-gram). It seems that in this improved, more complex, model the \textit{kneser ney} method consistently has a better performance for each n-gram length (except for the unigram case in which all scores are the same). By using this improved model we get an improvement of 6.35\% with respect to the basic one.

\section{Future Work}

	For reasons of time or scope, there are some other possible improvements we can do to the model that have not been explored in this work. This section will mention some of them in case anyone else is interested in trying them or for future research.

	The first possible change that could be worth looking into is mixing in the POS tags with either the words (ie: \textit{word\_\_pos}) or as an extension to the IOB tags (possibly compose them in the same way as we did with \textit{O\_\_word}). This raises the question of how does the performance vary when we add extra information to the words or to the tags. Another thing that might be interesting finding out is if extending the other IOB tags with words as was done with the O tag would increase or decrease the performance of the model. We could also leverage the fact that we have the lemmas in the dataset and try to see if these can be composed with the words or the tags either alone or together with the POS tags.

	A certain increase in performance could be obtained by transforming our tags from \textit{IOB} format to \textit{BILUO} format (Begin, In, Last, Unit, Out) format, which is as expressive as BIO but has been demonstrated in \cite{DesignChallenges} to be much easier for the model to learn. Even so, it would be interesting to see if extending the O tags in this new format would produce an increase in performance as it did for the IOB one.

\section{Conclusion}

	In this work, we've explored a way in which to build an automatic IOB tagger, train it on some data and predicting the actual tags. We've seen that O tags don't provide much information and the model has a hard time actually learning to differentiate when an O tag is the one that should be predicted and when not. To solve this problem we've added more information to the O tag by extending it with the word it is tagging, in doing so we've practically replaced the O with $\#words$ new tags. After this, the model seemed to be able to learn the correct mapping more efficiently.

	We've also analyzed various combinations of smoothing methods and n-gram lengths and compared how all their possible combinations affected the final performance of the model. We've seen that for both models the \textit{knesser ney} smoothing together with a \textit{4-gram} underlying model is the combination that works best. In the case of the second model in which we had more complexity on the \textit{tag} side, \textit{knesser ney} smoothing produced the best 3 results, so it might be that this smoothing method is especially useful when there is high variation in the data (although more research should be done to attest that this is actually the case).

% include your own bib file like this:
\bibliographystyle{plain}
%\bibliography{acl2018}

%\bibliographystyle{plainnat}
\bibliography{bibliography}

%\bibliographystyle{acl_natbib}

\end{document}


%\documentclass[10pt]{beamer} % aspect ratio 4:3, 128 mm by 96 mm
%\documentclass[10pt,aspectratio=169]{beamer} % aspect ratio 16:9, only frames
\documentclass[10pt,aspectratio=169,notes]{beamer} % aspect ratio 16:9, frames+notes
%\documentclass[10pt,aspectratio=169,notes=only]{beamer} % aspect ratio 16:9, notes only
\usepackage{pgfpages}
%\setbeameroption{show notes}
%\setbeameroption{show notes on second screen=right}
%\setbeameroption{show notes on second screen=bottom} % does not work for animations

%\graphicspath{{../../figures/}}
\graphicspath{{figs/}}
%\includeonlyframes{frame1,frame2,frame3}
%\includeonlyframes{frame10}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Packages
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{appendixnumberbeamer}
\usepackage{booktabs}
\usepackage{csvsimple} % for csv read
\usepackage[scale=2]{ccicons}
\usepackage{pgfplots}
\usepackage{xspace}
\usepackage{amsmath}
\usepackage{totcount}
\usepackage{tikz}
\usepackage{bm}
%\usepackage{FiraSans}
\usepackage{mathrsfs} % for Fourier and Laplace symbols
\usepackage{verbatim}
%\usepackage{eulervm} % alternative math fonts
%\usepackage{comment}
\usetikzlibrary{external} % speedup compilation
%\tikzexternalize % activate!
%\usetikzlibrary{shapes,arrows}
% the animations are only supported by some pdf readers (AcrobatReader, PDF-XChange, acroread, and Foxit Reader)
\usepackage{animate}
\usepackage{ifthen}
\newcounter{angle}
\setcounter{angle}{0}
%\usepackage{bibentry}
%\nobibliography*
\usepackage{caption}%
\captionsetup[figure]{labelformat=empty}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Metropolis theme custom modification file
\input{metropolis_mods.tex}
%\usefonttheme[onlymath]{Serif}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Custom commands
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% matrix command
%\newcommand{\matr}[1]{\mathbf{#1}} % bold upright (Elsevier, Springer)
%  metropolis compatible (FiraSans auto replacement)
\newcommand{\matr}[1]{\boldsymbol{#1}}
%\newcommand{\matr}[1]{#1}          % pure math version
%\newcommand{\matr}[1]{\bm{#1}}     % ISO complying version
% vector command
%\newcommand{\vect}[1]{\mathbf{#1}} % bold upright (Elsevier, Springer)
% metropolis compatible (FiraSans auto replacement)
\newcommand{\vect}[1]{\boldsymbol{#1}}
% bold symbol
\newcommand{\bs}[1]{\boldsymbol{#1}}
% derivative upright command
\DeclareRobustCommand*{\drv}{\mathop{}\!\mathrm{d}}
\newcommand{\ud}{\mathrm{d}}
\newcommand{\myexp}{\mathrm{e}}
%
\newcommand{\themename}{\textbf{\textsc{metropolis}}\xspace}
\renewcommand{\Re}{\operatorname{\mathbb{R}e}}
\renewcommand{\Im}{\operatorname{\mathbb{I}m}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  Title page options
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \date{\today}
\date{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% option 1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\title{Application of Fourier transform in selected problems of mechanics, signal processing and imaging}
\subtitle{Lecture Series}
\author{\textbf{Paweł Kudela} }
% logo align to Institute
\institute{Institute of Fluid Flow Machinery\\Polish Academy of Sciences \\ \vspace{-1.5cm}\flushright \includegraphics[width=4cm]{//odroid-sensors/sensors/MISD_shared/logo/logo_eng_40mm.eps}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\tikzexternalize % activate!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\maketitle
%%%%%%%%%%%%%%%%%%%%
\note{My name is Pawel Kudela.
I am an associate professor at the Institute of Fluid Machinery, Polish Academy of Sciences.
I will give you a few lectures in the frame of the doctoral school.
Today's topic is a Fourier transform.
You can look at the Fourier transform from various perspectives such as mathematical formula or numerical algorithm.
But my intention is to give you some intuition about the mathematics behind the Fourier transform and look at it from engineer perspective so you can confidently use it as a tool in your particular problem.
I will be using Matlab to illustrate examples of practical applications of the Fourier transform.}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SLIDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[label=frame1]{Table of contents}
  \setbeamertemplate{section in toc}[sections numbered]
  \tableofcontents[hideallsubsections]
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{I will start with the \textbf{Fourier series}, then mathematical formulation of the \textbf{Continuous Fourier Transform}.
Next, I will move to the \textbf{Discrete Fourier Transform}.
I will cover also inverse Fourier Transform.
Then, I will explain how to apply Fourier transforms to selected problem of mechanics which will be \textbf{Heat transfer problem}.
Finally I will show you a few examples of \textbf{Signal filtering} and \textbf{Image processing}.
At the end you will be given an \textbf{Assignment} so I encourage you to listen carefully.}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Fourier Series}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[label=frame2]{Jean-Baptiste Joseph Fourier}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{columns}[T]
  \column{0.5\textwidth}
		Jean-Baptiste Joseph \alert{Fourier} 1768--1830
		 \begin{itemize}
			\item Mathematician
			\item Physicist
			\item \emph{The Analytic Theory of Heat}
			\item Fourier series
			\item Fourier transform
		\end{itemize}
  \column{0.5\textwidth}
  	\begin{figure}
  		\includegraphics[width=0.7\textwidth]{Fourier2.jpg}
  	\end{figure}
\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{Jean-Baptiste Joseph Fourier was a French mathematician and physicist best known for initiating the investigation of Fourier series.
Fourier, the son of a tailor, first attended the local military school conducted by Benedictine monks.
It is said that he saved wax from the candle ends so that he could study at night.
He showed such proficiency in mathematics in his early years that he later became a teacher in mathematics at the same school.
As a student, he received lessons from eminent teachers like Lagrange, Laplace and Monge.
After passing out from school, he entered the Benedictine abbey with the intention of becoming a priest.
However, he slowly became involved in politics; joined the local Revolutionary Committee.
He was imprisoned briefly during the French Revolution.
In 1798 Fourier accompanied Napoleon on his expedition to Egypt.
He was engaged in extensive research on Egyptian antiquities, gave advice on engineering and diplomatic undertakings.
On his return, Napoleon appointed him Prefect (Governor) of the Department of Is\`{e}re in Grenoble.
He showed great administrative ability while continuing his Egyptological and mathematical work.
At that time, he began to experiment on the propagation of heat.
And here our story begins.
 }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Fourier's idea}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{equation*}
\frac{4}{\pi}\left( \frac{\cos \pi x}{1} - \frac{\cos (3 \pi x) }{3} + \frac{\cos (5 \pi x)}{5} - \frac{\cos (7 \pi x)}{7} +  \ldots \right) = \left\{ \begin{array}{rll} 1& \mathrm{if} & x<0.5\\ 0 & \mathrm{if}& x=0.5\\ -1& \mathrm{if} & x>0.5 \end{array} \right.
\end{equation*}
\begin{columns}[T]
	\column{0.5\textwidth}
	\centering
		% 3 frames per second
		%\animategraphics[controls,loop,autoplay]{3}{Fourier_series_}{1}{25}
		\animategraphics[loop,autoplay]{3}{Fourier_series_}{1}{25}
		%	\animategraphics[controls,loop,autoplay,width=\linewidth]{3}{Fourier_series_}{1}{25}
	\column{0.5\textwidth}
	\centering
			\includegraphics{step_function}
	\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{Fourier was obsessed with the physics of heat and developed the Fourier series and transform to model heat-flow problems.
He had an idea that any periodic function can be rewritten as a weighted sum of sines and cosines of different frequencies.
On the right hand side is a step function.
The step function can be approximated by Fourier series.
However, we are restricted by boundary conditions.
In this case only cosine components are necessary.
For other boundary conditions, we may need to use sine components as well.
The more the Fourier series elements we take, the more accurate representation of the step function is achieved.
Therefore, the equation above holds true if the infinite sum is applied.
It should be noted that we had to add a point at discontinuity in the middle of the step function jump.
In summary, the infinite sum of wavy continous functions can equal a discontinous flat function like this.
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Heat flow}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	\begin{equation*}
T(x,t)=	\frac{4}{\pi}\left( \frac{\cos \pi x}{1} \, \myexp^{-\alpha 1^2 t} - \frac{\cos (3 \pi x) }{3} \, \myexp^{-\alpha 3^2 t} + \frac{\cos (5 \pi x)}{5} \, \myexp^{-\alpha 5^2 t}  -   \ldots \right)
	\end{equation*}
	\begin{columns}[T]
		\column{0.5\textwidth}
		\centering
		% 2 frames per second
		\animategraphics[controls,loop]{2}{Fourier_series_rod_temperatures_}{1}{27}
		\column{0.5\textwidth}
		Fourier series converges to the exact solution when the number of added terms goes to \(\infty\) and if the function satisfies so-called Dirichlet boundary conditions (values that a solution needs to take along the boundary of the domain).
	\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{Let's assume that you brought two rods with uniform temperatures and you want to know what happens immediately after they come into contact.
To make the numbers simple let's assume that the temperature of left rod is 1 degree and the right rod is negative 1 degree and the total length of combine rods is 1.
It means that our initial temperature distribution is the step function.
So, when we take the heat equation solution associated with these cosine waves and add infinitely many of them we do get exact solution describing how the step function will evolve over time.
Here, I have taken 250 sums in Fourier series.
It can be noted that in engineering applications, the Fourier series is generally presumed to converge everywhere except at discontinuities.
The key challenge is to find coefficients which stays besides sine and cosine terms.
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Fourier series definition}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Fourier series can be written in a general form:
\begin{equation*}
s_N(x)=	\frac{a_0}{2} + \underbrace{ \sum \limits_{n=1}^N a_n \cos \left(\frac{2 \pi n x}{P} \right)}_{\mathrm{even \, component}} +  \underbrace{\sum \limits_{n=1}^N b_n \sin \left( \frac{2 \pi n x}{P} \right)}_{\mathrm{odd \, component}}
\end{equation*}
where \(P\) is the interval length (period of the Fourier series) and \(N\) is theoretically \(\infty\).\\
Fourier coefficients are:
	\begin{equation*}
		a_0= \frac{1}{P}	\int_P s(x) \ud x \quad  a_n= \frac{2}{P}	\int_P s(x)\, \cos \left(2 \pi x \frac{n}{P}\right) \ud x \quad 	b_n= \frac{2}{P}	\int_P s(x)\, \sin\left(2 \pi x \frac{n}{P}\right) \ud x
	\end{equation*}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{The formal definition of Fourier series expansion is a sum of infinite number of even and odd components.
Even components are cosine terms multiplied by \(a_n\) and odd components are sine terms multiplied by \(b_n\).
There is also additional \(a_0\) coefficient in front.
P is the interval length (period of the Fourier series).
\(a_0\) , \(a_n\) and \(b_n\) are Fourier coefficients which can be calculated by using these formulas.
The derivation of Fourier coefficients can be found in any textbooks so I will skip it here.
But as you can see, it is quite easy to find Fourier coefficients of the function \(s(x)\) and approximate this fuction by Fourier series.
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Continuous Fourier Transform}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile,label=frame3]{Continuous Fourier Transform - definition}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	\begin{equation*}
	F(\omega) = \int \limits_{-\infty}^{\infty} f(t)\, \myexp^{-i \omega t} \ud t
	\end{equation*}
	where \(i=\sqrt{-1}\) denotes imaginary component\\
Other notations
	\begin{equation*}
	\hat{f}(\omega) = \int \limits_{-\infty}^{\infty} f(t)\, \myexp^{-i \omega t} \ud t
	\end{equation*}
	\begin{equation*}
	\mathscr{F}\{E(t)\}= 	\left(\mathscr{F} E \right)(\omega)=\mathcal{F} \left[E(t) \right](\omega) =\tilde{E}(\omega) =  \int \limits_{-\infty}^{\infty} E(t)\, \myexp^{-i \omega t} \ud t
	\end{equation*}
The Fourier transform can be denoted by:\\
 \(\mathcal{F}\) which can be produced in LaTeX by: \verb+\mathcal{F}+\\
\(\mathscr{F}\) which can be produced in LaTeX by: \verb+\mathscr{F}+\\

\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{\(F\) with the argument \(\omega\) is called the Fourier transform of function \(f\) with the argument \(t\).
\(i\) is the square root of negative one which denotes imaginary components.
In this definition function under integral is denoted by lower case letter wheres the transform is denoted by upper case letter.
You can also find  in the literature other notations.
For example if you want to use the same lower case letter, for distinction of the transform, hat over the letter is placed.
In case of capital letter under integral, Fourier transform can be denoted by fancy symbol F.
It can be produced in LaTeX like this.
It is an operator applied to function \(E(t)\); also the resulting domain \(\omega\) can be specified.
Eventually, tilde over upper case letter can be used.
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[label=frame4]{Forward and inverse Fourier transform}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{columns}[T]
	\column{0.5\textwidth}
	\centering
	Forward\\
	\begin{equation*}
	\hat{f}(\omega) = \int \limits_{-\infty}^{\infty} f(t)\, \myexp^{-i \omega t} \ud t
	\end{equation*}
	\begin{equation*}
	\mathcal{F} \left[f(t) \right](\omega)=\int \limits_{-\infty}^{\infty} f(t)\, \myexp^{-i \omega t} \ud t
	\end{equation*}
	\begin{equation*}
	f(t) \rightarrow \mathcal{F} \left[f(t) \right] \quad  \textrm{or:} \quad f(t)  \rightarrow F(\omega)
	\end{equation*}
	\begin{equation*}
	f(t) \xrightarrow{\mathcal{F}} \hat{f}(\omega)
	\end{equation*}
	Mapping between the time domain \(t\) \\and the frequency domain \(\omega\)
	\column{0.5\textwidth}
	\centering
	Inverse\\
	\begin{equation*}
	f(t) = \frac{1}{2 \pi} \int \limits_{-\infty}^{\infty} \hat{f}(\omega)\, \myexp^{i \omega t} \ud t
	\end{equation*}
    \begin{equation*}
    \mathcal{F}^{-1} \left[F(\omega) \right](t)=\frac{1}{2 \pi}  \int \limits_{-\infty}^{\infty} F(\omega)\, \myexp^{i \omega t} \ud t
	\end{equation*}
	\begin{equation*}
	F(\omega) \rightarrow \mathcal{F}^{-1} \left[F(\omega) \right] \quad   \textrm{or:} \quad 	F(\omega) \rightarrow f(t)
	\end{equation*}
	\begin{equation*}
	\hat{f}(\omega) \xrightarrow{\mathcal{F}^{-1}}  f(t)
	\end{equation*}
	Mapping between the frequency domain  \(\omega\) \\and the time domain \(t\)

\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{Fourier transform is an equation.
It is a result of a transformation or mapping between one domain and another domain.
In the presented example, the Forward Fourier transform is a mapping between the time domain \(t\) and the frequency domain \(\omega\).
The Inverse Fourier transform is a mapping  between the frequency domain  \(\omega\) and the time domain \(t\).
All of these notations can be used interchangeably.
I like the last one with the Fourier transform symbol over an arrow.

If you look carefully at these equations you will see some differences.
In the forward Forward Fourier transform the exponent term is negative, whereas in the Inverse Fourier transform the exponent term is positive.
Furthermore, in the inverse Fourier transform we have additional scaling factor: one over two pi.
It is important to note that in both cases the integral interval is \((-\infty, \infty)\).
It should be also added that \(f\) and \(\hat{f}\) are in general complex functions.
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile,label=frame5]{Intuition behind Fourier transform}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{columns}[T]
	\begin{column}{0.5\textwidth}
	\begin{animateinline}[loop, poster = 45, controls]{30}
		%
		\whiledo{\theangle<359}{
			%
			\begin{tikzpicture}
			% Axis
			\draw[thick,->,logoblue] (-3,0)--(3,0) node[below] {$\Re$}; % x axis
			\draw[thick,->,logoblue] (0,-3)--(0,3) node[left] {$\Im$}; % y axis
			\draw[logoblue,thick] (0,0) circle (2.5cm);
			\node[logoblue,below] at (2.6,0) {1};
			\node[logoblue,above] at (0.12,2.5) {1};
			%
			%\draw[ultra thick,cyan] (0,0) -- (0,0 |- \theangle:2.5cm); % UpOn x axis
			\draw[ultra thick,orange] (0,0) -- (\theangle:2.5cm |- 0,0); % UpOn y axis
			%
			\draw[ultra thick,cyan] (\theangle:2.5cm) -- (\theangle:2.5cm |- 0,0); % vertical line
			\draw[densely dotted,cyan] (\theangle:2.5cm) -- (0,0 |- \theangle:2.5cm); % horizontal line
			\draw[ultra thick,red,->,rotate=\theangle] (0,0) -- (2.5,0);
			\draw[->,semithick,green] (0:0.9cm) arc[radius=0.9, start angle=0, end angle=\theangle]; % phase angle
			\node[green,right] at (0.2,0.2) {$\phi$}; % psi symbol
			\node[red,orange,right] at (0,-3.5)
			{%\footnotesize$\cos(\theangle^{\mathrm{o}}) = \pgfmathcos{\theangle}\pgfmathresult$
			};
			\node[red,cyan,right] at (0,-3.1)
			{%\footnotesize$\sin(\theangle^{\mathrm{o}}) = \pgfmathsin{\theangle}\pgfmathresult$
			};
			\end{tikzpicture}
			%
			\stepcounter{angle}
			\ifthenelse{\theangle<359}{
				\newframe
			}{
			\end{animateinline}
		}
	}
\end{column}
	\begin{column}{0.5\textwidth}
	\begin{equation*}
	F(\omega) = \int \limits_{-\infty}^{\infty} f(t)\, \myexp^{-i \omega t} \ud t
	\end{equation*}
	Euler's formula \(\myexp^{-i \omega t} = \cos (\omega t) - i \sin(\omega t)\)
	\begin{equation*}
	F(\omega) = \int \limits_{-\infty}^{\infty} f(t) \left[\cos (\omega t) - i \sin(\omega t) \right] \ud t
	\end{equation*}
	\begin{equation*}
	F(\omega) = \color{orange} \int \limits_{-\infty}^{\infty} f(t) \cos (\omega t)  \ud t \, - \, \color{cyan}  i   \int \limits_{-\infty}^{\infty}  f(t) \sin(\omega t)  \ud t
	\end{equation*}
	\begin{equation*}
		\color{red} A = \sqrt{\Re^2 + \Im^2}
		\label{eq:Fourier_magnitude}
	\end{equation*}
	\begin{equation*}
	\color{green}  \phi = \tan^{-1} \frac{\Im}{\Re}
	\label{eq:Fourier_phase}
	\end{equation*}
	\end{column}
\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{In order to have better intuition of the Fourier transform, let's substitute Euler's formula to the Fourier transform definition.
Now, we can split integral into two parts: real and imaginary.
Under integral we have a function \(f(t)\) which we want to transform which is multiplied by some analysing function.
The analysing function is cosine in case of real part and sine in case of imaginary part.
The interpretation of the integral over function is the area.
Therefore, we can calculate area of the real part and imaginary part separately and place them on complex plain.
The magnitude of the Fourier transform, denoted in the figure by red arrow, can be calculated by using the formula given in red colour.
The phase of the Fourier transform fi \(\phi\) is an angle denoted in the figure by a green arrow and can be calculated by using the formula given in green colour.
Of course, real part and imaginary part can also be negative.
Therefore, the magnitude arrow can be on any qurter of complex plane as it is shown on the animation.
Hence, to identify appropriate quarter, the information about phase can be used.
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Fourier series vs Fourier transform (1)}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Fourier coefficients are:
\begin{equation*}
a_n= \frac{2}{P}	\int_{\textcolor{green}{P}} s(t)\, \cos \left(2 \pi t \frac{\textcolor{red}{n}}{\textcolor{red}{P}}\right) \ud t \quad 	b_n= \frac{2}{P}	\int_{\textcolor{green}{P}} s(t)\, \sin\left(2 \pi t \frac{\textcolor{red}{n}}{\textcolor{red}{P}}\right) \ud t
\end{equation*}
Forward Fourier transform:
\begin{equation*}
S(\omega) =  \int \limits_{-\infty}^{\infty} s(t) \cos (\omega t)  \ud t \, - \,  i   \int \limits_{-\infty}^{\infty}  s(t) \sin(\omega t)  \ud t
\end{equation*}
\(\omega = 2 \pi f\)
\begin{equation*}
S(\textcolor{red}{f}) =  \int \limits_{\textcolor{green}{-\infty}}^{\textcolor{green}{\infty}} s(t) \cos (2 \pi t \textcolor{red}{f})  \ud t \, - \,  i   \int \limits_{\textcolor{green}{-\infty}}^{\textcolor{green}{\infty}}  s(t) \sin(2 \pi t \textcolor{red}{f})  \ud t
\end{equation*}
\(P\rightarrow \infty\) \url{https://dspillustrations.com/pages/posts/misc/the-complex-fourier-series-and-its-relation-to-the-fourier-transform.html}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{
Let's recall the definition of Fourier coefficients.
I have replaced \(x\) argument from the previous definition by \(t\).
Let's recall the forward Fourier transform and substitute the definition of angular frequency.
Now similarities between Fourier series coefficients and Fourier transform are obvious.
The difference is that instead of \(n/P\) we have frequency \(f\) and instead of integration interval \(P\) we have \((-\infty, \infty)\).

The Fourier transform can be viewed as the limit of the Fourier series of a function when the period approaches to infinity, so the limits of integration change from one period to \((-\infty, \infty)\).

You can find more details about it under this link.
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Fourier series vs Fourier transform (2)}
\begin{columns}[T]
	\begin{column}{0.5\textwidth}
		\textbf{Fourier series}
		\begin{itemize}
		\item Periodic function \(\Rightarrow\) converts into a \emph{discrete} sine and cosine function
		\item Non-periodic function \(\Rightarrow\) not applicable
		\end{itemize}
	\end{column}
	\begin{column}{0.5\textwidth}
		\textbf{Fourier transform}
		\begin{itemize}
			\item Periodic function \(\Rightarrow\) transforms its Fourier series into the frequency domain
			\item Non-periodic function \(\Rightarrow\) transforms it into continuous frequency domain
			\end{itemize}
	\end{column}
\end{columns}
\vspace{10mm}
\begin{block}{Periodic function}
A periodic function is a function that repeats its values in regular intervals or periods.
\end{block}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{These findings can be summarized as follows.
Fourier series is used to convert periodic function into discrete function as a sum of sines and cosines.
The word \emph{discrete} is debatable from mathematical point of view because of function jumps at discontinouities.
I would say that from a point of view of an engineer, the resulting function is continous because it is a sum of continous functions.
Fourier series cannot be applied to non-periodic functions.

Fourier transform is used to transform periodic and non-periodic signals from the time domain to the continuous frequency domain.
It can also transform Fourier series into the frequency domain, as Fourier series is nothing but a simplified form of the time domain periodic function.
So, the Fourier transform is more general.
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Discrete Fourier Transform}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Discrete Fourier Transform}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{center}
Given \(N\) values \(u_0,\cdots, u_{N-1}\), the following holds:
\end{center}
\begin{columns}[T]
	\begin{column}{0.5\textwidth}
		\textbf{Discrete Fourier transform (DFT)}
		\begin{equation*}
		\hat{u} _k = \sum \limits_{j=0}^{N-1} u_j \myexp^{-i 2 \pi j k/N}
		\end{equation*}
	\end{column}
	\begin{column}{0.5\textwidth}
		\textbf{Inverse discrete Fourier transform (IDFT)}
		\begin{equation*}
		u _j = \frac{1}{N}\sum \limits_{k=0}^{N-1} \hat{u}_k \myexp^{i 2 \pi j k/N}
		\end{equation*}
	\end{column}
\end{columns}
\begin{block}{Fast Fourier transform}
A fast Fourier transform (FFT) is an algorithm that computes the discrete Fourier transform (DFT) of a sequence, or its inverse (IDFT).
The algorithm manages to reduce the complexity of computing the DFT from \(O\left(N^{2}\right)\),  to \( O\left(N\log N\right)\), where \(N\) is the data size.
\end{block}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{So far I talk about continuous Fourier transform.
However, most often you will use discrete Fourier transform or rather its numerical implementation.
Given \(N\) values \(u_0,\cdots, u_{N-1}\), the following holds:
The first equation gives the discreter Fourier transform of the sequence \(\{u_j\}\);
the second gives the inverse discrete Fourier transform of the sequence \(\{\hat{u}_k\}\). \(u_j\) and \( \hat{u}_k \) are in general complex.
Note that although the formulae in these equations define the direct and inverse DFTs, they are almost never used to calculate them.
The reason is that they are computationally inefficient for large \(N\).
Instead, an elegant algorithm called Fast Fourier Transform (FFT in short) is used.
This is really just a clever way of re-arranging the multiplications and sums using the properties of the exponential function, to reduce the total number of arithmetic operations.
The algorithm manages to reduce the complexity of computing the DFT from \(O\left(N^{2}\right)\),  to \( O\left(N\log N\right)\), where \(N\) is the data size.
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Discrete Fourier Transform in MATLAB}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{columns}[T]
	\begin{column}{0.5\textwidth}
		\textbf{Discrete Fourier transform (DFT)}
		\begin{equation*}
		U (k) = \sum \limits_{j=1}^{N} u(j) \,\myexp^{-i 2 \pi (j-1) (k-1)/N}, \quad k=1\ldots N
		\end{equation*}

		\begin{verbatim}
		U = fft(u)
		\end{verbatim}
	\end{column}
	\begin{column}{0.5\textwidth}
		\textbf{Inverse discrete Fourier transform (IDFT)}
		\begin{equation*}
		u(j) = \frac{1}{N}\sum \limits_{k=1}^{N} U(k)\, \myexp^{i 2 \pi (j-1) (k-1)/N}, \quad j=1\ldots N
		\end{equation*}

		\begin{verbatim}
		u = ifft(U)
		\end{verbatim}
	\end{column}
\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{Vectors and matrices in some programming languages (including MATLAB) start at index 1 instead of 0.
Therefore, the following formulae were implemented in MATLAB by using the FFT.
Note that lower case letter and upper case letter u are used in appropriate places.
Also indices \(j\) and \(k\) are placed in round brackets which is compliant with MATLAB notations.
The index \(k\) denotes sample number and the index \(j\) denotes harmonic number.
fft and ifft commands are used in MATLAB for disrete Fourier transform and inverse discrete Fourier transform, respectively.
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Interpretation of variables}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
displacements - sequence \( u(j) = u_1, u_2, \ldots, u_{N}\)\\
corresponding spatial coordinates:
\begin{equation*}
x(j) = x_{start} +(j-1)  \Delta x, \quad j=1 \ldots N
\end{equation*}
The sequence  \( u(j) \) is a \alert{sampling} of the physical quantity in \(N\) points with \alert{sampling interval} \(\Delta x\).\\
What is the interpretation of the Fourier transform \(U(k)\)?\\
These are complex values that specify the amplitude and phase of the set of \(N\) Fourier components, that jointly exactly represent the original sequence.
The frequencies of the Fourier components are \alert{equidistant}:
\begin{equation*}
f_k = (k-1) \Delta f, \quad k = 1 \ldots N, \quad \Delta f = \frac{1}{N \Delta x}
\end{equation*}
Units \(x\) [m] \(\rightarrow\) \(f\) [1/m]\\
 \hspace{10mm}\(x\) [s] \(\rightarrow\) \(f\) [Hz]
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{In physcal applications, the values in the sequence usually represents some measureble quantity (displacements, temperature, electrical voltage, intensity of light) in a number of equidistant points along some spatial or time coordinates.
There is then always a corresponding sequence of spatial or time coordinates.
The sequence  \( \{u_j\} \) is a \emph{sampling} of the physical quantity in \(N\) points with \emph{sampling interval} \(\Delta x\).
If we take Fourier transform of this sequence we will get complex values that specify the amplitude and phase of the set of \(N\) Fourier components, that jointly exactly represent the original sequence.
The frequencies of the Fourier components are \alert{equidistant}.
If \(x\) units are in meters, than \(f\) units are in one over meter;
If \(x\) units are in secunds, than \(f\) units are in hertz.
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Examples}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\only<1>{
	\hspace{10mm} \(u(t) = 0.5 \cos (2 \pi 10 t + \pi/6)\)
	\begin{columns}[T]
		\begin{column}{0.5\textwidth}
			\begin{center}
			\includegraphics{FFT_example_cos_time.png}
			\includegraphics{FFT_example_cos_real.png}
			\end{center}
		\end{column}
		\begin{column}{0.5\textwidth}
			\begin{center}
			\includegraphics{FFT_example_cos_frequency.png}
			\includegraphics{FFT_example_cos_imag.png}
		\end{center}
		\end{column}
\end{columns}
}
\only<2>{
	\hspace{10mm} \(u(t) = 0.5 \sin (2 \pi 5 t + \pi/6)\)
	\begin{columns}[T]
		\begin{column}{0.5\textwidth}
			\begin{center}
				\includegraphics{FFT_example_sin_time.png}
				\includegraphics{FFT_example_sin_real.png}
			\end{center}
		\end{column}
		\begin{column}{0.5\textwidth}
			\begin{center}
				\includegraphics{FFT_example_sin_frequency.png}
				\includegraphics{FFT_example_sin_imag.png}
			\end{center}
		\end{column}
	\end{columns}
}
\only<3>{
	\hspace{10mm} \(u(t) = 0.5 \cos (2 \pi 10 t + \pi/6) + 0.3 \sin (2 \pi 5 t + \pi/6) \)
	\begin{columns}[T]
		\begin{column}{0.5\textwidth}
			\begin{center}
				\includegraphics{FFT_example_sin_cos_time.png}
				\includegraphics{FFT_example_sin_cos_real.png}
			\end{center}
		\end{column}
		\begin{column}{0.5\textwidth}
			\begin{center}
				\includegraphics{FFT_example_sin_cos_frequency.png}
				\includegraphics{FFT_example_sin_cos_imag.png}
			\end{center}
		\end{column}
	\end{columns}
}
\only<4>{
	\hspace{10mm} \(u(t) =  \left\{ \begin{array}{ll} 1& -T/2 \geq t \leq T/2 \\ 0 & \mathrm{otherwise} \end{array} \right.  ,\quad T = 10\)
	\begin{columns}[T]
		\begin{column}{0.5\textwidth}
			\begin{center}
				\includegraphics{FFT_example_rectangular_pulse_wide_time.png}
				\includegraphics{FFT_example_rectangular_pulse_wide_real.png}
			\end{center}
		\end{column}
		\begin{column}{0.5\textwidth}
			\begin{center}
				\includegraphics{FFT_example_rectangular_pulse_wide_frequency.png}
				\includegraphics{FFT_example_rectangular_pulse_wide_imag.png}
			\end{center}
		\end{column}
	\end{columns}
}
\only<5>{
	\hspace{10mm} \(u(t) =  \left\{ \begin{array}{ll} 1& -T/2 \geq t \leq T/2 \\ 0 & \mathrm{otherwise} \end{array} \right.  ,\quad T = 1\)
	\begin{columns}[T]
		\begin{column}{0.5\textwidth}
			\begin{center}
				\includegraphics{FFT_example_rectangular_pulse_narrow_time.png}
				\includegraphics{FFT_example_rectangular_pulse_narrow_real.png}
			\end{center}
		\end{column}
		\begin{column}{0.5\textwidth}
			\begin{center}
				\includegraphics{FFT_example_rectangular_pulse_narrow_frequency.png}
				\includegraphics{FFT_example_rectangular_pulse_narrow_imag.png}
			\end{center}
		\end{column}
	\end{columns}
}
\only<6>{
	%\vspace{-5mm}
	{\Large \(u(t) =\myexp^{\frac{-2 \log(2) (t-t0)^2}{\sigma^2}} \cos\left(2 \pi f_c (t - t_0)\right), \quad f_c = 375\, \mathrm{THz},\, \sigma =  8\, \mathrm{fs}\)}
	\begin{columns}[T]
		\begin{column}{0.5\textwidth}
			\begin{center}
				\includegraphics{FFT_example_gauss_time.png}
				\includegraphics{FFT_example_gauss_real.png}
			\end{center}
		\end{column}
		\begin{column}{0.5\textwidth}
			\begin{center}
				\includegraphics{FFT_example_gauss_frequency.png}
				\includegraphics{FFT_example_gauss_imag.png}
			\end{center}
		\end{column}
	\end{columns}
}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{Real values of continuous Fourier transform of rectangular pulse happens to be a sinc function.
However, discrete Fourier transform was applied here so the result only resembles sinc function.}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[label=frame10]{Sampling}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	\begin{columns}[T]
		\begin{column}{0.5\textwidth}
			\begin{center}
				\only<1>{\includegraphics{Aliasing_1.png}}
				\only<2>{\includegraphics{Aliasing_2.png}}
				\only<3>{\includegraphics{Aliasing_3.png}}
			\end{center}
		\end{column}
		\begin{column}{0.5\textwidth}
				\only<1->{\alert{Sampling} is a process of converting a signal (continuous function) into a sequence of values (discrete function).\\}
				\only<2->{
					\begin{equation*}
						f_s=1 \rightarrow \Delta t = \frac{1}{f_s} = 1
					\end{equation*}
				\(f_s\) \alert{sampling frequency} (sampling rate) is the number of data samples acquired per second\\
				\(\Delta t\) is the \alert{sampling interval}\\
			    }
				\only<3>{Insufficient sampling rate (number of discrete points) causes that it is impossible to restore original continuous signal.
				Instead we can obtain its \alert{alias}.}
		\end{column}
	\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{
\alert{Sampling} is a process of converting a signal (continuous function) into a sequence of values (discrete function).
Let's select sampling frequency \(f_s=1\).
The sampling interval \(\Delta t\) is the inverse of sampling frequency which in our example is also one.
The results of sampling are given by black dots.
It can be seen that such a number of points is insufficient to restore original continous signal.
Instead we can obtain its alias, namely other function which at this sampling rate is indistinguishable.
It is clearly visible that the red function has different frequency than the blue function.
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Aliasing (1)}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	\begin{alertblock}{Aliasing}
		It is irreversible signal distortion in the sampling process resulting from failure to meet the assumptions about the sampling theorem.
		Distortion is manifested by the presence of erroneous frequency components (aliases) in the resulting signal.
	\end{alertblock}
	Aliasing results from the ambiguous representation of the periodic signal by a series of its instantaneous values (samples) taken at equal intervals.

	If the continuous signal contains components up to the frequency \(f_{max}\), it is necessary to choose the \alert{sampling interval}:
	\begin{equation*}
	\boxed{\Delta t < \frac{1}{2 f_{max}}}
	\end{equation*}
	in order to avoid aliasing. In other words, the \alert{minimum sampling frequency is \(2 f_{max}\)}.\\
	This is known as the \alert{Nyquist–Shannon sampling theorem}.\\
	For example, our hearing ability is up to about 22 kHz.
	Therefore, the sampling frequency for music recording should be at least 44 kHz.
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{
	The DFT can be regarded as an approximation of the continuous Fourier transform, which it approaches when N goes to infinity and/or sampling interval goes to zero.
	In practice, \(N\) and sampling interval are always finite, which causes some undesirable effects.
	Two important effects of the sampling are: aliasing and finite frequency resolution.

	Aliasing is an effect that causes different signals to become indistinguishable (or aliases of one another) when sampled.
	It also often refers to the distortion or artifact that results when a signal reconstructed from samples is different from the original continuous signal.
	Aliasing can occur in signals sampled in time, for instance digital audio, and is referred to as temporal aliasing.
	It can also occur in spatially sampled signals (e.g. moiré patterns in digital images); this type of aliasing is called spatial aliasing.
	In order to avoid aliasing, the sampling frequency should be at least twice the maximum frequency component of analysed signal.
	This is known as the \alert{Nyquist–Shannon sampling theorem}.
	For example, our hearing ability is up to about 22 kHz.
	Therefore, the sampling frequency for music recording should be at least 44 kHz.
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Aliasing (2)}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{columns}[T]
	\begin{column}{0.5\textwidth}
			\begin{center}
				\only<1-2>{\includegraphics{Aliasing_3.png}	}
				\only<3>{\includegraphics{Aliasing_4.png}}
				\only<4>{\includegraphics{Aliasing_5.png}}
		\end{center}
	\end{column}
	\begin{column}{0.5\textwidth}
   			\begin{flalign*}
	   			\only<1->
	   			{
	         		& f_s = 1 \\
	   		 		&\color{red}{s_1=\sin(2 \pi \,1/8 \,f_s t)}\\
	   		 		&\color{logoblue}{s_2=\sin\left(2 \pi (1/8-1) f_s t\right)}\\
	   		 	}
   		 		\only<2->
   		 		{
   		 			&\color{logoblue}{s_2=\sin(2 \pi \underbrace{(1/8-1) f_s}_{f_{max}=7/8 f_s} t)} \\
   		 		}
   	 			\only<3->
   	 			{
   	 				&\color{magenta}{\hat{f_s} = 2 f_{max} = 14/8 f_s = 1.75 f_s}\\
   	 				&\color{magenta}{1.75\times 8\, \mathrm{intervals} = 14\, \mathrm{intervals} \rightarrow 15\, \mathrm{points}}\\
   	 			}
    			\only<4>
    			{
    				&\color{green}{\hat{f_s} \approx 2.86 f_{max} = 2.5 f_s}\\
    				&\color{green}{2.5 \times 8\, \mathrm{intervals} = 20\, \mathrm{intervals} \rightarrow 21\, \mathrm{points}}
    			}
  			 \end{flalign*}
	\end{column}
\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{
Let's go back to our example of aliasing.
At the sampling interval denoted by black dots	these two sine functions are aliases of each other.
We are not able to disgtinguish them.
Let's try to find out how many point we actually needs to properly sample the blue signal given by the blue formula.
Because it is a sine function we can identify easily the maximum frequency component \(f_{max}\).
Now, we now from the Nyquist–Shannon sampling theorem that we should use sampling frequency which is at least twice of that.
As a result, we have obtained fifteen magenta points which is still not enough to capture wave crests.
We need sligthly more points.
As you can see green points are enough to represent the original signal.
In practice, we often use oversampling with a factor of 10 or even more.
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Heat transfer problem}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Heat transfer problem - FFT for PDEs}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{columns}[T]
\begin{column}{0.5\textwidth}
	\only<1->{
One dimensional heat conduction equation:
\begin{equation*}
u_t = \alpha^2 u_{xx} \quad  \mathrm{or} \quad \frac{\partial u}{\partial t} = \alpha^2 \frac{\partial^2 u}{\partial^2x}
\end{equation*}
\(u\) - temperature\\
\(t\) - time\\
\(x\) - space\\
\(\alpha\) - diffusivity of the medium\\
\vspace{5mm}}
\only<5>{Initial condition \(u(x,0)\)\\}
\only<6>{Initial condition \(u(x,0) \xrightarrow {\mathcal{F}} \hat{u}(\kappa,0)\)\\}
\only<5->{
\begin{tikzpicture}
\draw[thick,->,logoblue] (0,0)--(7,0) node[right] {$x$}; % x axis
\draw[thick,logoblue] (2.5,0)--(2.5,2)--(5,2)--(5,0);
\node[logoblue,below] at (2.5,0) {$\frac{L}{2}-\frac{L}{10}$};
\node[logoblue,below] at (5,0) {$\frac{L}{2}+\frac{L}{10}$};
\node[logoblue,right] at (5,2) {1};
\filldraw[black] (2.5,0) circle (2pt);
\filldraw[black] (5,0) circle (2pt);
\end{tikzpicture}}
\end{column}
\begin{column}{0.5\textwidth}
\only<2->{
\begin{equation*}
u(x,t) \xrightarrow{\mathcal{F}} \hat{u}(\kappa,t)
\end{equation*}
\begin{equation*}
u_x \xrightarrow{\mathcal{F}} i \kappa \hat{u} (\kappa, t)
\end{equation*}
\begin{equation*}
u_{xx} \xrightarrow{\mathcal{F}}  - \kappa^2 \hat{u}(\kappa , t)
\end{equation*}
\begin{equation*}
u_{t} \xrightarrow{\mathcal{F}} \hat{u}_t = \frac{\partial \hat{u}(\kappa,t)}{\partial t}
\end{equation*}}
\only<3->{
\vspace{-3mm}
\begin{equation*}
u_t = \alpha^2 u_{xx} \xrightarrow{\mathcal{F}} \alert{\hat{u}_{t} = -\alpha^2 \kappa^2 \hat{u}}
\end{equation*}}
\centering
\only<4->{
\(n\) decoupled ODEs\\
one for each \(\kappa_j\)
\begin{equation*}
  \left[ \begin{array}{l} \hat{u}_{t1} \\ \hat{u}_{t2}\\ \vdots \\ \hat{u}_{tn} \end{array} \right] = -\alpha^2 \left[ \begin{array}{l} \kappa_1^2 \hat{u}_1 \\ \kappa_2^2 \hat{u}_2\\ \vdots \\ \kappa_n^2 \hat{u}_n \end{array} \right]
\end{equation*}}
\end{column}
\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{{\scriptsize Heat conduction equation has a form of a partial differential equation which can be written as derivative of temperature field over time is equal to alpha square times second derivative of temperature field over x.
So, u is the temperature, t is the time, x is space and alpha is the diffusivity of the medium.
It turns out that, the Fourier transform can be used to approximate partial differentials.
You already know how to apply one-dimensional Fourier transform to signals.
Now, we will be using Fourier transform for mapping spatial domain x into wavenumber domain denoted here by kappa.
We do not apply Fourier transform to the time domain.
Fourier transform has very nice property which allows to use it for approximation of partial derivatives.
So it is easy to compute derivatives in space in this case just by Fourier transforming and multiplying by i kappa or minus kappa square for the first and second derivative, respectively.
In case of the left hand side of the partial differential equation, we transform u from spatial domain to frequency domain but the differentiation in respect to time is applied afterwards.
Essentially, we applied the Fourier transform to the whole partial differential equation.
As you can see now we have only differentiation in respect to time so this is the system of ordinary differential equations (ODE) which is easy to solve.
Actually, it is n decoupled ODEs, one for each kappa j. This system of ODEs can be written in a matrix form.
Here, kappa 1 to n are just a numbers.
}
%Inspired by Steve Brunton: https://www.youtube.com/watch?v=BkA7ncY0b7I
%S. L. Brunton and J. N. Kutz, Data Driven Science \& Engineering: Machine Learning, Dynamical Systems, and Control, Cambridge Textbook, 2019
}
\newpage
\note{In order to have well-posed problem we need to add initial conditions at the time equal zero.
Let's assume that our initial conditions can be represented by the top-hat function.
In order to better visualize it, you can think of three rods: the rod in the middle is hot and the rods at the left hand side and right hand side are cold.
We would like to know how the tempereture evolve with time immediately after the rods  come into contact.
Because we are solving this problem in wavenumber domain, we also have to transform function of intial condition from the space domain to the time domain.
Once, the system of ODEs is solved in the wavenumber domain, we will apply inverse Fourier transform in order to obtain spatial temperature distribution.
OK, Let's try to code it in Matlab.
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Signal filtering}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Digital filters}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Digital filter purposes:
\begin{enumerate}
	\item separation of signals that have been combined
	\item restoration of signals that have been distorted in some way.
\end{enumerate}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{Digital filters are used for two general purposes: (1) separation of signals that have been combined, and (2) restoration of signals that have been distorted in some way.
Signal separation is needed when a signal has been contaminated with interference, noise, or other signals.
For example, imagine a device for measuring the electrical activity of a baby's heart while still in the womb.
The raw signal will likely be corrupted by the breathing and heartbeat of the mother.
A filter might be used to separate these signals so that they can be individually analyzed.
Signal restoration is used when a signal has been distorted in some way.
For example, an audio recording made with poor equipment may be filtered to better represent the sound as it actually occurred.
 Another example is the deblurring of an image acquired with an improperly focused lens, or a shaky camera.

Analog (electronic) filters can be used for the same tasks;
however, digital filters can achieve far superior results.

Digital filters are a very important part of digital signal processing (DSP).
In fact, their extraordinary performance is one of the key reasons that digital signal processing has become so popular.

I will introduce you the most popular digital filters.}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Signal filtering(1)}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{alertblock}{Low-pass filter}
A low-pass filter (LPF) is a filter that passes signals with a frequency lower than a selected cut-off frequency and attenuates signals with frequencies higher than the cut-off frequency.
\end{alertblock}
\begin{tikzpicture}
\draw[thick,->,logoblue] (0,0)--(7,0) node[right] {$f$ [Hz]}; % x axis
\draw[thick,->,logoblue] (0,0)--(0,4.5) ; % y axis
\draw[thick,red] (0,3.5)--(3,3.5)--(4.5,0)--(6,0); % low-pass filter
\draw[thin,dashed,green] (3,3.5)--(3,0); % cut off frequency
\node[logoblue,below] at (3,0) {$f_c$};
\node[logoblue,above] at (2,0.14) {Passband};
\node[logoblue,above] at (5.5,0.1) {Stopband};
\end{tikzpicture}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{A low-pass filter (LPF) is a filter that passes signals with a frequency lower than a selected cut-off frequency and attenuates signals with frequencies higher than the cut-off frequency.}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Signal filtering(2)}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{alertblock}{High-pass filter}
A high-pass filter (HPF) is a filter that passes signals with a frequency higher than a certain cut-off frequency and attenuates signals with frequencies lower than the cut-off frequency.
\end{alertblock}
\begin{tikzpicture}
\draw[thick,->,logoblue] (0,0)--(7,0) node[right] {$f$ [Hz]}; % x axis
\draw[thick,->,logoblue] (0,0)--(0,4.5) ; % y axis
\draw[thick,red] (0,0)--(2.5,0)--(3,3.5)--(6,3.5); % high-pass filter
\draw[thin,dashed,green] (3,3.5)--(3,0); % cut off frequency
\node[logoblue,below] at (3,0) {$f_c$};
\node[logoblue,above] at (1.5,0.1) {Stopband};
\node[logoblue,above] at (4,0.14) {Passband};
\end{tikzpicture}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{Most discussions on filter design only give examples of low-pass filters.
It is because low-pass filter can be converted to high-pass filter.
There are two methods for the low-pass to high-pass conversion: spectral inversion and spectral reversal. Both are equally useful.

A high-pass filter (HPF) is a filter that passes signals with a frequency higher than a certain cut-off frequency and attenuates signals with frequencies lower than the cut-off frequency.}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Signal filtering(3)}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{alertblock}{Band-pass filter}
A band-pass filter (BPF) is a filter that passes frequencies within a certain range and rejects (attenuates) frequencies outside that range.\\
These filters can be created by combining a low-pass filter with a high-pass filter.
\end{alertblock}
	\begin{tikzpicture}
	\draw[thick,->,logoblue] (0,0)--(9,0) node[right] {$f$ [Hz]}; % x axis
	\draw[thick,->,logoblue] (0,0)--(0,4.5) ; % y axis
	\draw[thick,red] (0,0)--(1.5,0)--(2,3.5)--(4,3.5)--(4.5,0)--(7,0); % band-pass filter
	\draw[thin,dashed,green] (2,3.5)--(2,0); % cut off frequency f_L
	\node[logoblue,below] at (2,0) {$f_L$};
	\draw[thin,dashed,green] (4,3.5)--(4,0); % cut off frequency f_H
	\node[logoblue,below] at (4,0) {$f_H$};
	\node[logoblue,above] at (0.8,0.1) {Stopband};
	\node[logoblue,above] at (3,0.14) {Passband};
	\node[logoblue,above] at (5.8,0.1) {Stopband};
	\end{tikzpicture}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{Band-pass filter can be obtained by convolving low-pass and high-pass filters.}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Signal filtering(4)}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The filtering strategy which we will be using is as follows:
\begin{equation*}
\alert{s(t) \xrightarrow{\mathcal{F}} \hat{s}(\omega) \rightarrow \hat{s}(\omega) \cdot \hat{M}(\omega)  \xrightarrow{\mathcal{F}^{-1}}  s(t)}
\end{equation*}
\(\cdot\) is element-wise multiplication; (.* in Matlab)

\(\hat{M}\) a kernel, convolution matrix, or mask
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Image processing}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Image processing (1)}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Purposes: image enhancement, object detection, segmentation.
\begin{block}{Image enhancement}
	Image enhancement is the process of adjusting digital images so that the results are more suitable for display or further processing.
\end{block}
	\begin{itemize}
		\item Noise removal
		\item Deblurring
		\item Filtering
	\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{Image processing can have various purposes such as image enhancement, object detection, image segmentation, etc.
We often want to enhance an image in certain way.
Image enhancement is the process of adjusting digital images so that the results are more suitable for display or further processing.
It can be use for example for noise removal, debluring or filtering.}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Image processing (2)}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{columns}[T]
	\begin{column}{0.4\textwidth}
		\begin{figure}
			\animategraphics[controls,autoplay,loop,width=0.8\textwidth]{3}{Lena}{1}{46}
			%\includegraphics[width=0.8\textwidth]{Lena1.png}
			\caption{Lenna}
		\end{figure}
	\end{column}
	\begin{column}{0.6\textwidth}
	1D FFT
	\begin{equation*}
		f(t) \xrightarrow{\mathcal{F}} \hat{f}(\omega)
	\end{equation*}
	2D FFT
	\begin{equation*}
		f(x,y) \xrightarrow{\mathcal{F}} \hat{f}(k_x,k_y)
	\end{equation*}
	\(k_x,\, k_y\) - wavenumbers in \(x\) and \(y\) direction, respectively.\\
	Image processing strategy:
	\begin{equation*}
	\alert{I(x,y) \xrightarrow{\mathcal{F}} \hat{I}(k_x,k_y) \rightarrow \hat{I}(k_x,k_y) \cdot \hat{M}(k_x,k_y)  \xrightarrow{\mathcal{F}^{-1}}  I(x,y)}
	\end{equation*}
	\(\cdot\) is element-wise multiplication; (.* in Matlab)
	\end{column}
	\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{The Lenna picture is one of the most widely used standard test image in the field of compression algorithms.
It is a picture of the Swedish model Lena Forsen which comes from Playboy magazine from 1972.
We will use it as well for some image processing examples by using 2D FFT as it is shown in the animation.
{\scriptsize There is a story behind this image.
Alexander Sawchuk, assistant professor at the University of Southern California Signal and Image Processing Institute along with graduate student was searching the lab for a good image to scan for a conference paper.
They wanted to have something more distinctive from boring test photos.
They were looking for a photo with a human face with a good dynamic range.
Then, somebody just came in with a recent issue of Playboy.
Engineers took part of that photo and scanned it which resulted in the 512 by 512 pixel image.
This scan became one of the most used images in computer history.
But let's go back to the main topic.}
}
\newpage
\note{As you remember, 1D FFT in case of signals is a mapping between the time domain and frequency domain.
2D FFT on the other hand is a mapping between 2D spatial domain (x,y) and 2D wavenumber domain.
The strategy is the same as in case of signal filtering.
First, we transfom image to the wavenumber domain. Image here is denoted by the captial I. Then we apply a filter mask m hat, and finally going back to the spatial domain by using the inverse Fourier transform.
It should be noted that element-wise multiplication is performed in the wavenumber domain.
Such operation is performed in Matlab by using dot asterix symbol.
Let's move to Matlab so you can code such animations yourself.
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Assignment}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Assignment}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{enumerate}
	\item Write a code in Matlab or other preferred language like Python or Julia which plots a function:
	\begin{equation*}
	s(t) = 0.5 \left[1 - \cos(2 \pi f_m t) \right] \sin(2 \pi f_c t)
	\end{equation*}
	and its Fourier transform.
	Please comment on obtained figures for frequency pairs:
	\begin{itemize}
		\item \(f_c = 100\) kHz,  \(f_m = 20\) kHz
		\item \(f_c = 100\) kHz,  \(f_m = 5\) kHz.
	\end{itemize}
  \item Let's suppose, that we are using a software that provides a results in a form of a function sampled at Gauss-Lobatto-Legendre points which are non-equidistant.
  Our task is to perform the Fourier transform of that data.
  What will be the strategy of performing the Fourier transform on sampling points which are non-equidistant? \\
  \vspace{5mm}
  \begin{tikzpicture}
  \draw[thick,->,logoblue] (-1,0)--(1.4,0) node[right] {$x$}; % x axis
  \filldraw[black] (-1,0) circle (2pt);
  \filldraw[black] (-0.765,0) circle (2pt);
  \filldraw[black] ( -0.2852,0) circle (2pt);
  \filldraw[black] ( 0.2852,0) circle (2pt);
   \filldraw[black] (0.765,0) circle (2pt);
   \filldraw[black] (1,0) circle (2pt);
  \end{tikzpicture}

\end{enumerate}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\note{I have prepared two tasks for you.
In the first task, I want you to write a code in Matlab  or other preferred language like Python or Julia.
But I think that it will be easiest to use Matlab scripts which are attached to this lecture as a starting point.
The code should plot a function defined here. It should perform Fourier transform of this function and plot its magnitude.
As you can see there are two sets of frequency parameters for definition of this function.
I want you to write a few sentences describing what you see in the time domain and frequency domain for each frequency pair.

In the second task, I want you to write an answer to the following problem.
Let's suppose, that we are using a software that provides a results in a form of a function sampled at Gauss-Lobatto-Legendre points which are non-equidistant (like here).
Our task is to perform the Fourier transform of that data.
So we have an arbitrary function sampled at these points.
What will be the strategy of performing the Fourier transform on sampling points which are non-equidistant?
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
{\setbeamercolor{palette primary}{fg=black, bg=white}
\begin{frame}[standout]
  Thank you for your attention!\\ \vspace{12pt}
  Questions?\\ \vspace{12pt}
  \url{pk@imp.gda.pl}
\end{frame}
}
\note{Thank you for your attention!
I hope that you have learnt something from my presentation.
I am aware that the presentation was given in a quite condensed form.
Therefore, I expect that you might not grasp everything.
So, if you have any questions please drop me a line.
See you next time!}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% END OF SLIDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}