public Basic_Material(double[] ABS, double[] Phase_Delay) { Abs = ABS; PD = Phase_Delay; for (int i = 0; i < ABS.Length; i++) { Ref[i] = 1 - ABS[i]; } //Interpolate a transfer function... this will probably be clumsy at first... double rt2 = Math.Sqrt(2); List <double> f = new List <double>(); f.Add(0); f.Add(31.25 * rt2); for (int oct = 0; oct < 9; oct++) { f.Add(62.5 * Math.Pow(2, oct)); f.Add(rt2 * 62.5 * Math.Pow(2, oct)); } f.Add(24000); List <double> pr = new List <double>(); pr.Add(0); pr.Add(Math.Sqrt(1 - Abs[0])); for (int oct = 0; oct < 7; oct++) { pr.Add(Math.Sqrt(1 - Abs[oct])); pr.Add(Math.Sqrt((2 - Abs[oct] - Abs[oct + 1]) / 2)); } if (pr.Count < f.Count) { pr.Add(Math.Sqrt(1 - Abs[7])); //8k } if (pr.Count < f.Count) { pr.Add(Math.Sqrt((1 - Abs[7] + (1 - Abs[7])) / 2)); //10k } if (pr.Count < f.Count) { pr.Add(Math.Sqrt(1 - Abs[7])); //12k } if (pr.Count < f.Count) { pr.Add(Math.Sqrt(1 - Abs[7])); //16k } while (pr.Count < f.Count) { pr.Add(1 - Abs[7]); } Transfer_Function = MathNet.Numerics.Interpolation.Interpolation.CreateAkimaCubicSpline(f.ToArray(), pr.ToArray()); }
public void ISO9613_1_Spline(double Tk, double Pa, double Hr) { double[] freq = new double[1024]; double df = 22050 / 1024; for (int i = 1; i < 1025; i++) { freq[i - 1] = df * i; } Spectrum = MathNet.Numerics.Interpolation.Interpolation.CreateAkimaCubicSpline(freq, ISO9613_1_attencoef(freq, Tk, Pa, Hr)); }
public static double[] Pressure_Interpolation(double[][] ETC, int SampleRate_IN, int SampleRate_Out, double Rho_C) { double[][] SPLetc = new double[8][]; double[] Total_E = new double[8]; double[] time = new double[ETC[0].Length]; double dtIn = 1.0f / SampleRate_IN; double dtOut = 1.0f / SampleRate_Out; for (int i = 1; i < time.Length; i++) { time[i] = (double)i / SampleRate_IN; } for (int oct = 0; oct < 8; oct++) { SPLetc[oct] = new double[ETC[0].Length]; for (int i = 0; i < time.Length; i++) { Total_E[oct] += ETC[oct][i]; if (ETC[oct][i] > 0) { SPLetc[oct][i] = Math.Log10(ETC[oct][i]); } else { SPLetc[oct][i] = Math.Log10(1E-12); } } } int NewLength = (int)Math.Ceiling((double)(SampleRate_Out * ETC[0].Length) / SampleRate_IN); double[][] NewETC = new double[8][]; double[] NewTE = new double[8]; for (int oct = 0; oct < 8; oct++) { MathNet.Numerics.Interpolation.IInterpolationMethod CS = MathNet.Numerics.Interpolation.Interpolation.CreateAkimaCubicSpline(time, SPLetc[oct]); NewETC[oct] = new double[NewLength]; for (int i = 0; i < NewLength; i++) { NewETC[oct][i] = Math.Pow(10, CS.Interpolate(i * dtOut)); NewTE[oct] += NewETC[oct][i]; } for (int i = 0; i < NewLength; i++) { NewETC[oct][i] *= Total_E[oct] / NewTE[oct]; } } return(ETCToPTC(NewETC, (double)NewLength / SampleRate_Out, SampleRate_Out, SampleRate_Out, Rho_C)); }
public static void Initialize_filter_functions() { int n = 100; double[] A = new double[n]; double[] ph = new double[n]; for (int i = 0; i < 100; i++) { ph[i] = Math.PI / 2 * i; A[i] = 0.25 * (ph[i] - Math.Cos(ph[i])) / (Math.PI * 2); } RCos_Integral = MathNet.Numerics.Interpolation.Interpolation.CreateAkimaCubicSpline(A, ph); }
public static double[] Magnitude_Filter(double[] Octave_pressure, int sample_frequency, int length_starttofinish, int threadid) { double rt2 = Math.Sqrt(2); int spec_length = length_starttofinish / 2; List <double> f = new List <double>(); f.Add(0); f.Add(31.25 * rt2); for (int oct = 0; oct < 9; oct++) { f.Add(62.5 * Math.Pow(2, oct)); f.Add(rt2 * 62.5 * Math.Pow(2, oct)); } f.Add(sample_frequency / 2); double[] output = new double[spec_length]; double[] samplep = new double[spec_length]; List <double> pr = new List <double>(); pr.Add(Octave_pressure[0]); pr.Add(Octave_pressure[0]); for (int oct = 0; oct < 7; oct++) { pr.Add(Octave_pressure[oct]); pr.Add((Octave_pressure[oct] + Octave_pressure[oct + 1]) / 2); } if (pr.Count < f.Count) { pr.Add(Octave_pressure[7]); //8k } if (pr.Count < f.Count) { pr.Add(Octave_pressure[7]); //10k } if (pr.Count < f.Count) { pr.Add(Octave_pressure[7]); //12k } if (pr.Count < f.Count) { pr.Add(Octave_pressure[7]); //16k } while (pr.Count < f.Count) { pr.Add(Octave_pressure[7]); } MathNet.Numerics.Interpolation.IInterpolationMethod prm = MathNet.Numerics.Interpolation.Interpolation.CreateAkimaCubicSpline(f.ToArray(), pr.ToArray()); double[] p_i = new double[spec_length]; for (int j = 0; j < spec_length; j++) { double fr = (j + 1) * (sample_frequency / 2) / spec_length; p_i[j] = prm.Interpolate(fr);// / (fr); } return(p_i); }