comparison m-toolbox/test/test_ao_eqmotion.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 % Test ao/eqmotion for the solution of a torsion pendulum equation of the
3 % motion
4 %
5 % 25-03-2009 L. Ferraioli
6 % CREATION
7 %
8 % $Id: test_ao_eqmotion.m,v 1.1 2009/03/27 12:25:15 luigi Exp $
9 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10 %% Generate data
11
12 % generate signal + white noise
13 a = ao(plist('tsfcn','20.*sin(2.*pi.*t./800)+randn(size(t))','fs',1,'nsecs',1e5,'yunits','rad'));
14
15 %% Solve equation of Motion for the torsion pendulum
16
17 % Set pendulum parameters
18 I = 4.31e-5; % Moment of Inertia
19 T0 = 563; % Oscillatory period
20 Q = 2880; % Quality factor
21 Gam = I*(2*pi/T0)^2;
22
23 % building coefficients AO
24 alpha2 = cdata(I);
25 alpha2.setYunits(unit('kg').*unit('m').^2./unit('rad'));
26 alpha2 = ao(alpha2);
27
28 alpha1 = cdata(Gam./(2.*pi.*Q./T0));
29 alpha1.setYunits(unit('kg').*unit('m').^2./unit('rad')./unit('s'));
30 alpha1 = ao(alpha1);
31
32 alpha0 = cdata(Gam);
33 alpha0.setYunits(unit('kg').*unit('m').^2./unit('rad')./unit('s').^2);
34 alpha0 = ao(alpha0);
35
36 % Calculate torque output units are defined by the coefficients units
37 pl1 = plist('ALPHA2',alpha2,'ALPHA1',alpha1,'ALPHA0',alpha0);
38 b1 = eqmotion(a,pl1);
39 b1.simplifyYunits;
40 b1.setName;
41
42 % Alternative torque calculation set the targunits to get appropiate output
43 % units
44 pl2 = plist('ALPHA2',I,'ALPHA1',Gam./(2.*pi.*Q./T0),'ALPHA0',Gam,'TARGETUNITS',unit('kg').*unit('m').^2./unit('s').^2);
45 b2 = eqmotion(a,pl2);
46 b2.simplifyYunits;
47 b2.setName;
48
49 % plotting
50 iplot(b1,b2)
51
52 %% Extract TF
53
54 tf1 = tfe(a,b1,plist('Nfft',1e4));
55
56 tf2 = tfe(a,b2,plist('Nfft',1e4));
57
58 % Theorethical TF
59 f = logspace(-4,log10(0.5),300);
60 f = f.';
61 s = 1i.*2.*pi.*f;
62 I = 4.31e-5;
63 T0 = 563;
64 Q = 2880;
65 Gam = I*(2*pi/T0)^2;
66 TF = I.*s.^2 + (Gam./(2.*pi.*Q./T0)).*s + Gam;
67 TF = ao(plist('xvals',f,'yvals',TF,'dtype','fsdata','fs',a.fs));
68 TF.setYunits(tf1.yunits);
69 TF.setName;
70
71 % plot
72 iplot(TF,tf1,tf2)