#+TITLE: Measurement of Piezoelectric Amplifiers
:DRAWER:
#+LANGUAGE: en
#+EMAIL: dehaeze.thomas@gmail.com
#+AUTHOR: Dehaeze Thomas

#+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>

#+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
#+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:

* Introduction                                                        :ignore:

Two voltage amplifiers are tested:
- PI E-505.00 ([[https://www.pi-usa.us/en/products/controllers-drivers-motion-control-software/piezo-drivers-controllers-power-supplies-high-voltage-amplifiers/e-505-piezo-amplifier-module-602300/][link]])
- Cedrat Technology LA75B ([[https://www.cedrat-technologies.com/en/products/piezo-controllers/electronic-amplifier-boards.html][link]])

The piezoelectric actuator under test is an APA95ML from Cedrat technology.
It contains three stacks with a capacitance of $5 \mu F$ each that can be connected independently to the amplifier.

* Effect of a change of capacitance
** 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

** Cedrat Technology
Load Data
#+begin_src matlab
  piezo1 = load('mat/cedrat_la75b_med_1_stack.mat', 't', 'V_in', 'V_out');
  piezo2 = load('mat/cedrat_la75b_med_2_stack.mat', 't', 'V_in', 'V_out');
  piezo3 = load('mat/cedrat_la75b_med_3_stack.mat', 't', 'V_in', 'V_out');
#+end_src

Compute Coherence and Transfer functions
#+begin_src matlab
  Ts = 1e-4;
  win = hann(ceil(0.1/Ts));

  [tf_1, f_1] = tfestimate(piezo1.V_in, piezo1.V_out, win, [], [], 1/Ts);
  [co_1, ~] = mscohere(piezo1.V_in, piezo1.V_out, win, [], [], 1/Ts);


  [tf_2, f_2] = tfestimate(piezo2.V_in, piezo2.V_out, win, [], [], 1/Ts);
  [co_2, ~] = mscohere(piezo2.V_in, piezo2.V_out, win, [], [], 1/Ts);


  [tf_3, f_3] = tfestimate(piezo3.V_in, piezo3.V_out, win, [], [], 1/Ts);
  [co_3, ~] = mscohere(piezo3.V_in, piezo3.V_out, win, [], [], 1/Ts);
#+end_src

#+begin_src matlab :exports none
  figure;
  ax1 = subplot(2, 1, 1);
  hold on;
  plot(f_1, abs(tf_1), 'DisplayName', '1 stack')
  plot(f_2, abs(tf_2), 'DisplayName', '2 stacks')
  plot(f_3, abs(tf_3), 'DisplayName', '3 stacks')
  set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'log');
  ylabel('Amplitude'); xlabel('Frequency [Hz]');
  hold off;
  legend('location', 'southwest');
  ylim([1, 40]);

  ax2 = subplot(2, 1, 2);
  hold on;
  plot(f_1, 180/pi*unwrap(angle(tf_1)))
  plot(f_2, 180/pi*unwrap(angle(tf_2)))
  plot(f_3, 180/pi*unwrap(angle(tf_3)))
  set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'lin');
  ylabel('Phase'); xlabel('Frequency [Hz]');
  hold off;
  ylim([-270, 90]);
  yticks(-360:90:90)

  linkaxes([ax1,ax2], 'x');
  xlim([10, 5000]);
#+end_src

#+begin_src matlab :tangle no :exports results :results file replace
  exportFig('figs/change_capa_cedrat.pdf', 'width', 'full', 'height', 'full');
#+end_src

#+name: fig:change_capa_cedrat
#+caption: Effect of a change of the piezo capacitance on the Amplifier transfer function
#+RESULTS:
[[file:figs/change_capa_cedrat.png]]

** PI
#+begin_src matlab
  piezo1 = load('mat/pi_505_high.mat', 't', 'V_in', 'V_out');
  piezo2 = load('mat/pi_505_high_2_stacks.mat', 't', 'V_in', 'V_out');
  piezo3 = load('mat/pi_505_high_3_stacks.mat', 't', 'V_in', 'V_out');
#+end_src

#+begin_src matlab
  Ts = 1e-4;
  win = hann(ceil(0.1/Ts));

  [tf_1, f_1] = tfestimate(piezo1.V_in, piezo1.V_out, win, [], [], 1/Ts);
  [co_1, ~] = mscohere(piezo1.V_in, piezo1.V_out, win, [], [], 1/Ts);


  [tf_2, f_2] = tfestimate(piezo2.V_in, piezo2.V_out, win, [], [], 1/Ts);
  [co_2, ~] = mscohere(piezo2.V_in, piezo2.V_out, win, [], [], 1/Ts);


  [tf_3, f_3] = tfestimate(piezo3.V_in, piezo3.V_out, win, [], [], 1/Ts);
  [co_3, ~] = mscohere(piezo3.V_in, piezo3.V_out, win, [], [], 1/Ts);
#+end_src

#+begin_src matlab :exports none
  figure;
  ax1 = subplot(2, 1, 1);
  hold on;
  plot(f_1, abs(tf_1), 'DisplayName', '1 stack')
  plot(f_2, abs(tf_2), 'DisplayName', '2 stacks')
  plot(f_3, abs(tf_3), 'DisplayName', '3 stacks')
  set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'log');
  ylabel('Amplitude'); xlabel('Frequency [Hz]');
  hold off;
  legend('location', 'southwest');
  ylim([0.05, 11]);

  ax2 = subplot(2, 1, 2);
  hold on;
  plot(f_1, 180/pi*unwrap(angle(tf_1)))
  plot(f_2, 180/pi*unwrap(angle(tf_2)))
  plot(f_3, 180/pi*unwrap(angle(tf_3)))
  set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'lin');
  ylabel('Phase'); xlabel('Frequency [Hz]');
  hold off;
  ylim([-360, 0]);
  yticks(-360:90:90)

  linkaxes([ax1,ax2], 'x');
  xlim([10, 5000]);
#+end_src

#+begin_src matlab :tangle no :exports results :results file replace
  exportFig('figs/change_capa_pi.pdf', 'width', 'full', 'height', 'full');
#+end_src

#+name: fig:change_capa_pi
#+caption: Effect of a change of the piezo capacitance on the Amplifier transfer function
#+RESULTS:
[[file:figs/change_capa_pi.png]]

* Effect of a change in Voltage level
** 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

** Cedrat Technology
#+begin_src matlab
  hi = load('mat/cedrat_la75b_high_1_stack.mat', 't', 'V_in', 'V_out');
  me = load('mat/cedrat_la75b_med_1_stack.mat', 't', 'V_in', 'V_out');
  lo = load('mat/cedrat_la75b_low_1_stack.mat', 't', 'V_in', 'V_out');
#+end_src

#+begin_src matlab
  Ts = 1e-4;
  win = hann(ceil(0.1/Ts));

  [tf_hi, f_hi] = tfestimate(hi.V_in, hi.V_out, win, [], [], 1/Ts);
  [co_hi, ~] = mscohere(hi.V_in, hi.V_out, win, [], [], 1/Ts);

  [tf_me, f_me] = tfestimate(me.V_in, me.V_out, win, [], [], 1/Ts);
  [co_me, ~] = mscohere(me.V_in, me.V_out, win, [], [], 1/Ts);

  [tf_lo, f_lo] = tfestimate(lo.V_in, lo.V_out, win, [], [], 1/Ts);
  [co_lo, ~] = mscohere(lo.V_in, lo.V_out, win, [], [], 1/Ts);
#+end_src

#+begin_src matlab :exports none
  figure;
  ax1 = subplot(2, 1, 1);
  hold on;
  plot(f_lo, abs(tf_lo), 'DisplayName', 'low')
  plot(f_me, abs(tf_me), 'DisplayName', 'med')
  plot(f_hi, abs(tf_hi), 'DisplayName', 'high')
  set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'log');
  ylabel('Amplitude'); xlabel('Frequency [Hz]');
  hold off;
  legend('location', 'southwest');
  ylim([1, 50]);

  ax2 = subplot(2, 1, 2);
  hold on;
  plot(f_lo, 180/pi*unwrap(angle(tf_lo)))
  plot(f_me, 180/pi*unwrap(angle(tf_me)))
  plot(f_hi, 180/pi*unwrap(angle(tf_hi)))
  set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'lin');
  ylabel('Phase'); xlabel('Frequency [Hz]');
  hold off;
  ylim([-360, 0]);
  yticks(-360:90:90)

  linkaxes([ax1,ax2], 'x');
  xlim([10, 5000]);
