function [Vequivalent,qcOverp0,qcOverp]=AS2(Vcalibrated,p)
% function [Vequivalent,qcOverp0,qcOverp]=AS2(Vcalibrated,p)
% Computes the Scale Altitude Correction a.k.a. "Compressibility Correction"
% Vcalibrated is calibrated velocity.
% p is static pressure at which Vcalibrated is known.
% Vcalibrated and p are row vectors.
% Assumes Vcalibrated <=ao.
% Units are knots and lbf/ft^2.
% Theses equations are a slightly different version
% of quantities in equation 2.15.2 in the book
% "Flight Test Engineering" by Ward and Srtganac (page 13).
% This function works for all different types of aircraft
% as long as Vcalibrated <=ao.

% Convert from knots to ft/sec
Vcalfps=Vcalibrated*1.687808;
gamma=1.4;
p0=2116.22 ;      
rho0=0.00237691267925741;
const1=(gamma-1)*rho0/(2*gamma*p0);
const2=gamma/(gamma-1);
qcOverp0=(1+const1*Vcalfps.*Vcalfps).^const2-1;
f0=sqrt(3.5*(1./qcOverp0).*((qcOverp0+1).^(2/7)-1));
% f0 and f are Compressibility factors as defined by William Gracey
% in NASA Reference Publication 1046.
qcOverp=(qcOverp0*p0)./p;
f=sqrt(3.5*(1./qcOverp).*((qcOverp+1).^(2/7)-1));
Vefps=Vcalfps.*f./f0; % Units are ft/sec
% This equation is a slightly different version
% of quantities in equation 2.15.2 in the book
% "Flight Test Engineering" by Ward and Srtganac (page 13).
Vequivalent=Vefps/1.687808;  % Convert to knots
