You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// <summary>/// Return a filtered version of the input array (with the same number of points)/// </summary>publicdouble[]GaussianFilter1d(double[]data,intdegree=5){if(degree<2)returndata;double[]smooth=newdouble[data.Length];// create a gaussian windowing functionintwindowSize=degree*2-1;double[]kernel=newdouble[windowSize];for(inti=0;i<windowSize;i++){intpos=i-degree+1;doublefrac=i/(double)windowSize;doublegauss=1.0/Math.Exp(Math.Pow(4*frac,2));// TODO: why 4?kernel[i]=gauss*windowSize;}// normalize the kernel (so area is 1)doubleweightSum=kernel.Sum();for(inti=0;i<windowSize;i++)kernel[i]=kernel[i]/weightSum;// apply the windowfor(inti=0;i<smooth.Length;i++){if(i>kernel.Length&&i<smooth.Length-kernel.Length){doublesmoothedValue=0;for(intj=0;j<kernel.Length;j++){smoothedValue+=kernel[j]*data[i+j];}smooth[i]=smoothedValue;}else{smooth[i]=data[i];}}// blank-out values outside the smoothing rangeintfirstValidPoint=kernel.Length;intlastValidPoint=smooth.Length-kernel.Length;for(inti=0;i<firstValidPoint;i++)smooth[i]=smooth[firstValidPoint];for(inti=lastValidPoint;i<smooth.Length;i++)smooth[i]=smooth[lastValidPoint];returnsmooth;}