Compare commits

..

No commits in common. "c2fec7b2369a112c211bd13ec248c804f238bacb" and "5afe1bcdd1214e094c3b6c5e7091e7399e36091f" have entirely different histories.

5 changed files with 10 additions and 223 deletions

116
index.org
View File

@ -50,134 +50,38 @@
<<matlab-init>>
#+end_src
* Setup
:PROPERTIES:
:header-args:matlab+: :tangle matlab/setup_experiment.m
:header-args:matlab+: :comments org :mkdirp yes
:END:
** Parameters
* Parameters
#+begin_src matlab
Ts = 1e-4;
#+end_src
** Filter White Noise
* Filter White Noise
#+begin_src matlab
Glpf = 1/(1 + s/2/pi/500);
Gz = c2d(Glpf, Ts, 'tustin');
#+end_src
* Run Experiment and Save Data
:PROPERTIES:
:header-args:matlab+: :tangle matlab/run_experiment.m
:header-args:matlab+: :comments org :mkdirp yes
:END:
** Load Data
* Load Data
#+begin_src matlab
data = SimulinkRealTime.utils.getFileScopeData('data/apa95ml.dat').data;
data = SimulinkRealTime.utils.getFileScopeData('data/apa95ml_5kg.dat').data;
#+end_src
** 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
figure;
plot(t, y)
ylabel('Output Displacement [m]'); xlabel('Time [s]');
#+end_src
** PSD of Measurement Noise
#+begin_src matlab
Ts = t(end)/(length(t)-1);
Fs = 1/Ts;
win = hanning(ceil(1*Fs));
#+end_src
#+begin_src matlab
[pxx, f] = pwelch(y, win, [], [], Fs);
#+end_src
#+begin_src matlab
figure;
plot(f, sqrt(pxx));
set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
xlabel('Frequency [Hz]'); ylabel('ASD [$m/\sqrt{Hz}$]');
#+end_src
* 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
ht = load('./mat/huddle_test.mat', 't', 'u', 'y');
load('./mat/apa95ml_5kg.mat', 't', 'u', 'y');
#+end_src
** Time Domain Data
* Time Domain Data
#+begin_src matlab
figure;
subplot(1,2,1);
plot(t, u)
plot(data(:, 3), data(:, 1))
ylabel('Input Voltage [V]'); xlabel('Time [s]');
subplot(1,2,2);
plot(t, y)
plot(data(:, 3), data(:, 2))
ylabel('Output Displacement [m]'); xlabel('Time [s]');
#+end_src
** Comparison of the PSD with Huddle Test
#+begin_src matlab
Ts = t(end)/(length(t)-1);
Fs = 1/Ts;
win = hanning(ceil(1*Fs));
#+end_src
#+begin_src matlab
[pxx, f] = pwelch(y, win, [], [], Fs);
[pht, ~] = pwelch(ht.y, win, [], [], Fs);
#+end_src
#+begin_src matlab
figure;
hold on;
plot(f, sqrt(pxx), 'DisplayName', '5kg');
plot(f, sqrt(pht), 'DisplayName', 'Huddle Test');
hold off;
set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
xlabel('Frequency [Hz]'); ylabel('ASD [$m/\sqrt{Hz}$]');
legend('locaation', 'norteast');
#+end_src
** Compute TF estimate and Coherence
* Compute TF estimate and Coherence
#+begin_src matlab
win = hann(ceil(1/Ts));
@ -185,7 +89,7 @@
[co_est, ~] = mscohere( data(:, 1), -data(:, 2), win, [], [], 1/Ts);
#+end_src
** Coherence
* Coherence
#+begin_src matlab
figure;
@ -196,7 +100,7 @@
hold off;
#+end_src
** Transfer Function
* Transfer Function
#+begin_src matlab
figure;
ax1 = subplot(2, 1, 1);

View File

@ -1,23 +0,0 @@
% Load Data
load('./mat/huddle_test.mat', 't', 'u', 'y');
% Time Domain Data
figure;
plot(t, y)
ylabel('Output Displacement [m]'); xlabel('Time [s]');
% PSD of Measurement Noise
Ts = t(end)/(length(t)-1);
Fs = 1/Ts;
win = hanning(ceil(1*Fs));
[pxx, f] = pwelch(y, win, [], [], Fs);
figure;
plot(f, sqrt(pxx));
set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
xlabel('Frequency [Hz]'); ylabel('ASD [$m/\sqrt{Hz}$]');

View File

@ -1,11 +0,0 @@
% Load Data
data = SimulinkRealTime.utils.getFileScopeData('data/apa95ml.dat').data;
% Save Data
u = data(:, 1); % Input Voltage [V]
y = data(:, 2); % Output Displacement [m]
t = data(:, 3); % Time [s]
save('./mat/huddle_test.mat', 't', 'u', 'y', 'Glpf');

View File

@ -1,9 +0,0 @@
% Parameters
Ts = 1e-4;
% Filter White Noise
Glpf = 1/(1 + s/2/pi/500);
Gz = c2d(Glpf, Ts, 'tustin');

View File

@ -1,74 +0,0 @@
% Load Data
ht = load('./mat/huddle_test.mat', 't', 'u', 'y');
load('./mat/apa95ml_5kg.mat', 't', 'u', 'y');
% Time Domain Data
figure;
subplot(1,2,1);
plot(t, u)
ylabel('Input Voltage [V]'); xlabel('Time [s]');
subplot(1,2,2);
plot(t, y)
ylabel('Output Displacement [m]'); xlabel('Time [s]');
% Comparison of the PSD with Huddle Test
Ts = t(end)/(length(t)-1);
Fs = 1/Ts;
win = hanning(ceil(1*Fs));
[pxx, f] = pwelch(y, win, [], [], Fs);
[pht, ~] = pwelch(ht.y, win, [], [], Fs);
figure;
hold on;
plot(f, sqrt(pxx), 'DisplayName', '5kg');
plot(f, sqrt(pht), 'DisplayName', 'Huddle Test');
hold off;
set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
xlabel('Frequency [Hz]'); ylabel('ASD [$m/\sqrt{Hz}$]');
legend('locaation', 'norteast');
% Compute TF estimate and Coherence
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);
% Coherence
figure;
hold on;
plot(f, co_est, 'k-')
set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'lin');
ylabel('Coherence'); xlabel('Frequency [Hz]');
hold off;
% Transfer Function
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]);