#+end_src

#+begin_src matlab :tangle no :exports results :results file replace
  exportFig('figs/change_level_cedrat.pdf', 'width', 'full', 'height', 'full');
#+end_src

#+name: fig:change_level_cedrat
#+caption: Effect of a change of voltage level on the Amplifier transfer function
#+RESULTS:
[[file:figs/change_level_cedrat.png]]

** PI
#+begin_src matlab
  hi = load('mat/pi_505_high.mat', 't', 'V_in', 'V_out');
  lo = load('mat/pi_505_low.mat', 't', 'V_in', 'V_out');
#+end_src

#+begin_src matlab
  Ts = 1e-4;
  win = hann(ceil(0.1/Ts));

  [tf_hi, f_hi] = tfestimate(hi.V_in, hi.V_out, win, [], [], 1/Ts);
  [co_hi, ~] = mscohere(hi.V_in, hi.V_out, win, [], [], 1/Ts);

  [tf_lo, f_lo] = tfestimate(lo.V_in, lo.V_out, win, [], [], 1/Ts);
  [co_lo, ~] = mscohere(lo.V_in, lo.V_out, win, [], [], 1/Ts);
#+end_src

#+begin_src matlab :exports none
  figure;
  ax1 = subplot(2, 1, 1);
  hold on;
  plot(f_hi, abs(tf_hi), 'DisplayName', 'high')
  plot(f_lo, abs(tf_lo), 'DisplayName', 'low')
  set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'log');
  ylabel('Amplitude'); xlabel('Frequency [Hz]');
  hold off;
  legend('location', 'southwest');
  ylim([0.1, 20]);

  ax2 = subplot(2, 1, 2);
  hold on;
  plot(f_hi, 180/pi*unwrap(angle(tf_hi)))
  plot(f_lo, 180/pi*unwrap(angle(tf_lo)))
  set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'lin');
  ylabel('Phase'); xlabel('Frequency [Hz]');
  hold off;
  ylim([-360, 0]);
  yticks(-360:90:90)

  linkaxes([ax1,ax2], 'x');
  xlim([10, 5000]);
