filters-matlab-bank/index.org

1223 lines
35 KiB
Org Mode
Raw Normal View History

2019-08-17 10:50:06 +02:00
#+TITLE: List of filters - Matlab Implementation
:DRAWER:
#+LANGUAGE: en
#+EMAIL: dehaeze.thomas@gmail.com
#+AUTHOR: Dehaeze Thomas
#+HTML_LINK_HOME: ./index.html
#+HTML_LINK_UP: ./index.html
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="./css/htmlize.css"/>
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="./css/readtheorg.css"/>
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="./css/zenburn.css"/>
#+HTML_HEAD: <script type="text/javascript" src="./js/jquery.min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="./js/bootstrap.min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="./js/jquery.stickytableheaders.min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="./js/readtheorg.js"></script>
2020-10-26 09:43:09 +01:00
#+PROPERTY: header-args:latex :headers '("\\usepackage{tikz}" "\\usepackage{import}" "\\import{$HOME/Cloud/tikz/org/}{config.tex}")
2019-08-17 10:50:06 +02:00
#+PROPERTY: header-args:latex+ :imagemagick t :fit yes
#+PROPERTY: header-args:latex+ :iminoptions -scale 100% -density 150
#+PROPERTY: header-args:latex+ :imoutoptions -quality 100
#+PROPERTY: header-args:latex+ :results raw replace :buffer no
#+PROPERTY: header-args:latex+ :eval no-export
#+PROPERTY: header-args:latex+ :exports both
#+PROPERTY: header-args:latex+ :mkdirp yes
#+PROPERTY: header-args:latex+ :output-dir figs
#+PROPERTY: header-args:latex+ :post pdf2svg(file=*this*, ext="png")
#+PROPERTY: header-args:matlab :session *MATLAB*
#+PROPERTY: header-args:matlab+ :tangle filters.m
#+PROPERTY: header-args:matlab+ :comments org
#+PROPERTY: header-args:matlab+ :exports both
#+PROPERTY: header-args:matlab+ :results none
#+PROPERTY: header-args:matlab+ :eval no-export
#+PROPERTY: header-args:matlab+ :noweb yes
#+PROPERTY: header-args:matlab+ :mkdirp yes
#+PROPERTY: header-args:matlab+ :output-dir figs
:END:
* Matlab Init :noexport:ignore:
#+begin_src matlab :tangle no :exports none :results silent :noweb yes :var current_dir=(file-name-directory buffer-file-name)
<<matlab-dir>>
#+end_src
#+begin_src matlab :exports none :results silent :noweb yes
<<matlab-init>>
#+end_src
* Proportional - Integral - Derivative
** Proportional
** Integral
** Derivative
* Low Pass
** First Order
\[ H(s) = \frac{1}{1 + s/\omega_0} \]
#+begin_src matlab
w0 = 2*pi; % [rad/s]
H = 1/(1 + s/w0);
#+end_src
#+begin_src matlab :exports none
freqs = logspace(-1, 1, 1000);
resp = squeeze(freqresp(H, freqs, 'Hz'));
Ha = abs(resp);
Hp = 180/pi*phase(resp);
T = table(freqs', Ha, Hp, 'VariableNames', {'freqs', 'amplitude', 'phase'});
writetable(T,'mat/lpf_first_order.csv');
#+end_src
#+begin_src latex :file lpf_first_order.pdf :tangle figs/lpf_first_order.tex :exports results
\setlength\fwidth{8cm}
\setlength\fheight{6cm}
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\begin{tikzpicture}
\begin{axis}[%
width=\fwidth,
height=0.45\fheight,
at={(0\fwidth,0.5\fheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmode=log,
xmin=0.1,
xmax=10,
xticklabels={{}},
xminorticks=true,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
every y tick/.append style={black},
ymode=log,
ymin=1e-2,
ymax=1e1,
% ytick={1e-14, 1e-12, 1e-10, 1e-8, 1e-6},
% yticklabels={{1e-14}, {}, {1e-10}, {}, {1e-6}},
yminorticks=true,
ylabel={Amplitude},
axis background/.style={fill=white},
xmajorgrids,
xminorgrids,
ymajorgrids,
yminorgrids
]
\addplot[color=black, mark=none]
2020-10-26 09:43:09 +01:00
table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlpf_first_order.csv};
2019-08-17 10:50:06 +02:00
\end{axis}
\begin{axis}[%
width=\fwidth,
height=0.45\fheight,
at={(0\fwidth,0\fheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmode=log,
xmin=0.1,
xmax=10,
xminorticks=true,
xlabel={Frequency [Hz]},
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
every y tick/.append style={black},
ymin=-270,
ymax=90,
ytick={-360, -270, -180, -90, 0, 90},
ylabel={Phase [deg]},
axis background/.style={fill=white},
xmajorgrids,
xminorgrids,
ymajorgrids
]
\addplot[color=black, mark=none]
2020-10-26 09:43:09 +01:00
table [x=freqs, y=phase, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlpf_first_order.csv};
2019-08-17 10:50:06 +02:00
\end{axis}
\end{tikzpicture}
#+end_src
#+name: fig:lpf_first_order
#+caption: First Order Low Pass Filter ([[./figs/lpf_first_order.png][png]], [[./figs/lpf_first_order.pdf][pdf]].
#+RESULTS:
[[file:figs/lpf_first_order.png]]
** Second Order
\[ H(s) = \frac{1}{1 + 2 \xi / \omega_0 s + s^2/\omega_0^2} \]
#+begin_src matlab
w0 = 2*pi; % [rad/s]
xi = 0.3;
H = 1/(1 + 2*xi/w0*s + s^2/w0^2);
#+end_src
#+begin_src matlab :exports none
freqs = logspace(-1, 1, 1000);
resp = squeeze(freqresp(H, freqs, 'Hz'));
Ha = abs(resp);
Hp = 180/pi*phase(resp);
T = table(freqs', Ha, Hp, 'VariableNames', {'freqs', 'amplitude', 'phase'});
writetable(T,'mat/lpf_second_order.csv');
#+end_src
#+begin_src latex :file lpf_second_order.pdf :tangle figs/lpf_second_order.tex :exports results
\setlength\fwidth{8cm}
\setlength\fheight{6cm}
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\begin{tikzpicture}
\begin{axis}[%
width=\fwidth,
height=0.45\fheight,
at={(0\fwidth,0.5\fheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmode=log,
xmin=0.1,
xmax=10,
xticklabels={{}},
xminorticks=true,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
every y tick/.append style={black},
ymode=log,
ymin=1e-2,
ymax=1e1,
% ytick={1e-14, 1e-12, 1e-10, 1e-8, 1e-6},
% yticklabels={{1e-14}, {}, {1e-10}, {}, {1e-6}},
yminorticks=true,
ylabel={Amplitude},
axis background/.style={fill=white},
xmajorgrids,
xminorgrids,
ymajorgrids,
yminorgrids
]
\addplot[color=black, mark=none]
2020-10-26 09:43:09 +01:00
table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlpf_second_order.csv};
2019-08-17 10:50:06 +02:00
\end{axis}
\begin{axis}[%
width=\fwidth,
height=0.45\fheight,
at={(0\fwidth,0\fheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmode=log,
xmin=0.1,
xmax=10,
xminorticks=true,
xlabel={Frequency [Hz]},
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
every y tick/.append style={black},
ymin=-270,
ymax=90,
ytick={-360, -270, -180, -90, 0, 90},
ylabel={Phase [deg]},
axis background/.style={fill=white},
xmajorgrids,
xminorgrids,
ymajorgrids
]
\addplot[color=black, mark=none]
2020-10-26 09:43:09 +01:00
table [x=freqs, y=phase, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlpf_second_order.csv};
2019-08-17 10:50:06 +02:00
\end{axis}
\end{tikzpicture}
#+end_src
#+name: fig:lpf_second_order
#+caption: Second Order Low Pass Filter ([[./figs/lpf_second_order.png][png]], [[./figs/lpf_second_order.pdf][pdf]].
#+RESULTS:
[[file:figs/lpf_second_order.png]]
** Combine multiple filters
\[ H(s) = \left( \frac{1}{1 + s/\omega_0} \right)^n \]
#+begin_src matlab
w0 = 2*pi; % [rad/s]
n = 3;
H = (1/(1 + s/w0))^n;
#+end_src
#+begin_src matlab :exports none
freqs = logspace(-1, 1, 1000);
resp = squeeze(freqresp(H, freqs, 'Hz'));
Ha = abs(resp);
Hp = 180/pi*phase(resp);
T = table(freqs', Ha, Hp, 'VariableNames', {'freqs', 'amplitude', 'phase'});
writetable(T,'mat/lpf_multiple_first_order.csv');
#+end_src
#+begin_src latex :file lpf_multiple_first_order.pdf :tangle figs/lpf_multiple_first_order.tex :exports results
\setlength\fwidth{8cm}
\setlength\fheight{6cm}
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\begin{tikzpicture}
\begin{axis}[%
width=\fwidth,
height=0.45\fheight,
at={(0\fwidth,0.5\fheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmode=log,
xmin=0.1,
xmax=10,
xticklabels={{}},
xminorticks=true,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
every y tick/.append style={black},
ymode=log,
ymin=1e-2,
ymax=1e1,
% ytick={1e-14, 1e-12, 1e-10, 1e-8, 1e-6},
% yticklabels={{1e-14}, {}, {1e-10}, {}, {1e-6}},
yminorticks=true,
ylabel={Amplitude},
axis background/.style={fill=white},
xmajorgrids,
xminorgrids,
ymajorgrids,
yminorgrids
]
\addplot[color=black, mark=none]
2020-10-26 09:43:09 +01:00
table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlpf_multiple_first_order.csv};
2019-08-17 10:50:06 +02:00
\end{axis}
\begin{axis}[%
width=\fwidth,
height=0.45\fheight,
at={(0\fwidth,0\fheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmode=log,
xmin=0.1,
xmax=10,
xminorticks=true,
xlabel={Frequency [Hz]},
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
every y tick/.append style={black},
ymin=-270,
ymax=90,
ytick={-360, -270, -180, -90, 0, 90},
ylabel={Phase [deg]},
axis background/.style={fill=white},
xmajorgrids,
xminorgrids,
ymajorgrids
]
\addplot[color=black, mark=none]
2020-10-26 09:43:09 +01:00
table [x=freqs, y=phase, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlpf_multiple_first_order.csv};
2019-08-17 10:50:06 +02:00
\end{axis}
\end{tikzpicture}
#+end_src
#+name: fig:lpf_multiple_first_order
#+caption: Combine Multiple First Order Low Pass Filter ([[./figs/lpf_multiple_first_order.png][png]], [[./figs/lpf_multiple_first_order.pdf][pdf]].
** Nice combination
\begin{equation}
W(s) = G_c * \left(\frac{\frac{1}{\omega_0}\sqrt{\frac{1 - \left(\frac{G_0}{G_c}\right)^{\frac{2}{n}}}{1 - \left(\frac{G_c}{G_\infty}\right)^{\frac{2}{n}}}} s + \left(\frac{G_0}{G_c}\right)^{\frac{1}{n}}}{\frac{1}{\omega_0} \sqrt{\frac{1 - \left(\frac{G_0}{G_c}\right)^{\frac{2}{n}}}{\left(\frac{G_\infty}{G_c}\right)^{\frac{2}{n}} - 1}} s + 1}\right)^n
\end{equation}
#+begin_src matlab
n = 2; w0 = 2*pi*11; G0 = 1/10; G1 = 1000; Gc = 1/2;
wL = Gc*(((G1/Gc)^(1/n)/w0*sqrt((1-(G0/Gc)^(2/n))/((G1/Gc)^(2/n)-1))*s + (G0/Gc)^(1/n))/(1/w0*sqrt((1-(G0/Gc)^(2/n))/((G1/Gc)^(2/n)-1))*s + 1))^n;
n = 3; w0 = 2*pi*9; G0 = 10000; G1 = 0.1; Gc = 1/2;
wH = Gc*(((G1/Gc)^(1/n)/w0*sqrt((1-(G0/Gc)^(2/n))/((G1/Gc)^(2/n)-1))*s + (G0/Gc)^(1/n))/(1/w0*sqrt((1-(G0/Gc)^(2/n))/((G1/Gc)^(2/n)-1))*s + 1))^n;
#+end_src
* High Pass
** First Order
\[ H(s) = \frac{s/\omega_0}{1 + s/\omega_0} \]
#+begin_src matlab
w0 = 2*pi; % [rad/s]
H = (s/w0)/(1 + s/w0);
#+end_src
#+begin_src matlab :exports none
freqs = logspace(-1, 1, 1000);
resp = squeeze(freqresp(H, freqs, 'Hz'));
Ha = abs(resp);
Hp = 180/pi*phase(resp);
T = table(freqs', Ha, Hp, 'VariableNames', {'freqs', 'amplitude', 'phase'});
writetable(T,'mat/hpf_first_order.csv');
#+end_src
#+begin_src latex :file hpf_first_order.pdf :tangle figs/hpf_first_order.tex :exports results
\setlength\fwidth{8cm}
\setlength\fheight{6cm}
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\begin{tikzpicture}
\begin{axis}[%
width=\fwidth,
height=0.45\fheight,
at={(0\fwidth,0.5\fheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmode=log,
xmin=0.1,
xmax=10,
xticklabels={{}},
xminorticks=true,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
every y tick/.append style={black},
ymode=log,
ymin=1e-2,
ymax=1e1,
% ytick={1e-14, 1e-12, 1e-10, 1e-8, 1e-6},
% yticklabels={{1e-14}, {}, {1e-10}, {}, {1e-6}},
yminorticks=true,
ylabel={Amplitude},
axis background/.style={fill=white},
xmajorgrids,
xminorgrids,
ymajorgrids,
yminorgrids
]
\addplot[color=black, mark=none]
2020-10-26 09:43:09 +01:00
table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/mathpf_first_order.csv};
2019-08-17 10:50:06 +02:00
\end{axis}
\begin{axis}[%
width=\fwidth,
height=0.45\fheight,
at={(0\fwidth,0\fheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmode=log,
xmin=0.1,
xmax=10,
xminorticks=true,
xlabel={Frequency [Hz]},
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
every y tick/.append style={black},
ymin=-270,
ymax=90,
ytick={-360, -270, -180, -90, 0, 90},
ylabel={Phase [deg]},
axis background/.style={fill=white},
xmajorgrids,
xminorgrids,
ymajorgrids
]
\addplot[color=black, mark=none]
2020-10-26 09:43:09 +01:00
table [x=freqs, y=phase, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/mathpf_first_order.csv};
2019-08-17 10:50:06 +02:00
\end{axis}
\end{tikzpicture}
#+end_src
#+name: fig:hpf_first_order
#+caption: First Order High Pass Filter ([[./figs/hpf_first_order.png][png]], [[./figs/hpf_first_order.pdf][pdf]].
#+RESULTS:
[[file:figs/hpf_first_order.png]]
** Second Order
\[ H(s) = \frac{s^2/\omega_0^2}{1 + 2 \xi / \omega_0 s + s^2/\omega_0^2} \]
#+begin_src matlab
w0 = 2*pi; % [rad/s]
xi = 0.3;
H = (s^2/w0^2)/(1 + 2*xi/w0*s + s^2/w0^2);
#+end_src
#+begin_src matlab :exports none
freqs = logspace(-1, 1, 1000);
resp = squeeze(freqresp(H, freqs, 'Hz'));
Ha = abs(resp);
Hp = 180/pi*phase(resp);
T = table(freqs', Ha, Hp, 'VariableNames', {'freqs', 'amplitude', 'phase'});
writetable(T,'mat/hpf_second_order.csv');
#+end_src
#+begin_src latex :file hpf_second_order.pdf :tangle figs/hpf_second_order.tex :exports results
\setlength\fwidth{8cm}
\setlength\fheight{6cm}
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\begin{tikzpicture}
\begin{axis}[%
width=\fwidth,
height=0.45\fheight,
at={(0\fwidth,0.5\fheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmode=log,
xmin=0.1,
xmax=10,
xticklabels={{}},
xminorticks=true,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
every y tick/.append style={black},
ymode=log,
ymin=1e-2,
ymax=1e1,
% ytick={1e-14, 1e-12, 1e-10, 1e-8, 1e-6},
% yticklabels={{1e-14}, {}, {1e-10}, {}, {1e-6}},
yminorticks=true,
ylabel={Amplitude},
axis background/.style={fill=white},
xmajorgrids,
xminorgrids,
ymajorgrids,
yminorgrids
]
\addplot[color=black, mark=none]
2020-10-26 09:43:09 +01:00
table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/mathpf_second_order.csv};
2019-08-17 10:50:06 +02:00
\end{axis}
\begin{axis}[%
width=\fwidth,
height=0.45\fheight,
at={(0\fwidth,0\fheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmode=log,
xmin=0.1,
xmax=10,
xminorticks=true,
xlabel={Frequency [Hz]},
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
every y tick/.append style={black},
ymin=-270,
ymax=90,
ytick={-360, -270, -180, -90, 0, 90},
ylabel={Phase [deg]},
axis background/.style={fill=white},
xmajorgrids,
xminorgrids,
ymajorgrids
]
\addplot[color=black, mark=none]
2020-10-26 09:43:09 +01:00
table [x=freqs, y=phase, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/mathpf_second_order.csv};
2019-08-17 10:50:06 +02:00
\end{axis}
\end{tikzpicture}
#+end_src
#+name: fig:hpf_second_order
#+caption: Second Order High Pass Filter ([[./figs/hpf_second_order.png][png]], [[./figs/hpf_second_order.pdf][pdf]].
#+RESULTS:
[[file:figs/hpf_second_order.png]]
** Combine multiple filters
\[ H(s) = \left( \frac{s/\omega_0}{1 + s/\omega_0} \right)^n \]
#+begin_src matlab
w0 = 2*pi; % [rad/s]
n = 3;
H = ((s/w0)/(1 + s/w0))^n;
#+end_src
#+begin_src matlab :exports none
freqs = logspace(-1, 1, 1000);
resp = squeeze(freqresp(H, freqs, 'Hz'));
Ha = abs(resp);
Hp = 180/pi*phase(resp);
T = table(freqs', Ha, Hp, 'VariableNames', {'freqs', 'amplitude', 'phase'});
writetable(T,'mat/hpf_multiple_first_order.csv');
#+end_src
#+begin_src latex :file hpf_multiple_first_order.pdf :tangle figs/hpf_multiple_first_order.tex :exports results
\setlength\fwidth{8cm}
\setlength\fheight{6cm}
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\begin{tikzpicture}
\begin{axis}[%
width=\fwidth,
height=0.45\fheight,
at={(0\fwidth,0.5\fheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmode=log,
xmin=0.1,
xmax=10,
xticklabels={{}},
xminorticks=true,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
every y tick/.append style={black},
ymode=log,
ymin=1e-2,
ymax=1e1,
% ytick={1e-14, 1e-12, 1e-10, 1e-8, 1e-6},
% yticklabels={{1e-14}, {}, {1e-10}, {}, {1e-6}},
yminorticks=true,
ylabel={Amplitude},
axis background/.style={fill=white},
xmajorgrids,
xminorgrids,
ymajorgrids,
yminorgrids
]
\addplot[color=black, mark=none]
2020-10-26 09:43:09 +01:00
table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/mathpf_multiple_first_order.csv};
2019-08-17 10:50:06 +02:00
\end{axis}
\begin{axis}[%
width=\fwidth,
height=0.45\fheight,
at={(0\fwidth,0\fheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmode=log,
xmin=0.1,
xmax=10,
xminorticks=true,
xlabel={Frequency [Hz]},
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
every y tick/.append style={black},
ymin=-270,
ymax=90,
ytick={-360, -270, -180, -90, 0, 90},
ylabel={Phase [deg]},
axis background/.style={fill=white},
xmajorgrids,
xminorgrids,
ymajorgrids
]
\addplot[color=black, mark=none]
2020-10-26 09:43:09 +01:00
table [x=freqs, y=phase, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/mathpf_multiple_first_order.csv};
2019-08-17 10:50:06 +02:00
\end{axis}
\end{tikzpicture}
#+end_src
#+name: fig:hpf_multiple_first_order
#+caption: Combine Multiple First Order High Pass Filter ([[./figs/hpf_multiple_first_order.png][png]], [[./figs/hpf_multiple_first_order.pdf][pdf]].
#+RESULTS:
[[file:figs/hpf_multiple_first_order.png]]
* Band Pass
* Notch
2020-10-26 09:43:09 +01:00
* Bump
#+begin_src matlab
n = 4;
w0 = 2*pi;
A = 10;
a = sqrt(2*A^(2/n) - 1 + 2*A^(1/n)*sqrt(A^(2/n) - 1));
G = ((1 + s/(w0/a))*(1 + s/(w0*a))/(1 + s/w0)^2)^n;
bodeFig({G})
#+end_src
2019-08-17 10:50:06 +02:00
* Chebyshev
** Chebyshev Type I
#+begin_src matlab
n = 4; % Order of the filter
Rp = 3; % Maximum peak-to-peak ripple [dB]
Wp = 2*pi; % passband-edge frequency [rad/s]
[A,B,C,D] = cheby1(n, Rp, Wp, 'high', 's');
H = ss(A, B, C, D);
#+end_src
#+begin_src matlab :exports none
freqs = logspace(-1, 1, 1000);
resp = squeeze(freqresp(H, freqs, 'Hz'));
Ha = abs(resp);
Hp = 180/pi*phase(resp);
T = table(freqs', Ha, Hp, 'VariableNames', {'freqs', 'amplitude', 'phase'});
writetable(T,'mat/cheby1_hpf.csv');
#+end_src
#+begin_src latex :file cheby1_hpf.pdf :tangle figs/cheby1_hpf.tex :exports results
\setlength\fwidth{8cm}
\setlength\fheight{6cm}
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\begin{tikzpicture}
\begin{axis}[%
width=\fwidth,
height=0.45\fheight,
at={(0\fwidth,0.5\fheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmode=log,
xmin=0.1,
xmax=10,
xticklabels={{}},
xminorticks=true,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
every y tick/.append style={black},
ymode=log,
% ymin=1e-2,
% ymax=1e1,
% ytick={1e-14, 1e-12, 1e-10, 1e-8, 1e-6},
% yticklabels={{1e-14}, {}, {1e-10}, {}, {1e-6}},
yminorticks=true,
ylabel={Amplitude},
axis background/.style={fill=white},
xmajorgrids,
xminorgrids,
ymajorgrids,
yminorgrids
]
\addplot[color=black, mark=none]
2020-10-26 09:43:09 +01:00
table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matcheby1_hpf.csv};
2019-08-17 10:50:06 +02:00
\end{axis}
\begin{axis}[%
width=\fwidth,
height=0.45\fheight,
at={(0\fwidth,0\fheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmode=log,
xmin=0.1,
xmax=10,
xminorticks=true,
xlabel={Frequency [Hz]},
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
every y tick/.append style={black},
ymin=-270,
ymax=90,
ytick={-360, -270, -180, -90, 0, 90},
ylabel={Phase [deg]},
axis background/.style={fill=white},
xmajorgrids,
xminorgrids,
ymajorgrids
]
\addplot[color=black, mark=none]
2020-10-26 09:43:09 +01:00
table [x=freqs, y=phase, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matcheby1_hpf.csv};
2019-08-17 10:50:06 +02:00
\end{axis}
\end{tikzpicture}
#+end_src
#+name: fig:cheby1_hpf
#+caption: First Order Low Pass Filter ([[./figs/cheby1_hpf.png][png]], [[./figs/cheby1_hpf.pdf][pdf]].
#+RESULTS:
[[file:figs/cheby1_hpf.png]]
* Lead - Lag
** Lead
\[ H(s) = \frac{1 + s/\omega_z}{1 + s/\omega_p}, \quad \omega_z < \omega_p \]
- [ ] Find a nice parametrisation to be able to specify the center frequency and the phase added
- [ ] Compute also the change in magnitude
#+begin_src matlab
h = 2.0;
wz = 2*pi/h; % [rad/s]
wp = 2*pi*h; % [rad/s]
H = (1 + s/wz)/(1 + s/wp);
#+end_src
#+begin_src matlab :exports none
freqs = logspace(-1, 1, 1000);
resp = squeeze(freqresp(H, freqs, 'Hz'));
Ha = abs(resp);
Hp = 180/pi*phase(resp);
T = table(freqs', Ha, Hp, 'VariableNames', {'freqs', 'amplitude', 'phase'});
writetable(T,'mat/lead_filter.csv');
#+end_src
#+begin_src latex :file lead_filter.pdf :tangle figs/lead_filter.tex :exports results
\setlength\fwidth{8cm}
\setlength\fheight{6cm}
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\begin{tikzpicture}
\begin{axis}[%
width=\fwidth,
height=0.45\fheight,
at={(0\fwidth,0.5\fheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmode=log,
xmin=0.1,
xmax=10,
xticklabels={{}},
xminorticks=true,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
every y tick/.append style={black},
ymode=log,
% ymin=1e-2,
% ymax=1e1,
% ytick={1e-14, 1e-12, 1e-10, 1e-8, 1e-6},
% yticklabels={{1e-14}, {}, {1e-10}, {}, {1e-6}},
yminorticks=true,
ylabel={Amplitude},
axis background/.style={fill=white},
xmajorgrids,
xminorgrids,
ymajorgrids,
yminorgrids
]
\addplot[color=black, mark=none]
2020-10-26 09:43:09 +01:00
table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlead_filter.csv};
2019-08-17 10:50:06 +02:00
\end{axis}
\begin{axis}[%
width=\fwidth,
height=0.45\fheight,
at={(0\fwidth,0\fheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmode=log,
xmin=0.1,
xmax=10,
xminorticks=true,
xlabel={Frequency [Hz]},
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
every y tick/.append style={black},
ymin=-90,
ymax=90,
ytick={-360, -270, -180, -90, 0, 90},
ylabel={Phase [deg]},
axis background/.style={fill=white},
xmajorgrids,
xminorgrids,
ymajorgrids
]
\addplot[color=black, mark=none]
2020-10-26 09:43:09 +01:00
table [x=freqs, y=phase, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlead_filter.csv};
2019-08-17 10:50:06 +02:00
\end{axis}
\end{tikzpicture}
#+end_src
#+name: fig:lead_filter
#+caption: Lead Filter ([[./figs/lead_filter.png][png]], [[./figs/lead_filter.pdf][pdf]].
#+RESULTS:
[[file:figs/lead_filter.png]]
** Lag
\[ H(s) = \frac{1 + s/\omega_z}{1 + s/\omega_p}, \quad \omega_z > \omega_p \]
- [ ] Find a nice parametrisation to be able to specify the center frequency and the phase added
- [ ] Compute also the change in magnitude
#+begin_src matlab
h = 2.0;
wz = 2*pi*h; % [rad/s]
wp = 2*pi/h; % [rad/s]
H = (1 + s/wz)/(1 + s/wp);
#+end_src
#+begin_src matlab :exports none
freqs = logspace(-1, 1, 1000);
resp = squeeze(freqresp(H, freqs, 'Hz'));
Ha = abs(resp);
Hp = 180/pi*phase(resp);
T = table(freqs', Ha, Hp, 'VariableNames', {'freqs', 'amplitude', 'phase'});
writetable(T,'mat/lag_filter.csv');
#+end_src
#+begin_src latex :file lag_filter.pdf :tangle figs/lag_filter.tex :exports results
\setlength\fwidth{8cm}
\setlength\fheight{6cm}
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\begin{tikzpicture}
\begin{axis}[%
width=\fwidth,
height=0.45\fheight,
at={(0\fwidth,0.5\fheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmode=log,
xmin=0.1,
xmax=10,
xticklabels={{}},
xminorticks=true,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
every y tick/.append style={black},
ymode=log,
% ymin=1e-2,
% ymax=1e1,
% ytick={1e-14, 1e-12, 1e-10, 1e-8, 1e-6},
% yticklabels={{1e-14}, {}, {1e-10}, {}, {1e-6}},
yminorticks=true,
ylabel={Amplitude},
axis background/.style={fill=white},
xmajorgrids,
xminorgrids,
ymajorgrids,
yminorgrids
]
\addplot[color=black, mark=none]
2020-10-26 09:43:09 +01:00
table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlag_filter.csv};
2019-08-17 10:50:06 +02:00
\end{axis}
\begin{axis}[%
width=\fwidth,
height=0.45\fheight,
at={(0\fwidth,0\fheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmode=log,
xmin=0.1,
xmax=10,
xminorticks=true,
xlabel={Frequency [Hz]},
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
every y tick/.append style={black},
ymin=-90,
ymax=90,
ytick={-360, -270, -180, -90, 0, 90},
ylabel={Phase [deg]},
axis background/.style={fill=white},
xmajorgrids,
xminorgrids,
ymajorgrids
]
\addplot[color=black, mark=none]
2020-10-26 09:43:09 +01:00
table [x=freqs, y=phase, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlag_filter.csv};
2019-08-17 10:50:06 +02:00
\end{axis}
\end{tikzpicture}
#+end_src
#+name: fig:lag_filter
#+caption: Lag Filter ([[./figs/lag_filter.png][png]], [[./figs/lag_filter.pdf][pdf]].
#+RESULTS:
[[file:figs/lag_filter.png]]
** Lead Lag
\[ H(s) = \frac{1 + s/\omega_z}{1 + s/\omega_p} \frac{1 + s/\omega_z}{1 + s/\omega_p}, \quad \omega_z > \omega_p \]
#+begin_src matlab
wz1 = 2*pi*1; % [rad/s]
wp1 = 2*pi*0.1; % [rad/s]
wz2 = 2*pi*10; % [rad/s]
wp2 = 2*pi*20; % [rad/s]
H = (1 + s/wz1)/(1 + s/wp1)*(1 + s/wz2)/(1 + s/wp2);
#+end_src
#+begin_src matlab :exports none
freqs = logspace(-2, 2, 1000);
resp = squeeze(freqresp(H, freqs, 'Hz'));
Ha = abs(resp);
Hp = 180/pi*phase(resp);
T = table(freqs', Ha, Hp, 'VariableNames', {'freqs', 'amplitude', 'phase'});
writetable(T,'mat/lead_lag_filter.csv');
#+end_src
#+begin_src latex :file lead_lag_filter.pdf :tangle figs/lead_lag_filter.tex :exports results
\setlength\fwidth{8cm}
\setlength\fheight{6cm}
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\begin{tikzpicture}
\begin{axis}[%
width=\fwidth,
height=0.45\fheight,
at={(0\fwidth,0.5\fheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmode=log,
xmin=0.01,
xmax=100,
xticklabels={{}},
xminorticks=true,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
every y tick/.append style={black},
ymode=log,
% ymin=1e-2,
% ymax=1e1,
% ytick={1e-14, 1e-12, 1e-10, 1e-8, 1e-6},
% yticklabels={{1e-14}, {}, {1e-10}, {}, {1e-6}},
yminorticks=true,
ylabel={Amplitude},
axis background/.style={fill=white},
xmajorgrids,
xminorgrids,
ymajorgrids,
yminorgrids
]
\addplot[color=black, mark=none]
2020-10-26 09:43:09 +01:00
table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlead_lag_filter.csv};
2019-08-17 10:50:06 +02:00
\end{axis}
\begin{axis}[%
width=\fwidth,
height=0.45\fheight,
at={(0\fwidth,0\fheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmode=log,
xmin=0.01,
xmax=100,
xminorticks=true,
xlabel={Frequency [Hz]},
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
every y tick/.append style={black},
ymin=-90,
ymax=90,
ytick={-360, -270, -180, -90, 0, 90},
ylabel={Phase [deg]},
axis background/.style={fill=white},
xmajorgrids,
xminorgrids,
ymajorgrids
]
\addplot[color=black, mark=none]
2020-10-26 09:43:09 +01:00
table [x=freqs, y=phase, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlead_lag_filter.csv};
2019-08-17 10:50:06 +02:00
\end{axis}
\end{tikzpicture}
#+end_src
#+name: fig:lead_lag_filter
#+caption: Lead Lag Filter ([[./figs/lead_lag_filter.png][png]], [[./figs/lead_lag_filter.pdf][pdf]].
#+RESULTS:
[[file:figs/lead_lag_filter.png]]
* Complementary
2020-10-26 09:43:09 +01:00
* Performance Weight
#+begin_src matlab
w0 = 2*pi; % [rad/s]
A = 1e-2;
M = 5;
H = (s/sqrt(M) + w0)^2/(s + w0*sqrt(A))^2;
#+end_src
#+begin_src matlab :exports none
freqs = logspace(-2, 2, 1000);
resp = squeeze(freqresp(inv(H), freqs, 'Hz'));
Ha = abs(resp);
Hp = 180/pi*phase(resp);
T = table(freqs', Ha, Hp, 'VariableNames', {'freqs', 'amplitude', 'phase'});
writetable(T,'mat/weight_first_order.csv');
#+end_src
#+begin_src latex :file weight_first_order.pdf :tangle figs/weight_first_order.tex :exports results
\setlength\fwidth{8cm}
\setlength\fheight{4cm}
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\begin{tikzpicture}
\begin{axis}[%
width=\fwidth,
height=\fheight,
at={(0,0)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
every x tick/.append style={black},
xmode=log,
xmin=0.01,
xmax=100,
xminorticks=true,
xlabel={Frequency [Hz]},
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
every y tick/.append style={black},
ymode=log,
ymin=5e-3,
ymax=1e1,
yminorticks=true,
ylabel={Amplitude},
axis background/.style={fill=white},
xmajorgrids,
xminorgrids,
ymajorgrids,
yminorgrids
]
\addplot[color=black, mark=none]
table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matweight_first_order.csv};
\draw[dashed] (0.01,1e-2) -- (1,1e-2) node[right]{$A$};
\draw[dashed] (1,5) node[left]{$M$} -- (100,5);
\draw[dashed] (1,1) -- (1,0.5) node[below]{$\omega_b^*$};
\end{axis}
\end{tikzpicture}
#+end_src
#+RESULTS:
[[file:figs/weight_first_order.png]]
2019-08-17 10:50:06 +02:00
* Combine Filters
** Additive
- [ ] Explain how phase and magnitude combine
** Multiplicative
2020-10-26 09:43:09 +01:00
* Filters representing noise
Let's consider a noise $n$ that is shaped from a white-noise $\tilde{n}$ with unitary PSD ($\Phi_\tilde{n}(\omega) = 1$) using a transfer function $G(s)$.
The PSD of $n$ is then:
\[ \Phi_n(\omega) = |G(j\omega)|^2 \Phi_{\tilde{n}}(\omega) = |G(j\omega)|^2 \]
The PSD $\Phi_n(\omega)$ is expressed in $\text{unit}^2/\text{Hz}$.
And the root mean square (RMS) of $n(t)$ is:
\[ \sigma_n = \sqrt{\int_{0}^{\infty} \Phi_n(\omega) d\omega} \]
** First Order Low Pass Filter
\[ G(s) = \frac{g_0}{1 + \frac{s}{\omega_c}} \]
#+begin_src matlab
g0 = 1; % Noise Density in unit/sqrt(Hz)
wc = 1; % Cut-Off frequency [rad/s]
G = g0/(1 + s/wc);
% Frequency vector [Hz]
freqs = logspace(-3, 3, 1000);
% PSD of n in [unit^2/Hz]
Phi_n = abs(squeeze(freqresp(G, freqs, 'Hz'))).^2;
% RMS value of n in [unit, rms]
sigma_n = sqrt(trapz(freqs, Phi_n))
#+end_src
\[ \sigma = \frac{1}{2} g_0 \sqrt{\omega_c} \]
with:
- $g_0$ the Noise Density of $n$ in $\text{unit}/\sqrt{Hz}$
- $\omega_c$ the bandwidth over which the noise is located, in rad/s
- $\sigma$ the rms noise
If the cut-off frequency is to be expressed in Hz:
\[ \sigma = \frac{1}{2} g_0 \sqrt{2\pi f_c} = \sqrt{\frac{\pi}{2}} g_0 \sqrt{f_c} \]
Thus, if a sensor is said to have a RMS noise of $\sigma = 10 nm\ rms$ over a bandwidth of $\omega_c = 100 rad/s$, we can estimated the noise density of the sensor to be (supposing a first order low pass filter noise shape):
\[ g_0 = \frac{2 \sigma}{\sqrt{\omega_c}} \quad \left[ m/\sqrt{Hz} \right] \]
#+begin_src matlab :results value replace
2*10e-9/sqrt(100)
#+end_src
#+RESULTS:
: 2e-09
#+begin_src matlab :results value replace
6*0.5*20e-12*sqrt(2*pi*100)
#+end_src
#+RESULTS:
: 1.504e-09