test-bench-apa300ml/matlab/frf_analyze.m

87 lines
1.8 KiB
Mathematica
Raw Normal View History

2021-06-01 23:16:49 +02:00
%% Clear Workspace and Close figures
clear; close all; clc;
%% Intialize Laplace variable
s = zpk('s');
addpath('./src/');
% Test with one APA
%% Load measurement data for APA number 1
load(sprintf('mat/frf_data_%i.mat', 1), 't', 'Va', 'Vs', 'de', 'da');
2021-06-01 13:05:36 +02:00
2021-06-01 18:24:01 +02:00
2021-06-01 23:16:49 +02:00
% Time domain data:
2021-06-01 18:24:01 +02:00
figure;
plot(t, de);
2021-06-01 23:16:49 +02:00
% Compute transfer functions:
2021-06-01 18:24:01 +02:00
Ts = (t(end) - t(1))/(length(t)-1);
Fs = 1/Ts;
2021-06-01 23:16:49 +02:00
win = hanning(ceil(0.5*Fs)); % Hannning Windows
2021-06-01 18:24:01 +02:00
[G_dvf, f] = tfestimate(Va, de, win, [], [], 1/Ts);
[G_d, ~] = tfestimate(Va, da, win, [], [], 1/Ts);
[G_iff, ~] = tfestimate(Va, Vs, win, [], [], 1/Ts);
figure;
tiledlayout(2, 1, 'TileSpacing', 'None', 'Padding', 'None');
ax1 = nexttile;
hold on;
plot(f, abs(G_dvf));
plot(f, abs(G_d));
hold off;
set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
ylabel('Amplitude $V_{out}/V_{in}$ [V/V]'); set(gca, 'XTickLabel',[]);
hold off;
2021-06-01 23:16:49 +02:00
ylim([10, 30]);
2021-06-01 18:24:01 +02:00
ax2 = nexttile;
hold on;
plot(f, 180/pi*angle(G_dvf));
plot(f, 180/pi*angle(G_d));
hold off;
set(gca, 'XScale', 'log'); set(gca, 'YScale', 'lin');
xlabel('Frequency [Hz]'); ylabel('Phase [deg]');
hold off;
yticks(-360:90:360);
linkaxes([ax1,ax2],'x');
xlim([5, 5e3]);
figure;
tiledlayout(2, 1, 'TileSpacing', 'None', 'Padding', 'None');
ax1 = nexttile;
plot(f, abs(G_iff));
set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
ylabel('Amplitude $V_{out}/V_{in}$ [V/V]'); set(gca, 'XTickLabel',[]);
hold off;
2021-06-01 23:16:49 +02:00
ylim([10, 30]);
2021-06-01 18:24:01 +02:00
ax2 = nexttile;
plot(f, 180/pi*angle(G_iff));
set(gca, 'XScale', 'log'); set(gca, 'YScale', 'lin');
xlabel('Frequency [Hz]'); ylabel('Phase [deg]');
hold off;
yticks(-360:90:360);
linkaxes([ax1,ax2],'x');
2021-06-01 23:16:49 +02:00
xlim([5, 5e3]);
% Comparison of all APA
%% Load all the measurements
meas_data = {};
for i = 1:7
meas_data(i) = {load(sprintf('mat/frf_data_%i.mat', i), 't', 'Va', 'Vs', 'de', 'da')};
end