echo off;
close all; % figure を全部閉じる

%%%%%%%%%%%%
% FFT 分析 %
%%%%%%%%%%%%

sample = 0.00075; % サンプリング周期
no = result(8000:40000,:); % 制御なしの区間を抜き出す(1 〜 5 秒)
yes = result(48000:80000,:); % 制御ありの区間を抜き出す(6 〜 10 秒)

% z
[amp_no,freq] = realfft(no(:,2),sample);
[amp_yes,freq] = realfft(yes(:,2),sample);
figure(1);
clf;
loglog(freq, amp_no, 'b', freq, amp_yes, 'r');
xlabel('Frequency [Hz]');
ylabel('Amplitude of z');
legend('without control', 'with control',3);
axis([10, 2000, 1e-5, 1]);
print -djpeg -r70 data/z_fft.jpg;

% w
[amp_w_no,freq] = realfft(no(:,5),sample);
[amp_w_yes,freq] = realfft(yes(:,5),sample);
figure(2);
clf;
loglog(freq, amp_w_no, 'b', freq, amp_w_yes, 'r');
xlabel('Frequency [Hz]');
ylabel('Amplitude of w');
legend('without control', 'with control',3);
axis([10, 2000, 1e-4, 1]);
print -djpeg -r70 data/w_fft.jpg;

% z/w
figure(3);
clf;
loglog(freq, amp_no./amp_w_no, 'b', freq, amp_yes./amp_w_yes, 'r');
xlabel('Frequency [Hz]');
ylabel('Amplitude of z/w');
legend('without control', 'with control',3);
axis([10, 2000, 1e-4, 10]);
print -djpeg -r70 data/zw_fft.jpg;
