pattern.c
float32_t fTriangWeight( float32_t* ufFourierFrequency, float32_t fTriangCent, float32_t fTriangWidth )
{
  /** The weighting triangle must always return an area of 1 
    * before being multiplied by the frequency magnitudes.
    *
    * Area of Triangle:
    *  1 = h*b/2     (b = TriangWidth*2)
    */

    float32_t fH = 1.0F/fTriangWidth;

  /**  Now linearly interpolate and apply the scalings to the FFT.
    */

  /** Increasing triangle slope. fH will be the y-intercept because the
    * traingle will be centered on the y-axis.
    */

    float32_t fSlope = fH / fTriangWidth;

    float32_t fSummation = 0.0F;
    uint32_t uInterpStart = (uint32_t)(SAT_ZERO_MACRO((fTriangCent- fTriangWidth)) / HERTZ_PER_INDEX);
    float32_t fInterpStop = fTriangCent / HERTZ_PER_INDEX;

    uint32_t uIdx= 0U;
    for (uint32_t uI = uInterpStart; uI <= fInterpStop; uI++, uIdx++)
    {
        /** Look up the value to weight the frequency by and then sum it. */
        fSummation += ufFourierFrequency[uI] * (uIdx * fSlope + fH);
    }

  /** Decreasing triangle slope. fH will be the y-intercept because the
    * traingle will be centered on the y-axis.
    */
    
    /** This time the slope is negative. */
    fSlope *= -1;
    
    /** This interp starts at the center. */
    uInterpStart = (uint32_t)(fTriangCent / HERTZ_PER_INDEX);
    fInterpStop = SAT_RFFT_LEN_MACRO((fTriangCent + fTriangWidth) / HERTZ_PER_INDEX);

    uIdx= 0U;
    for (uint32_t uI = uInterpStart; uI <= fInterpStop; uI++, uIdx++)
    {
        /** Look up the value to weight the frequency by and then sum it. */
        fSummation += ufFourierFrequency[uI] * (uIdx * fSlope + fH);
    }

    return fSummation;
}
/**
  * @brief  Calculates area under the curve.  Uses a triangle for weighting curve.
  * @note   Areas calculated using this function can be compared to each other 
                because the height of the weighting triangle is dynamically 
                adjusted to accomodate varying bandwidths.
  * @param  ufFourierFrequency :: Array of magnitudes from the FFT.
  * @param  TriangCent :: Center of weighting triangle (hertz).
  * @param  TriangWidth :: Width of the weighting triangle (base/2, hertz).
  * @retval Normalized area of under the curve.
  */
@brief  Calculates area under the curve.  Uses a triangle for weighting curve.
@note   Areas calculated using this function can be compared to each other
because the height of the weighting triangle is dynamically
adjusted to accomodate varying bandwidths.
@param  ufFourierFrequency :: Array of magnitudes from the FFT.
@param  TriangCent :: Center of weighting triangle (hertz).
@param  TriangWidth :: Width of the weighting triangle (base/2, hertz).
@retval Normalized area of under the curve.
@brief Calculates area under the curve . Uses a triangle for weighting curve . @note Areas calculated using this function can be compared to each other because the height of the weighting triangle is dynamically adjusted to accomodate varying bandwidths . @param ufFourierFrequency :: Array of magnitudes from the FFT . @param TriangCent :: Center of weighting triangle ( hertz ) . @param TriangWidth :: Width of the weighting triangle ( base / 2 hertz ) . @retval Normalized area of under the curve .
float32_t fTriangWeight( float32_t* ufFourierFrequency, float32_t fTriangCent, float32_t fTriangWidth )
{
    float32_t fH = 1.0F/fTriangWidth;
    float32_t fSlope = fH / fTriangWidth;
    float32_t fSummation = 0.0F;
    uint32_t uInterpStart = (uint32_t)(SAT_ZERO_MACRO((fTriangCent- fTriangWidth)) / HERTZ_PER_INDEX);
    float32_t fInterpStop = fTriangCent / HERTZ_PER_INDEX;
    uint32_t uIdx= 0U;
    for (uint32_t uI = uInterpStart; uI <= fInterpStop; uI++, uIdx++)
    {
        fSummation += ufFourierFrequency[uI] * (uIdx * fSlope + fH);
    }
    fSlope *= -1;
    uInterpStart = (uint32_t)(fTriangCent / HERTZ_PER_INDEX);
    fInterpStop = SAT_RFFT_LEN_MACRO((fTriangCent + fTriangWidth) / HERTZ_PER_INDEX);
    uIdx= 0U;
    for (uint32_t uI = uInterpStart; uI <= fInterpStop; uI++, uIdx++)
    {
        fSummation += ufFourierFrequency[uI] * (uIdx * fSlope + fH);
    }
    return fSummation;
}
float32_t fTriangWeight ( float32_t * ufFourierFrequency , float32_t fTriangCent , float32_t fTriangWidth ) { float32_t fH = 1.0F / fTriangWidth ; float32_t fSlope = fH / fTriangWidth ; float32_t fSummation = 0.0F ; uint32_t uInterpStart = ( uint32_t ) ( SAT_ZERO_MACRO ( ( fTriangCent - fTriangWidth ) ) / HERTZ_PER_INDEX ) ; float32_t fInterpStop = fTriangCent / HERTZ_PER_INDEX ; uint32_t uIdx = 0U ; for ( uint32_t uI = uInterpStart ; uI <= fInterpStop ; uI ++ , uIdx ++ ) { fSummation += ufFourierFrequency [ uI ] * ( uIdx * fSlope + fH ) ; } fSlope *= -1 ; uInterpStart = ( uint32_t ) ( fTriangCent / HERTZ_PER_INDEX ) ; fInterpStop = SAT_RFFT_LEN_MACRO ( ( fTriangCent + fTriangWidth ) / HERTZ_PER_INDEX ) ; uIdx = 0U ; for ( uint32_t uI = uInterpStart ; uI <= fInterpStop ; uI ++ , uIdx ++ ) { fSummation += ufFourierFrequency [ uI ] * ( uIdx * fSlope + fH ) ; } return fSummation ; }
@brief  Calculates area under the curve.
@brief Calculates area under the curve .
/** The weighting triangle must always return an area of 1 
    * before being multiplied by the frequency magnitudes.
    *
    * Area of Triangle:
    *  1 = h*b/2     (b = TriangWidth*2)
    */ /**  Now linearly interpolate and apply the scalings to the FFT.
    */ /** Increasing triangle slope. fH will be the y-intercept because the
    * traingle will be centered on the y-axis.
    */ /** Look up the value to weight the frequency by and then sum it. */ /** Decreasing triangle slope. fH will be the y-intercept because the
    * traingle will be centered on the y-axis.
    */ /** This time the slope is negative. */ /** This interp starts at the center. */ /** Look up the value to weight the frequency by and then sum it. */