%% Simulation Zweimasseschwinger bei Weganregung
%
%Start.m
%f.m
%
%25.11.2014
%Thomas Schmid


%% Variablen

clear all, close all
global t            %Zeit
global x0 x0m fs fe %Erregerschwingung (Amplitude, Startfrequenz, Endfrequenz)
global w0 x0p       %Kreisfrequenz Erregerschwingung, Ableitung Erregerschwingung
global tm           %Dauer der Modalanalyse
global n E b h l    %Anzahl, Elastizität und Abmessungen Blattfedern
global g lp         %Erdbeschleunigung, Länge Tilgerpendel
global m1 m2        %Masse Hauptsystem(1)/Tilger(2)
global D1 D2        %Dämpfungsgrad (experimentell bestimmt)

global c1 c2        %Federkonstante Hauptsystem/Tilger
global d1 d2        %Dämpfungskonstante Hauptsystem/Tilger
global w01 w02      %Eigenkreisfrequenzen
global f01 f02      %Eigenfrequenzen

global x1           %Schwingung Hauptsystem
global x2           %Schwingung Tilgermasse

%% Deklaration

%Blattfeder
n=4
E=2.1*10^11
b=0.15
h=0.0008
l=0.35

%Pendel
g=9.81
lp=0.07

%Systeme
m1=5.195
m2=0.490
D1=0.0065
D2=0.0085

%Anregung
x0m=0.0001
fs=1
fe=5
tm=60

%% Anregung (Modalanalyse, linear)

t=linspace(0,tm,6000)           %Zeit von t=0 bis t=tmax
w0=(2*pi)*(fs+[(fe-fs)/tm]*t)   %Kreisfrequenz steigt linear von Fstart zu Fend
x0=x0m*sin(w0.*t)
x0p=gradient(x0)

%% Nebenrechnungen

c1=n*E*b*h^3/l^3    %Federkonstante der Blattfedern
c2=g*m2/lp          %Federkonstante Tilger (Ersatzsystem)

w01=sqrt(c1+c2/m1)  %Eigenkreisfrequenz Hauptsystem
w02=sqrt(c2/m2)     %Eigenkreisfrequenz Tilger
f01=w01/(2*pi)
f02=w02/(2*pi)

d2=2*w02*D2*m2      %Dämpfungskonstante Tilger
d1=2*w01*D1*m1-d2   %Dämpfungskonstante Hauptsystem

%% Lösen der DGL

xp=[0;0;0;0];                           %Startwerte fuer Integration
[t,x1]=ode45('f1',[0:tm],xp);   %Integration Pendel mit Schwingungsdaempfer

%% Plotten der Anregungsfunktionen x0 sowie x0p

figure('Name', 'Anregungsfunktion','NumberTitle','off'); grid on
subplot (1,2,1);plot(t,x0)
title('Anregung (x0)', 'Color','b', 'FontWeight','bold')
xlabel('Zeit [s]'); ylabel('Weg [m]')
subplot (1,2,2);plot(t,x0p)
title('Anregung (x0p)', 'Color','b', 'FontWeight','bold')
xlabel('Zeit [s]'); ylabel('Geschwindigkeit [m/s]')

%% Plotten der Ausgangsfunktionen x1 sowie x2

figure('Name', 'Anregungsfunktion','NumberTitle','off'); grid on
subplot (1,2,1);plot(t,x1)
title('Hauptsystem(x1)', 'Color','b', 'FontWeight','bold')
xlabel('Zeit [s]'); ylabel('Weg [m]')
subplot (1,2,2);plot(t,x2)
title('Tilgersystem(x2)', 'Color','b', 'FontWeight','bold')
xlabel('Zeit [s]'); ylabel('Weg [m]')

