Initial Commit

This commit is contained in:
Thomas Dehaeze 2020-07-17 11:46:45 +02:00
commit 6591b9a3ba
4 changed files with 185 additions and 0 deletions

BIN
data/apa95ml_5kg.dat Executable file

Binary file not shown.

123
index.org Normal file
View File

@ -0,0 +1,123 @@
#+TITLE: Test Bench APA
:DRAWER:
#+STARTUP: overview
#+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>
#+HTML_MATHJAX: align: center tagside: right font: TeX
#+PROPERTY: header-args:matlab :session *MATLAB*
#+PROPERTY: header-args:matlab+ :comments org
#+PROPERTY: header-args:matlab+ :results none
#+PROPERTY: header-args:matlab+ :exports both
#+PROPERTY: header-args:matlab+ :eval no-export
#+PROPERTY: header-args:matlab+ :output-dir figs
#+PROPERTY: header-args:matlab+ :tangle no
#+PROPERTY: header-args:matlab+ :mkdirp yes
#+PROPERTY: header-args:shell :eval no-export
#+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
: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
* Parameters
#+begin_src matlab
Ts = 1e-4;
#+end_src
* Filter White Noise
#+begin_src matlab
Glpf = 1/(1 + s/2/pi/500);
Gz = c2d(Glpf, Ts, 'tustin');
#+end_src
* Load Data
#+begin_src matlab
data = SimulinkRealTime.utils.getFileScopeData('data/apa95ml_5kg.dat').data;
#+end_src
* Time Domain Data
#+begin_src matlab
figure;
subplot(1,2,1);
plot(data(:, 3), data(:, 1))
ylabel('Input Voltage [V]'); xlabel('Time [s]');
subplot(1,2,2);
plot(data(:, 3), data(:, 2))
ylabel('Output Displacement [m]'); xlabel('Time [s]');
#+end_src
* Compute TF estimate and Coherence
#+begin_src matlab
win = hann(ceil(1/Ts));
[tf_est, f] = tfestimate(data(:, 1), -data(:, 2), win, [], [], 1/Ts);
[co_est, ~] = mscohere( data(:, 1), -data(:, 2), win, [], [], 1/Ts);
#+end_src
* Coherence
#+begin_src matlab
figure;
hold on;
plot(f, co_est, 'k-')
set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'lin');
ylabel('Coherence'); xlabel('Frequency [Hz]');
hold off;
#+end_src
* Transfer Function
#+begin_src matlab
figure;
ax1 = subplot(2, 1, 1);
hold on;
plot(f, abs(tf_est), 'k-')
set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'log');
ylabel('Amplitude'); xlabel('Frequency [Hz]');
hold off;
ax2 = subplot(2, 1, 2);
hold on;
plot(f, 180/pi*angle(tf_est), 'k-')
set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'lin');
ylabel('Phase'); xlabel('Frequency [Hz]');
legend();
hold off;
linkaxes([ax1,ax2], 'x');
xlim([10, 5000]);
#+end_src

56
matlab/runtest.m Executable file
View File

@ -0,0 +1,56 @@
tg = slrt;
%%
f = SimulinkRealTime.openFTP(tg);
mget(f, 'apa95ml.dat');
% remove file on RT-target
% removefile(f, 'C:\data\data_001.dat')
close(f);
%% Convert the Data
data = SimulinkRealTime.utils.getFileScopeData('apa95ml.dat').data;
%%
figure;
subplot(1,2,1);
plot(data(:, 3), data(:, 1))
subplot(1,2,2);
plot(data(:, 3), data(:, 2))
%%
run setup;
win = hann(ceil(0.1/Ts));
[tf_est, f] = tfestimate(data(:, 1), data(:, 2), win, [], [], 1/Ts);
[co_est, ~] = mscohere(data(:, 1), data(:, 2), win, [], [], 1/Ts);
%%
figure;
hold on;
plot(f, co_est, 'k-')
set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'lin');
ylabel('Coherence'); xlabel('Frequency [Hz]');
hold off;
%%
figure;
ax1 = subplot(2, 1, 1);
hold on;
plot(f, abs(tf_est), 'k-', 'DisplayName', 'Identified')
set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'log');
ylabel('Amplitude'); xlabel('Frequency [Hz]');
legend();
hold off;
ax2 = subplot(2, 1, 2);
hold on;
plot(f, 180/pi*angle(-tf_est), 'k-')
set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'lin');
ylabel('Phase'); xlabel('Frequency [Hz]');
legend();
hold off;
linkaxes([ax1,ax2], 'x');
xlim([10, 5000]);

6
matlab/setup.m Executable file
View File

@ -0,0 +1,6 @@
s = tf('s');
Ts = 1e-4;
Glpf = 1/(1 + s/2/pi/500);
Gz = c2d(Glpf, Ts, 'tustin');