clear all
close all

load('transient_oscillations.mat')

% generate data example
duration = max(t);
n = duration / dt+1
fmax=1/dt;

figure(1)
subplot(2,1,1)
plot(t,final)
xlabel('time')
ylabel('data')

subplot(2,1,2)
% compute FT
num_windows=5;
num_window_points=n/num_windows;
num_overlap = 0.0 * num_window_points;
duration_window=duration/num_windows;
df=1/duration_window;
num_maxf1=2.0/df;
[pxx1,f1] = pwelch(final,num_window_points,num_overlap,num_window_points,fmax);
num_windows=5;
num_window_points=n/num_windows;
num_overlap = 0.5 * num_window_points;
duration_window=duration/num_windows;
df=1/duration_window;
[pxx2,f2] = pwelch(final,num_window_points,num_overlap,num_window_points,fmax);
%plot(f,10*log10(pxx))
num_maxf2=2.0/df;
%plot(f1(1:num_maxf1),pxx1(1:num_maxf1),f2(1:num_maxf2),pxx2(1:num_maxf2),'r')
plot(f1(1:num_maxf1),10*log(pxx1(1:num_maxf1)),f2(1:num_maxf2),10*log(pxx2(1:num_maxf2)),'r')
%plot(f1(1:num_maxf1),pxx1(1:num_maxf1))
xlabel('frequency')
ylabel('power spectral density [dB]')

