clear
clc

D=load('Z_beschleunigung.mat');
D = D.Z_beschleunigung;
%skalierung von messdaten
Z_a_vibration=D(:,2);%%Z_vibration_Zeit 
Ts=1e-3; %sample time 
Fs=1/Ts; %sample frequenz(Hz)
x=D(:,2);
t1=D(:,1);
Ndata=length(x); %sample punkte
t=[0:1/Fs:(Ndata-1)/Fs];
N=2.^10;
N=1000;
n=0:N-1; %plus
f=n*Fs/N;
subplot(2,2,1) %plus
plot(t1,Z_a_vibration,'g','Linewidth',1.0);
title('signal_original');
xlabel('Zeit');
ylabel('Beschleunigung');
Y_z = fft(Z_a_vibration,N); %fft translation for z-achse fft±ä»¯
Ayy_z =(abs(Y_z));
subplot(2,2,2); %plus
plot(f,Ayy_z,'g');
title('FFT-Modulus');
xlabel('sample-punkt');
ylabel('FFT-Modulus');
Ayy_z=Ayy_z/(N/2);
Ayy_z(1)=Ayy_z(1)/2;
subplot(2,2,3);
plot(f(1:N/2),Ayy_z(1:N/2),'g'); 
title('Amplitude-frequenz');
xlabel('Frequenz');
ylabel('Betrag');
%% phase
Pyy=[1:N/2];
for i=1:N/2
    Pyy(i)=phase(Y_z(i));   % Phase
    Pyy(i)=Pyy(i)*180/pi; % as Winkel
end
%figure;
subplot(2,2,4);
plot(f(1:N/2),Pyy(1:N/2));
title('Phase-frequency');

grid on;