import type { NumericArray } from "@thi.ng/api" ; import { isNumber } from "@thi.ng/checks/is-number" ; import type { ComplexArray } from "./api.js" ; import { isComplex } from "./complex.js" ; param window export const integralT = ( window ) => { let sum = 0 ; for ( let i = window . length ; i -- > 0 ; ) { sum += window [ i ] ; } return sum ; } ; param window export const integralTSquared = ( window ) => { let sum = 0 ; for ( let i = window . length ; i -- > 0 ; ) { sum += window [ i ] ** 2 ; } return sum ; } ; param window export const integralF = ( [ real , img ] ) => { let sum = 0 ; for ( let i = real . length ; i -- > 0 ; ) { sum += Math . hypot ( real [ i ] , img [ i ] ) ; } return sum ; } ; param window export const integralFSquared = ( [ real , img ] ) => { let sum = 0 ; for ( let i = real . length ; i -- > 0 ; ) { sum += real [ i ] ** 2 + img [ i ] ** 2 ; } return sum ; } ; param scale param base export const powerScale = ( scale , base = 1 ) => isNumber ( scale ) ? scale : base / integralT ( scale ) ; param scale param base export const invPowerScale = ( scale , base = 1 ) => isNumber ( scale ) ? scale : integralT ( scale ) / base ; remarks param window export const powerSumSquared = ( window ) => isComplex ( window ) ? integralFSquared ( window ) / window [ 0 ] . length : integralTSquared ( window ) ; remarks param window export const powerMeanSquared = ( window ) => powerSumSquared ( window ) / ( isComplex ( window ) ? window [ 0 ] . length : window . length ) ; remarks param window export const powerTimeIntegral = ( window , fs ) => ( isComplex ( window ) ? integralFSquared ( window ) : integralTSquared ( window ) ) / fs ;