% ADXL320main_3.m - PRM - 12/14/04
%
% This is the main file for simulating the ADXL320 Behavioral model.
%
% The data is stored in the matrix Y. The matrix X contains all the state information.
%
%
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear % clear all variables
ADXL320_constants % reread initial data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The input acceleration definition: (X Channel)
xinamp=1 % X input amplitude (Gee peak)
xinfreq=10; % X input frequency
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The input acceleration definition: (Y Channel)
yinamp=1; % Y input amplitude (Gee peak)
yinfreq=10; % Y input frequency
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The input acceleration definition: (Z Channel Cross Axis)
zinamp=0; % Z input amplitude (Gee Peak)
zinfreq=10; % Z input frequency
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Perform simulation: Calculate the X & Y output vectors:
xtstop=0.2; % the end of the simulation (seconds)
ytstop=0.2; % the end of the simulation (seconds)
reltol=1e-7; % relative tolerance
maxstep=0.1e-5; % max step during simulation (seconds)
% Set up options for simulation
OPTIONS = simset('RelTol',reltol,'MaxStep',maxstep);
% Set up time base
T=[0:maxstep:xtstop]';
% Sinusoid, continuous (+/- amplitude)
u1t=xinamp*sin(2*pi*xinfreq*T); % sine wave
u2t=yinamp*sin(2*pi*yinfreq*T); % sine wave
u3t=zinamp*sin(2*pi*zinfreq*T); % sine wave
% Create input matrix. Each "u1t" corresponds to an input port.
U=[T,u1t,u2t,u3t];
% Perform the simulation!
[t,X,Y]=sim('ADXL320_3',xtstop,OPTIONS,U);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create plots
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1)
hold off
plot(t,Y(:,1))
grid on
title(['ADXL320 Model - X Input Acceleration - ',date])
ylabel('Acceleration (g)')
xlabel('Time (seconds)')
orient tall
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(2)
hold off
plot(t,Y(:,2))
grid on
title(['ADXL320 Model - X Output Voltage - ',date])
ylabel('Volts')
xlabel('Time (seconds)')
orient tall
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(3)
hold on
plot(t,Y(:,3),'r')
grid on
title(['ADXL320 Model - Y Input Acceleration - ',date])
ylabel('Acceleration (g)')
xlabel('Time (seconds)')
orient tall
% print
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(4)
hold on
plot(t,Y(:,4),'r')
grid on
title(['ADXL320 Model - Y Output Voltage - ',date])
ylabel('Volts')
xlabel('Time (seconds)')
orient tall
% print
hold off