Add code to analyze experiments

This commit is contained in:
Thomas Dehaeze 2020-07-20 09:44:30 +02:00
parent 5afe1bcdd1
commit 89e0e13629

View File

@ -50,24 +50,58 @@
<<matlab-init>> <<matlab-init>>
#+end_src #+end_src
* Parameters * Setup
:PROPERTIES:
:header-args:matlab+: :tangle matlab/setup_experiment.m
:header-args:matlab+: :comments org :mkdirp yes
:END:
** Parameters
#+begin_src matlab #+begin_src matlab
Ts = 1e-4; Ts = 1e-4;
#+end_src #+end_src
* Filter White Noise ** Filter White Noise
#+begin_src matlab #+begin_src matlab
Glpf = 1/(1 + s/2/pi/500); Glpf = 1/(1 + s/2/pi/500);
Gz = c2d(Glpf, Ts, 'tustin'); Gz = c2d(Glpf, Ts, 'tustin');
#+end_src #+end_src
* Load Data * Run Experiment and Save Data
:PROPERTIES:
:header-args:matlab+: :tangle matlab/run_experiment.m
:header-args:matlab+: :comments org :mkdirp yes
:END:
** Load Data
#+begin_src matlab #+begin_src matlab
data = SimulinkRealTime.utils.getFileScopeData('data/apa95ml_5kg.dat').data; data = SimulinkRealTime.utils.getFileScopeData('data/apa95ml.dat').data;
#+end_src #+end_src
* Time Domain Data ** Save Data
#+begin_src matlab
u = data(:, 1); % Input Voltage [V]
y = data(:, 2); % Output Displacement [m]
t = data(:, 3); % Time [s]
#+end_src
#+begin_src matlab
save('./mat/huddle_test.mat', 't', 'u', 'y', 'Glpf');
#+end_src
* Huddle Test
:PROPERTIES:
:header-args:matlab+: :tangle matlab/huddle_test.m
:header-args:matlab+: :comments org :mkdirp yes
:END:
** Load Data
#+begin_src matlab
load('./mat/huddle_test.mat', 't', 'u', 'y');
#+end_src
** Time Domain Data
#+begin_src matlab #+begin_src matlab
figure; figure;
@ -81,7 +115,34 @@
ylabel('Output Displacement [m]'); xlabel('Time [s]'); ylabel('Output Displacement [m]'); xlabel('Time [s]');
#+end_src #+end_src
* Compute TF estimate and Coherence ** PSD of Measurement Noise
* Transfer Function Estimation with m=5kg
:PROPERTIES:
:header-args:matlab+: :tangle matlab/tf_estimation.m
:header-args:matlab+: :comments org :mkdirp yes
:END:
** Load Data
#+begin_src matlab
load('./mat/huddle_test.mat', 't', 'u', 'y');
#+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 #+begin_src matlab
win = hann(ceil(1/Ts)); win = hann(ceil(1/Ts));
@ -89,7 +150,7 @@
[co_est, ~] = mscohere( data(:, 1), -data(:, 2), win, [], [], 1/Ts); [co_est, ~] = mscohere( data(:, 1), -data(:, 2), win, [], [], 1/Ts);
#+end_src #+end_src
* Coherence ** Coherence
#+begin_src matlab #+begin_src matlab
figure; figure;
@ -100,7 +161,7 @@
hold off; hold off;
#+end_src #+end_src
* Transfer Function ** Transfer Function
#+begin_src matlab #+begin_src matlab
figure; figure;
ax1 = subplot(2, 1, 1); ax1 = subplot(2, 1, 1);