1using Microsoft.MixedReality.Toolkit.UI;
3using System.Collections.Generic;
13 #region Private Variables
50 base.PopulateVariablesWithDataFromUI();
61 base.GenerateNewDistribution();
72 bool noiseAppliedState = ( m_NoiseValueList.Count >= (
m_SampleSize2X - 2 ) ) ? true :
false;
99 List<double> gammak =
new List<double>();
108 double first = Math.Pow( ( Mathf.Abs( i - 1 ) ), ( 2 *
m_AlphaValue ) );
110 double second = 2 * ( Math.Pow( i, ( 2 *
m_AlphaValue ) ) );
112 double third = Math.Pow( ( i + 1 ), ( 2 *
m_AlphaValue ) );
114 double result = ( first - second + third ) / 2.0;
115 gammak.Add( result * basePinkNoiseArrLen );
120 gammak.Add( gammak[i] );
123 Complex[] GammakComplex =
new Complex[gammak.Count];
125 for(
int i = 0; i < gammak.Count; i++ )
127 Complex gamComp =
new Complex( ( gammak[i] / gammak.Count ), 0.0 );
128 GammakComplex[i] = gamComp;
147 List<float> basePinkNoise =
new List<float>();
148 List<float> leftHalf =
new List<float>();
149 List<float> rightHalf =
new List<float>();
151 Complex[] basePinkNoiseComplexArr =
new Complex[
m_SampleSize2X - 2];
162 leftHalf.Add( basePinkNoise[i] );
166 rightHalf.Add( basePinkNoise[i] );
170 basePinkNoise.Clear();
180 leftHalf.Add(leftHalf[i]);
181 rightHalf.Add(-rightHalf[i]);
184 for(
int i = 0; i < rightHalf.Count; i++ )
186 Complex myComplex =
new Complex( leftHalf[i], rightHalf[i] );
187 basePinkNoiseComplexArr[i] = myComplex;
193 bool noZeroFlag =
true;
197 for(
int i = 0; i <
m_GKSqrt.Count; i++ )
199 if( Mathf.Approximately( (
float)
m_GKSqrt[i], 0.0f ) )
206 if( noZeroFlag ==
true )
208 int basePinkNoiseComplexArrLen = basePinkNoiseComplexArr.Length;
210 for(
int i = 0; i < basePinkNoiseComplexArrLen; i++ )
213 basePinkNoiseComplexArr[i] = Complex.Multiply( basePinkNoiseComplexArr[i],
m_GKSqrt[i] );
216 IDFT( ref basePinkNoiseComplexArr );
218 for(
int i = 0; i < basePinkNoiseComplexArrLen; i++ )
220 double power = Math.Pow( (
m_SampleSize - 1 ), ( -0.5 ) );
221 Complex intermediateResult = Complex.Multiply( power, basePinkNoiseComplexArr[i] );
222 Complex result = Complex.Multiply( intermediateResult, 0.5 );
226 m_Title.text =
"Distribution is Ready";
230 m_Title.text =
"Distribution is NOT Ready";
239 private void IDFT( ref Complex[] X )
243 Complex[] x =
new Complex[N];
245 for(
int n = 0; n < N; n++ )
249 for(
int k = 0; k < N; k++ )
251 sum += X[k] * Complex.Exp( Complex.ImaginaryOne * 2 * Math.PI * (k * n) / Convert.ToDouble(N) );
258 Array.Clear( X, 0, N );
260 for(
int i = 0; i < N; i++ )
275 for(
int n = 0; n < N; n++ )
279 for(
int k = 0; k < N; k++ )
281 sum += X[k] * Complex.Exp( Complex.ImaginaryOne * 2 * Math.PI * (k * n) / Convert.ToDouble(N) );
const float m_NoiseSTD
Hold the standard distribution.
float m_MeanPeriod
Hold the Mean Period Value.
void ConvertToZScore(ref List< float > basePinkNoiseList)
This converts Z values to Z Score values. May get off a small amount due to round error.
List< float > m_StandardNoiseDistribution
A List to hold Normal(Gaussian) distribution.
int m_SampleSize
Defines how many samples we want.
float m_SDPeriod
Hold the standard distribution period.
List< float > m_NoiseValueList
This list stores the calculated colored noise values.
float m_Multiplier
Used this as a multiplier to calculate pink noise.
const float m_Mean
Hold the Mean value.
void SetReadyMessage(bool flag, string lbl)
Indicate noise is successgully applied or not.
GaussianDistribution m_GaussianDistribution
Reference to GaussianDistribution script.
GameObject m_DistributionButton
double RandomGauss(double mu=0, double sigma=1)
Obtains normally (Gaussian) distrubuted random numbers, using the Box-Muller transformation....
override void ApplyPattern()
Calculate the noise according to the user input. Mapped to NoiseDataPanel ApplyPattern button.
void IDFTReal(ref Complex[] X)
Calculates inverse Discrete Fourier Transform of given spectrum X
override void GenerateNewDistribution()
Generate a new normal(Gaussian) distribution Mapped to NoiseDataPanel NewDistribution button.
void CalculateGKSQRT()
This value is used to calculate base pink noise TODO -> We can parellize this in future.
float m_AlphaValue
For pink noise 0.99 For white noise 0.5 In future, we might need to add different values.
override void CalculateNoise()
Scale the base pink noise.
override void CalculateBaseNoise()
Calculate the base pink noise value.
List< double > m_GKSqrt
A list to hold GKSqrt values. This is just an intermidiate value use to calculate base Pink noise.
int m_SampleSize2X
2 * sample size. We calculate 2X with X sample size.
void IDFT(ref Complex[] X)
Calculates inverse Discrete Fourier Transform of given spectrum X
float m_SqrtOfTwo
Used this to calculate pink noise.
override void PopulateVariablesWithDataFromUI()
Populate data variables used to alter noise. The data are gained through UI lables which are set by t...