Removed few scripts

This commit is contained in:
Thomas Dehaeze 2020-11-12 09:27:24 +01:00
parent f32ff33474
commit 9677b4d3c4
7 changed files with 5 additions and 328 deletions

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,54 +0,0 @@
%% Load Data
iff_g10 = load('../mat/apa95ml_iff_g10_res.mat', 'u', 't', 'y', 'v');
iff_g100 = load('../mat/apa95ml_iff_g100_res.mat', 'u', 't', 'y', 'v');
iff_of = load('../mat/apa95ml_iff_off_res.mat', 'u', 't', 'y', 'v');
%% Compute TF
Ts = 1e-4;
win = hann(ceil(10/Ts));
[tf_iff_g10, f] = tfestimate(iff_g10.u, iff_g10.y, win, [], [], 1/Ts);
[co_iff_g10, ~] = mscohere(iff_g10.u, iff_g10.y, win, [], [], 1/Ts);
[tf_iff_g100, f] = tfestimate(iff_g100.u, iff_g100.y, win, [], [], 1/Ts);
[co_iff_g100, ~] = mscohere(iff_g100.u, iff_g100.y, win, [], [], 1/Ts);
[tf_iff_of, ~] = tfestimate(iff_of.u, iff_of.y, win, [], [], 1/Ts);
[co_iff_of, ~] = mscohere(iff_of.u, iff_of.y, win, [], [], 1/Ts);
%% Coherence
figure;
hold on;
plot(f, co_iff_of, '-', 'DisplayName', 'g=0')
plot(f, co_iff_g10, '-', 'DisplayName', 'g=10')
plot(f, co_iff_g100, '-', 'DisplayName', 'g=100')
set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'lin');
ylabel('Coherence'); xlabel('Frequency [Hz]');
hold off;
legend();
xlim([60, 600])
%% Compare Dynamics IFF ON/OFF
figure;
ax1 = subplot(2, 1, 1);
hold on;
plot(f, abs(tf_iff_of), '-', 'DisplayName', 'g=0')
plot(f, abs(tf_iff_g10), '-', 'DisplayName', 'g=10')
plot(f, abs(tf_iff_g100), '-', 'DisplayName', 'g=100')
set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'log');
ylabel('Amplitude'); xlabel('Frequency [Hz]');
hold off;
legend();
ax2 = subplot(2, 1, 2);
hold on;
plot(f, 180/pi*angle(-tf_iff_of), '-')
plot(f, 180/pi*angle(-tf_iff_g10), '-')
plot(f, 180/pi*angle(-tf_iff_g100), '-')
set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'lin');
ylabel('Phase'); xlabel('Frequency [Hz]');
hold off;
linkaxes([ax1,ax2], 'x');
xlim([60, 600]);

View File

@ -1,112 +0,0 @@
tg = slrt;
%%
f = SimulinkRealTime.openFTP(tg);
mget(f, 'apa95ml.dat', 'data');
close(f);
%% Convert the Data
data = SimulinkRealTime.utils.getFileScopeData('data/apa95ml.dat').data;
u = data(:, 1); % Input Voltage [V]
y = data(:, 2); % Output Displacement [m]
v = data(:, 3); % Output Voltage (Force Sensor) [V]
t = data(:, 4); % Time [s]
save('../mat/apa95ml_5kg_1a_2s.mat', 'u', 't', 'y', 'v');
%%
figure;
subplot(1,2,1);
plot(t, u)
subplot(1,2,2);
plot(t, y)
%%
load('../mat/apa95ml_5kg_10V.mat', 'u', 't', 'y');
ht = load('../mat/huddle_test.mat', 'u', 't', 'y');
u = u - mean(u);
y = y - mean(y);
%%
[pxx, f] = pwelch(y, win, [], [], 1/Ts);
[pht, ~] = pwelch(ht.y, win, [], [], 1/Ts);
figure;
hold on;
plot(f, pxx);
plot(f, pht);
hold off;
set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'log');
ylabel('PSD'); xlabel('Frequency [Hz]');
%%
run setup;
win = hann(ceil(0.1/Ts));
[tf_est, f] = tfestimate(u, y, win, [], [], 1/Ts);
[co_est, ~] = mscohere(u, y, 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]');
hold off;
ax2 = subplot(2, 1, 2);
hold on;
plot(f, 180/pi*unwrap(angle(-tf_est)), 'k-')
set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'lin');
ylabel('Phase'); xlabel('Frequency [Hz]');
hold off;
linkaxes([ax1,ax2], 'x');
xlim([10, 5000]);
%%
win = hann(ceil(10/Ts));
[tf_est, f] = tfestimate(u, v, win, [], [], 1/Ts);
[co_est, ~] = mscohere(u, v, 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]');
hold off;
ax2 = subplot(2, 1, 2);
hold on;
plot(f, 180/pi*unwrap(angle(-tf_est)), 'k-')
set(gca, 'Xscale', 'log'); set(gca, 'Yscale', 'lin');
ylabel('Phase'); xlabel('Frequency [Hz]');
hold off;
linkaxes([ax1,ax2], 'x');
xlim([10, 5000]);

5
matlab/setup.m Executable file → Normal file
View File

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

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,54 +0,0 @@
tg = slrt;
%% Gains to test
g_iff = [0, 1, 5, 10, 50, 100];
results = {zeros(1, length(g_iff))};
if tg.Connected == "Yes"
stop(tg);
%% Set Parameters for the Simulation
% setparam(tg, 'Noise', 'Variance', 0);
setparam(tg, 'Sine', 'Amplitude', 0);
setparam(tg, 'DC_value', 'Value', 0);
setparam(tg, 'Chirp_gain', 'Gain', 0.03);
setparam(tg, 'iff_enable', 'Gain', 1);
if tg.Status == "stopped"
for i = 1:length(g_iff)
setparam(tg, 'g_iff', 'Gain', g_iff(i));
fprintf('(%i/%i) - Testing for g_iff = %.1f', i, length(g_iff), g_iff(i));
start(tg);
pause(101);
stop(tg);
setparam(tg, 'g_iff', 'Gain', 0);
%%
f = SimulinkRealTime.openFTP(tg);
mget(f, 'apa95ml.dat', 'data');
close(f);
%% Convert the Data
data = SimulinkRealTime.utils.getFileScopeData('data/apa95ml.dat').data;
u = data(:, 1); % Input Voltage [V]
y = data(:, 2); % Output Displacement [m]
v = data(:, 3); % Output Voltage (Force Sensor) [V]
t = data(:, 4); % Time [s]
results(i) = {struct('t', t, 'u', u, 'y', y, 'v', v)};
end
end
end
save('../mat/apa95ml_iff_test.mat', 'results');
%% Best functions
% viewTargetScreen(tg);

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