diff --git a/index.html b/index.html index d671c53..23be0da 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + List of filters - Matlab Implementation @@ -280,40 +280,79 @@ for the JavaScript code in this tag.

Table of Contents

- -
-

1 Low Pass

+
+

1 Proportional - Integral - Derivative

-
-

1.1 First Order

-
+
+

1.1 Proportional

+
+ +
+

1.2 Integral

+
+ +
+

1.3 Derivative

+
+
+ +
+

2 Low Pass

+
+
+
+

2.1 First Order

+

\[ H(s) = \frac{1}{1 + s/\omega_0} \]

@@ -326,7 +365,7 @@ H = 1/<
-
+

lpf_first_order.png

Figure 1: First Order Low Pass Filter (png, pdf.

@@ -335,9 +374,9 @@ H = 1/<
-
-

1.2 Second Order

-
+
+

2.2 Second Order

+

\[ H(s) = \frac{1}{1 + 2 \xi / \omega_0 s + s^2/\omega_0^2} \]

@@ -351,7 +390,7 @@ H = 1/<
-
+

lpf_second_order.png

Figure 2: Second Order Low Pass Filter (png, pdf.

@@ -360,9 +399,9 @@ H = 1/<
-
-

1.3 Combine multiple filters

-
+
+

2.3 Combine multiple filters

+

\[ H(s) = \left( \frac{1}{1 + s/\omega_0} \right)^n \]

@@ -376,23 +415,42 @@ H = ( +

lpf_multiple_first_order.png

Figure 3: Combine Multiple First Order Low Pass Filter (png, pdf.

-
-
-

2 High Pass

-
+
+

2.4 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} + + +
+
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;
+
-
-

2.1 First Order

-
+
+
+
+ +
+

3 High Pass

+
+
+
+

3.1 First Order

+

\[ H(s) = \frac{s/\omega_0}{1 + s/\omega_0} \]

@@ -405,7 +463,7 @@ H = (s -
+

hpf_first_order.png

Figure 4: First Order High Pass Filter (png, pdf.

@@ -414,9 +472,9 @@ H = (s -
-

2.2 Second Order

-
+
+

3.2 Second Order

+

\[ H(s) = \frac{s^2/\omega_0^2}{1 + 2 \xi / \omega_0 s + s^2/\omega_0^2} \]

@@ -430,7 +488,7 @@ H = (s -
+

hpf_second_order.png

Figure 5: Second Order High Pass Filter (png, pdf.

@@ -439,9 +497,9 @@ H = (s -
-

2.3 Combine multiple filters

-
+
+

3.3 Combine multiple filters

+

\[ H(s) = \left( \frac{s/\omega_0}{1 + s/\omega_0} \right)^n \]

@@ -455,7 +513,7 @@ H = ( +

hpf_multiple_first_order.png

Figure 6: Combine Multiple First Order High Pass Filter (png, pdf.

@@ -466,21 +524,38 @@ H = ( -

3 Band Pass

+
+

4 Band Pass

-
-

4 Notch

+
+

5 Notch

-
-

5 Chebyshev

-
+
+

6 Bump

+
+
+
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})
+
-
-

5.1 Chebyshev Type I

-
+
+
+ + +
+

7 Chebyshev

+
+
+
+

7.1 Chebyshev Type I

+
n = 4; % Order of the filter
 Rp = 3; % Maximum peak-to-peak ripple [dB]
@@ -492,7 +567,7 @@ H = ss(A, B, C, D
 
 
-
+

cheby1_hpf.png

Figure 7: First Order Low Pass Filter (png, pdf.

@@ -501,13 +576,141 @@ H = ss(A, B, C, D
-
-

6 Complementary

+
+

8 Lead - Lag

+
+
+
+

8.1 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
  • +
+ +
+
h = 2.0;
+wz = 2*pi/h; % [rad/s]
+wp = 2*pi*h; % [rad/s]
+
+H = (1 + s/wz)/(1 + s/wp);
+
+
+ + +
+

lead_filter.png +

+

Figure 8: Lead Filter (png, pdf.

+
+
+
+ +
+

8.2 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
  • +
+ +
+
h = 2.0;
+wz = 2*pi*h; % [rad/s]
+wp = 2*pi/h; % [rad/s]
+
+H = (1 + s/wz)/(1 + s/wp);
+
+
+ + +
+

lag_filter.png +

+

Figure 9: Lag Filter (png, pdf.

+
+
+
+ +
+

8.3 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 \] +

+ +
+
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);
+
+
+ + +
+

lead_lag_filter.png +

+

Figure 10: Lead Lag Filter (png, pdf.

+
+
+
+
+ +
+

9 Complementary

+
+
+

10 Performance Weight

+
+
+
w0 = 2*pi; % [rad/s]
+A = 1e-2;
+M = 5;
+
+H = (s/sqrt(M) + w0)^2/(s + w0*sqrt(A))^2;
+
+
+ + +
+

weight_first_order.png +

+
+
+
+ +
+

11 Combine Filters

+
+
+
+

11.1 Additive

+
+
    +
  • [ ] Explain how phase and magnitude combine
  • +
+
+
+ +
+

11.2 Multiplicative

+

Author: Dehaeze Thomas

-

Created: 2019-08-15 jeu. 12:24

+

Created: 2019-10-08 mar. 13:27

Validate

diff --git a/index.org b/index.org index 085472f..881e656 100644 --- a/index.org +++ b/index.org @@ -15,7 +15,7 @@ #+HTML_HEAD: #+HTML_HEAD: -#+PROPERTY: header-args:latex :headers '("\\usepackage{tikz}" "\\usepackage{import}" "\\import{$HOME/MEGA/These/LaTeX/}{config.tex}") +#+PROPERTY: header-args:latex :headers '("\\usepackage{tikz}" "\\usepackage{import}" "\\import{$HOME/Cloud/tikz/org/}{config.tex}") #+PROPERTY: header-args:latex+ :imagemagick t :fit yes #+PROPERTY: header-args:latex+ :iminoptions -scale 100% -density 150 #+PROPERTY: header-args:latex+ :imoutoptions -quality 100 @@ -37,7 +37,6 @@ #+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) <> @@ -113,7 +112,7 @@ yminorgrids ] \addplot[color=black, mark=none] - table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/MEGA/These/Matlab/filters/mat/lpf_first_order.csv}; + table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlpf_first_order.csv}; \end{axis} \begin{axis}[% @@ -143,7 +142,7 @@ ymajorgrids ] \addplot[color=black, mark=none] - table [x=freqs, y=phase, col sep=comma] {/home/thomas/MEGA/These/Matlab/filters/mat/lpf_first_order.csv}; + table [x=freqs, y=phase, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlpf_first_order.csv}; \end{axis} \end{tikzpicture} #+end_src @@ -213,7 +212,7 @@ yminorgrids ] \addplot[color=black, mark=none] - table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/MEGA/These/Matlab/filters/mat/lpf_second_order.csv}; + table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlpf_second_order.csv}; \end{axis} \begin{axis}[% @@ -243,7 +242,7 @@ ymajorgrids ] \addplot[color=black, mark=none] - table [x=freqs, y=phase, col sep=comma] {/home/thomas/MEGA/These/Matlab/filters/mat/lpf_second_order.csv}; + table [x=freqs, y=phase, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlpf_second_order.csv}; \end{axis} \end{tikzpicture} #+end_src @@ -253,7 +252,6 @@ #+RESULTS: [[file:figs/lpf_second_order.png]] - ** Combine multiple filters \[ H(s) = \left( \frac{1}{1 + s/\omega_0} \right)^n \] @@ -313,7 +311,7 @@ yminorgrids ] \addplot[color=black, mark=none] - table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/MEGA/These/Matlab/filters/mat/lpf_multiple_first_order.csv}; + table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlpf_multiple_first_order.csv}; \end{axis} \begin{axis}[% @@ -343,15 +341,13 @@ ymajorgrids ] \addplot[color=black, mark=none] - table [x=freqs, y=phase, col sep=comma] {/home/thomas/MEGA/These/Matlab/filters/mat/lpf_multiple_first_order.csv}; + table [x=freqs, y=phase, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlpf_multiple_first_order.csv}; \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]]. -#+RESULTS: -[[file:figs/lpf_multiple_first_order.png]] ** Nice combination @@ -427,7 +423,7 @@ yminorgrids ] \addplot[color=black, mark=none] - table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/MEGA/These/Matlab/filters/mat/hpf_first_order.csv}; + table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/mathpf_first_order.csv}; \end{axis} \begin{axis}[% @@ -457,7 +453,7 @@ ymajorgrids ] \addplot[color=black, mark=none] - table [x=freqs, y=phase, col sep=comma] {/home/thomas/MEGA/These/Matlab/filters/mat/hpf_first_order.csv}; + table [x=freqs, y=phase, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/mathpf_first_order.csv}; \end{axis} \end{tikzpicture} #+end_src @@ -527,7 +523,7 @@ yminorgrids ] \addplot[color=black, mark=none] - table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/MEGA/These/Matlab/filters/mat/hpf_second_order.csv}; + table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/mathpf_second_order.csv}; \end{axis} \begin{axis}[% @@ -557,7 +553,7 @@ ymajorgrids ] \addplot[color=black, mark=none] - table [x=freqs, y=phase, col sep=comma] {/home/thomas/MEGA/These/Matlab/filters/mat/hpf_second_order.csv}; + table [x=freqs, y=phase, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/mathpf_second_order.csv}; \end{axis} \end{tikzpicture} #+end_src @@ -627,7 +623,7 @@ yminorgrids ] \addplot[color=black, mark=none] - table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/MEGA/These/Matlab/filters/mat/hpf_multiple_first_order.csv}; + table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/mathpf_multiple_first_order.csv}; \end{axis} \begin{axis}[% @@ -657,7 +653,7 @@ ymajorgrids ] \addplot[color=black, mark=none] - table [x=freqs, y=phase, col sep=comma] {/home/thomas/MEGA/These/Matlab/filters/mat/hpf_multiple_first_order.csv}; + table [x=freqs, y=phase, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/mathpf_multiple_first_order.csv}; \end{axis} \end{tikzpicture} #+end_src @@ -673,6 +669,18 @@ * Notch +* 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 + + * Chebyshev ** Chebyshev Type I @@ -734,7 +742,7 @@ yminorgrids ] \addplot[color=black, mark=none] - table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/MEGA/These/Matlab/filters/mat/cheby1_hpf.csv}; + table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matcheby1_hpf.csv}; \end{axis} \begin{axis}[% @@ -764,7 +772,7 @@ ymajorgrids ] \addplot[color=black, mark=none] - table [x=freqs, y=phase, col sep=comma] {/home/thomas/MEGA/These/Matlab/filters/mat/cheby1_hpf.csv}; + table [x=freqs, y=phase, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matcheby1_hpf.csv}; \end{axis} \end{tikzpicture} #+end_src @@ -838,7 +846,7 @@ yminorgrids ] \addplot[color=black, mark=none] - table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/MEGA/These/Matlab/filters/mat/lead_filter.csv}; + table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlead_filter.csv}; \end{axis} \begin{axis}[% @@ -868,7 +876,7 @@ ymajorgrids ] \addplot[color=black, mark=none] - table [x=freqs, y=phase, col sep=comma] {/home/thomas/MEGA/These/Matlab/filters/mat/lead_filter.csv}; + table [x=freqs, y=phase, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlead_filter.csv}; \end{axis} \end{tikzpicture} #+end_src @@ -941,7 +949,7 @@ yminorgrids ] \addplot[color=black, mark=none] - table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/MEGA/These/Matlab/filters/mat/lag_filter.csv}; + table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlag_filter.csv}; \end{axis} \begin{axis}[% @@ -971,7 +979,7 @@ ymajorgrids ] \addplot[color=black, mark=none] - table [x=freqs, y=phase, col sep=comma] {/home/thomas/MEGA/These/Matlab/filters/mat/lag_filter.csv}; + table [x=freqs, y=phase, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlag_filter.csv}; \end{axis} \end{tikzpicture} #+end_src @@ -1042,7 +1050,7 @@ yminorgrids ] \addplot[color=black, mark=none] - table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/MEGA/These/Matlab/filters/mat/lead_lag_filter.csv}; + table [x=freqs, y=amplitude, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlead_lag_filter.csv}; \end{axis} \begin{axis}[% @@ -1072,7 +1080,7 @@ ymajorgrids ] \addplot[color=black, mark=none] - table [x=freqs, y=phase, col sep=comma] {/home/thomas/MEGA/These/Matlab/filters/mat/lead_lag_filter.csv}; + table [x=freqs, y=phase, col sep=comma] {/home/thomas/Cloud/thesis/matlab/filters/matlead_lag_filter.csv}; \end{axis} \end{tikzpicture} #+end_src @@ -1083,8 +1091,132 @@ [[file:figs/lead_lag_filter.png]] * Complementary +* 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]] + * Combine Filters ** Additive - [ ] Explain how phase and magnitude combine ** Multiplicative +* 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