nass-micro-station-measurem.../disturbance-ty/matlab/disturbance_ty.m

276 lines
7.4 KiB
Mathematica
Raw Normal View History

2019-05-14 14:10:58 +02:00
%% Clear Workspace and Close figures
clear; close all; clc;
%% Intialize Laplace variable
s = zpk('s');
% Load data
z_ty = load('mat/data_040.mat', 'data'); z_ty = z_ty.data;
e_ty = load('mat/data_041.mat', 'data'); e_ty = e_ty.data;
e_of = load('mat/data_042.mat', 'data'); e_of = e_of.data;
% Time domain plots
figure;
hold on;
plot(z_ty(:, 3), z_ty(:, 1), 'DisplayName', 'Marble - Z');
plot(z_ty(:, 3), z_ty(:, 2), 'DisplayName', 'Sample - Z');
hold off;
xlabel('Time [s]'); ylabel('Voltage [V]');
xlim([0, 100]); ylim([-5, 5]);
legend('Location', 'northeast');
% #+NAME: fig:ty_z_time
% #+CAPTION: Z motion of the sample and marble when scanning with the translation stage
% #+RESULTS: fig:ty_z_time
% [[file:figs/ty_z_time.png]]
xlim([0, 1])
% #+NAME: fig:ty_z_time_zoom
% #+CAPTION: Z motion of the sample and marble when scanning with the translation stage - Zoom
% #+RESULTS: fig:ty_z_time_zoom
% [[file:figs/ty_z_time_zoom.png]]
figure;
hold on;
plot(e_ty(:, 3), e_ty(:, 1), 'DisplayName', 'Marble - X');
plot(e_ty(:, 3), e_ty(:, 2), 'DisplayName', 'Sample - X');
hold off;
xlabel('Time [s]'); ylabel('Voltage [V]');
xlim([0, 100]); ylim([-10, 10]);
legend('Location', 'northeast');
% #+NAME: fig:ty_e_time
% #+CAPTION: Motion of the sample and marble in the east direction when scanning with the translation stage
% #+RESULTS: fig:ty_e_time
% [[file:figs/ty_e_time.png]]
xlim([0, 1])
% Frequency Domain analysis
% We first compute some parameters that will be used for the PSD computation.
dt = z_ty(2, 3)-z_ty(1, 3);
Fs = 1/dt; % [Hz]
win = hanning(ceil(10*Fs));
% Then we compute the Power Spectral Density using =pwelch= function.
% First for the geophone located on the marble
[pxz_ty_m, f] = pwelch(z_ty(:, 1), win, [], [], Fs);
[pxe_ty_m, ~] = pwelch(e_ty(:, 1), win, [], [], Fs);
[pxe_of_m, ~] = pwelch(e_of(:, 1), win, [], [], Fs);
% And for the geophone located at the sample position.
[pxz_ty_s, f] = pwelch(z_ty(:, 2), win, [], [], Fs);
[pxe_ty_s, ~] = pwelch(e_ty(:, 2), win, [], [], Fs);
[pxe_of_s, ~] = pwelch(e_of(:, 2), win, [], [], Fs);
% And we plot the ASD of the measured signals:
% - figure [[fig:asd_east_marble]] compares the marble motion in the east direction when scanning and when Ty is OFF
% - figure [[fig:asd_east_sample]] compares the sample motion in the east direction when scanning and when Ty is OFF
% - figure [[fig:asd_z_direction]] shows the marble and sample motion in the Z direction when scanning with the translation stage
figure;
hold on;
plot(f, sqrt(pxe_ty_m), 'DisplayName', 'Ty 1Hz - Marble - X');
plot(f, sqrt(pxe_of_m), 'DisplayName', 'Ty OFF - Marble - X');
hold off;
set(gca, 'xscale', 'log');
set(gca, 'yscale', 'log');
xlabel('Frequency [Hz]'); ylabel('ASD of the measured Voltage $\left[\frac{V}{\sqrt{Hz}}\right]$')
legend('Location', 'northwest');
xlim([0.1, 500]); ylim([1e-5, 1e1]);
% #+NAME: fig:asd_east_marble
% #+CAPTION: Amplitude spectral density of the measure voltage corresponding to the geophone in the east direction located on the marble when the translation stage is OFF and when it is scanning at 1Hz
% #+RESULTS: fig:asd_east_marble
% [[file:figs/asd_east_marble.png]]
figure;
hold on;
plot(f, sqrt(pxe_ty_s), 'DisplayName', 'Ty 1Hz - Sample - X');
plot(f, sqrt(pxe_of_s), 'DisplayName', 'Ty OFF - Sample - X');
hold off;
set(gca, 'xscale', 'log');
set(gca, 'yscale', 'log');
xlabel('Frequency [Hz]'); ylabel('ASD of the measured Voltage $\left[\frac{V}{\sqrt{Hz}}\right]$')
legend('Location', 'northwest');
xlim([0.1, 500]); ylim([1e-5, 1e1]);
% #+NAME: fig:asd_east_sample
% #+CAPTION: Amplitude spectral density of the measure voltage corresponding to the geophone in the east direction located at the sample location when the translation stage is OFF and when it is scanning at 1Hz
% #+RESULTS: fig:asd_east_sample
% [[file:figs/asd_east_sample.png]]
figure;
hold on;
plot(f, sqrt(pxz_ty_m), 'DisplayName', 'Ty 1Hz - Marble - Z');
plot(f, sqrt(pxz_ty_s), 'DisplayName', 'Ty 1Hz - Sample - Z');
hold off;
set(gca, 'xscale', 'log');
set(gca, 'yscale', 'log');
xlabel('Frequency [Hz]'); ylabel('ASD of the measured Voltage $\left[\frac{V}{\sqrt{Hz}}\right]$')
legend('Location', 'northwest');
xlim([0.1, 500]); ylim([1e-5, 1e1]);
% Transfer function from marble motion in the East direction to sample motion in the East direction
% Let's compute the transfer function for the marble motion in the east direction to the sample motion in the east direction.
% We first plot the time domain motions when every stage is off (figure [[fig:east_marble_sample]]).
figure;
hold on;
plot(e_of(:, 3), e_of(:, 2), 'DisplayName', 'Sample - X');
plot(e_of(:, 3), e_of(:, 1), 'DisplayName', 'Marble - X');
hold off;
xlabel('Time [s]'); ylabel('Voltage [V]');
xlim([0, 100]); ylim([-1, 1]);
legend('Location', 'northeast');
% #+NAME: fig:east_marble_sample
% #+CAPTION: East motion of the marble and sample when all the stages are OFF
% #+RESULTS: fig:east_marble_sample
% [[file:figs/east_marble_sample.png]]
% We then compute the transfer function using =tfestimate=.
dt = e_of(2, 3)-e_of(1, 3);
Fs = 1/dt; % [Hz]
win = hanning(ceil(10*Fs));
[T, f] = tfestimate(e_of(:, 1), e_of(:, 2), win, [], [], Fs);
% The result is shown on figure [[fig:tf_east_marble_sample]].
figure;
ax1 = subplot(2, 1, 1);
hold on;
plot(f, abs(T));
hold off;
set(gca, 'xscale', 'log'); set(gca, 'yscale', 'log');
set(gca, 'XTickLabel',[]);
ylabel('Magnitude');
ax2 = subplot(2, 1, 2);
hold on;
plot(f, mod(180+180/pi*phase(T), 360)-180);
hold off;
set(gca, 'xscale', 'log');
ylim([-180, 180]);
yticks([-180, -90, 0, 90, 180]);
xlabel('Frequency [Hz]'); ylabel('Phase [deg]');
linkaxes([ax1,ax2],'x');
xlim([10, 100]);
% #+RESULTS:
% #+begin_example
% 1 Elmo txt chart ver 2.0
% 2
% 3 [File Properties]
% 4 Creation Time,2019-05-13 05:11:45
% 5 Last Updated,2019-05-13 05:11:45
% 6 Resolution,0.001
% 7 Sampling Time,5E-05
% 8 Recording Time,5.461
% 9
% 10 [Chart Properties]
% 11 No.,Name,X Linear,X No.
% 12 1,Chart #1,True,0
% 13 2,Chart #2,True,0
% 14
% 15 [Chart Data]
% 16 Display No.,X No.,Y No.,X Unit,Y Unit,Color,Style,Width
% 17 1,1,2,sec,N/A,ff0000ff,Solid,TwoPoint
% 18 2,1,3,sec,N/A,ff0000ff,Solid,TwoPoint
% 19 2,1,4,sec,N/A,ff007f00,Solid,TwoPoint
% 20
% 21 [Signal Names]
% 22 1,Time (sec)
% 23 2,Position [cnt]
% 24 3,Current Command [A]
% 25 4,Total Current Command [A]
% 26
% 27 [Signals Data Group 1]
% 28 1,2,3,4,
% 29 0,1110769,-0.320872406596209,-0.320872406596209,
% 30 0.001,1108743,-0.319658428261391,-0.319658428261391,
% #+end_example
% The real data starts at line 29.
% We then load this =cvs= file starting at line 29.
data = csvread("mat/sin_elmo.csv", 29, 0);
% Time domain data
% We plot the position of the translation stage measured by the encoders.
% There is 200000 encoder count for each mm, we then divide by 200000 to obtain mm.
% The result is shown on figure [[fig:ty_position_time]].
figure;
hold on;
plot(data(:, 1), data(:, 2)/200000);
hold off;
xlim([0, 5]);
xlabel('Time [s]'); ylabel('Position [mm]');
% #+NAME: fig:ty_position_time_zoom
% #+CAPTION: Y position of the translation stage measured by the encoders - Zoom
% #+RESULTS: fig:ty_position_time_zoom
% [[file:figs/ty_position_time_zoom.png]]
% We also plot the current as function of the time on figure [[fig:current_time]].
figure;
hold on;
plot(data(:, 1), data(:, 3));
hold off;
xlim([0, 5]); ylim([-10, 10]);
xlabel('Time [s]'); ylabel('Current [A]');