#+end_src

#+begin_src matlab :tangle no :exports results :results file replace
  exportFig('figs/change_level_pi.pdf', 'width', 'full', 'height', 'full');
#+end_src

#+name: fig:change_level_pi
#+caption: Effect of a change of voltage level on the Amplifier transfer function
#+RESULTS:
[[file:figs/change_level_pi.png]]

* Comparison PI / Cedrat
** 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

** Results
#+begin_src matlab
  ce_results = load('mat/cedrat_la75b_high_1_stack.mat', 't', 'V_in', 'V_out');
  pi_results = load('mat/pi_505_high.mat', 't', 'V_in', 'V_out');
#+end_src

#+begin_src matlab
  Ts = 1e-4;
  win = hann(ceil(0.1/Ts));

  [tf_ce, f_ce] = tfestimate(ce_results.V_in, ce_results.V_out, win, [], [], 1/Ts);
  [tf_pi, f_pi] = tfestimate(pi_results.V_in, pi_results.V_out, win, [], [], 1/Ts);
#+end_src

#+begin_src matlab :exports none
  figure;
  ax1 = subplot(2, 1, 1);
  hold on;
  plot(f_pi, abs(tf_pi), 'DisplayName', 'PI')
  plot(f_ce, abs(tf_ce), 'DisplayName', 'Cedrat')
  set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'log');
  ylabel('Amplitude'); xlabel('Frequency [Hz]');
  hold off;
  legend('location', 'southwest');
  ylim([0.1, 50]);

  ax2 = subplot(2, 1, 2);
  hold on;
  plot(f_pi, 180/pi*unwrap(angle(tf_pi)))
  plot(f_ce, 180/pi*unwrap(angle(tf_ce)))
  set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'lin');
  ylabel('Phase'); xlabel('Frequency [Hz]');
  hold off;
  ylim([-360, 0]);
  yticks(-360:90:90)

  linkaxes([ax1,ax2], 'x');
  xlim([10, 5000]);
#+end_src

#+begin_src matlab :tangle no :exports results :results file replace
  exportFig('figs/tf_amplifiers_comp.pdf', 'width', 'full', 'height', 'full');
#+end_src

#+name: fig:tf_amplifiers_comp
#+caption: Comparison of the two Amplifier transfer functions
#+RESULTS:
[[file:figs/tf_amplifiers_comp.png]]
