% Function to estimate: aircraft true mach number, air density, speed of sound 
% and temperature 

% Given:
% alt = altitude (m)
% ias = indicated airspeed (knots)

% Calculate:
% mtrue = aircraft true mach number (dimensionless)
% rho = air density (kg/cu. meter)
% a_alt = speed of sound (m/s)
% temp = temperature of air (deg. Kelvin)

% programmer : A. Trani
% date: Oct/20/2006

function [mtrue,a_alt,rho,temp] = isam(alt,ias)

rho_zero = 1.225;			% density at sea level (kg/m-m-m)
load atmosphere;			% loads ISA atmospheric tables

h = atmosphere(:,1);		% vector with values of altitude
t = atmosphere(:,2);		% vector with values of temperature
r = atmosphere(:,3);		% vector with values of density
a = atmosphere(:,4);		% vector with values of speed

rho 	= interp1(h,r,alt,'cubic');	% interpolates to get density
mtrue 	= sqrt(5 * ((rho_zero/rho *((1 + 0.2 * (ias/661.5)^2)...
			^3.5 -1) + 1)^0.286 -1));
a_alt 	= interp1(h,a,alt,'cubic');	% gets speed of sound
temp 	= interp1(h,t,alt,'cubic');	% gets temperature


