# ComputeNormalizedProfile

## PURPOSE

This function computes the normalized velocity profile from basic velocity

## SYNOPSIS

function [dm,zm,Vme,Vmn,Vmv,Vmag,nmedpts,maxd] = ComputeNormalizedProfile(d,binDepth,Ve,Vn,Vv)

## DESCRIPTION

    This function computes the normalized velocity profile from basic velocity
    components.  This method ensures that profiles with variable depths are
    averaged according to height above the bed rather than depth from surface.

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

- STA_MeanProfileV2 Compute the mean profile from stationary measurements at a point.

## SOURCE CODE

    0001 function [dm,zm,Vme,Vmn,Vmv,Vmag,nmedpts,maxd] = ComputeNormalizedProfile(d,binDepth,Ve,Vn,Vv)
    0002
    0003 %This function computes the normalized velocity profile from basic velocity
    0004 %components.  This method ensures that profiles with variable depths are
    0005 %averaged according to height above the bed rather than depth from surface.
    0006
    0007 % d: 1 x n vector of bed depths
    0008 % binDepth: m x n matrix of bin depths as defined by the ADCP
    0009 % Ve: m x n matrix of East Velocity obervations
    0010 % Vn: m x n matrix of North Velocity observations
    0011
    0012 %P.R. Jackson, USGS, 3-21-12
    0013
    0014 %Determine the bin size
    0015 binSpacing = diff(binDepth(:,1));
    0016 binSize = binSpacing(1);
    0017
    0018 %Use the max depth and binsize to set the number of points in the profile
    0019 %(this maintains the resolution of the original data)
    0020
    0021 maxd = nanmax(d);
    0022 npts = ceil(maxd/binSize);
    0023 zcellBounds = linspace(0,1,npts+1);  %Boundary points for each averaging cell
    0024 zcn = (zcellBounds(2:end)+zcellBounds(1:end-1))/2;  %midpoint of each averaging cell
    0025
    0026 % Compute the normalized sample height above the bed
    0027 % Normalize by depth
    0028
    0029 dmat = repmat(d,size(binDepth,1),1);
    0030 zn = (dmat-binDepth)./dmat;
    0031
    0032 % Aggregate the data and plot the normalized profiles
    0033 Ve_all = [];
    0034 Vn_all = [];
    0035 Vv_all = [];
    0036 zn_all = [];
    0037 for i = 1:length(d)
    0038     Ve_all = [Ve_all; Ve(:,i)];
    0039     Vn_all = [Vn_all; Vn(:,i)];
    0040     Vv_all = [Vv_all; Vv(:,i)];
    0041     zn_all = [zn_all; zn(:,i)];
    0042 end
    0043
    0044
    0045 % Compute the median profiles
    0046 Vme = nan*ones(npts,1);
    0047 Vmn = nan*ones(npts,1);
    0048 Vmv = nan*ones(npts,1);
    0049 nmedpts = nan*ones(npts,1);
    0050 for i = 1:npts
    0051     indx = find(zn_all >= zcellBounds(i) & zn_all < zcellBounds(i+1) & ~isnan(Ve_all) & ~isnan(Vn_all));
    0052     Vme(i) = nanmedian(Ve_all(indx));
    0053     Vmn(i) = nanmedian(Vn_all(indx));
    0054     Vmv(i) = nanmedian(Vv_all(indx));
    0055     nmedpts(i) = length(indx);
    0056 end
    0057
    0058 % Plot the median profiles
    0059
    0060 figure(11); clf
    0061 subplot(1,3,1)
    0062 plot(Ve_all,zn_all,'k.'); hold on
    0063 plot(Vme,zcn,'ro-')
    0064 ylim([0 1])
    0065 ylabel('Normalized Height above bed')
    0066 xlabel('East Velocity')
    0067 grid on
    0068 subplot(1,3,2)
    0069 plot(Vn_all,zn_all,'k.'); hold on
    0070 plot(Vmn,zcn,'ro-')
    0071 ylim([0 1])
    0072 %ylabel('Normalized Height above bed')
    0073 xlabel('North Velocity')
    0074 grid on
    0075 subplot(1,3,3)
    0076 plot(Vv_all,zn_all,'k.'); hold on
    0077 plot(Vmv,zcn,'ro-')
    0078 ylim([0 1])
    0079 %ylabel('Normalized Height above bed')
    0080 xlabel('Vertical Velocity')
    0081 grid on
    0082
    0083 %Compute the Velocity Magnitude
    0084 Vmag = sqrt(Vme.^2 + Vmn.^2);
    0085
    0086 %Convert back to height above bottom and depth
    0087 zm = zcn*maxd;  %unnormalized height above bed
    0088 dm = maxd - zm;  %Depth from surface
    0089
    0090 % Remove points with few contributing observations
    0091 if 1
    0092     scrnpct = 0.2;  %screening percent
    0093     medobs = nanmedian(nmedpts);  %median number of observations
    0094     indx = find(nmedpts < scrnpct*medobs);  %finds points in the profile with fewer than 20% of the median number of observations contributing to the median
    0095     Vme(indx) = nan;
    0096     Vmn(indx) = nan;
    0097     Vmv(indx) = nan;
    0098     Vmag(indx) = nan;
    0099 end
    0100
    0101
    0102
    0103
    0104
    0105
    0106
    0107