コード例 #1
0
            public override MathNet.Numerics.Complex[] Reflection_Spectrum(int sample_frequency, int length, Hare.Geometry.Vector Normal, Hare.Geometry.Vector Dir, int threadid)
            {
                MathNet.Numerics.Complex[] Ref_trns = new MathNet.Numerics.Complex[length];

                for (int j = 0; j < length; j++)
                {
                    Ref_trns[j] = new MathNet.Numerics.Complex(Transfer_Function.Interpolate(j * (sample_frequency / 2) / length), 0);
                }

                return(Ref_trns);
            }
コード例 #2
0
            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));
            }
コード例 #3
0
            public override void AttenuationFilter(int no_of_elements, int sample_Frequency, double distance_meters, ref double[] Freq, ref double[] Atten, Hare.Geometry.Point pt)
            {
                double df = sample_Frequency / no_of_elements;

                Freq  = new double[no_of_elements];
                Atten = new double[no_of_elements];

                for (int i = 0; i < no_of_elements; i++)
                {
                    Freq[i]  = df * (i + 1);
                    Atten[i] = Math.Exp(-.1151 * Spectrum.Interpolate(Freq[i]) * distance_meters);
                }
            }
コード例 #4
0
            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);
            }