Esempio n. 1
0
            private void CalculateSim_Click(object sender, EventArgs e)
            {
                FC = new ForCall(Forw_proc);

                Polygon_Scene Rm = PachTools.Get_Poly_Scene((double)Rel_Humidity.Value, (double)Air_Temp.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked);

                if (!Rm.Complete)
                {
                    return;
                }

                Rhino.Geometry.Point3d[] Src = PachTools.GetSource();
                Rhino.Geometry.Point3d[] Rec = PachTools.GetReceivers().ToArray();
                if (Src.Length < 1 || Rm == null)
                {
                    Rhino.RhinoApp.WriteLine("Model geometry not specified... Exiting calculation...");
                }

                Numeric.TimeDomain.Microphone_Compact Mic = new Numeric.TimeDomain.Microphone_Compact(Rec);
                double fs = 137.8125 * Math.Pow(2, Selected_Extent.SelectedIndex);

                samplefrequency = fs;
                double df = 1d / ((double)CO_TIME.Value / 1000);

                Numeric.TimeDomain.Signal_Driver_Compact SD = new Numeric.TimeDomain.Signal_Driver_Compact(Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse, df, 1, PachTools.GetSource());
                FDTD = new Numeric.TimeDomain.Acoustic_Compact_FDTD(Rm, ref SD, ref Mic, fs, (double)CO_TIME.Value);

                for (double f = df; f < fs; f += df)
                {
                    FDTD.reset(f, Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse);
                    FDTD.RuntoCompletion();

                    Frequencies.Items.Add(string.Format("{0} Hz.", f), true);
                }

                Receiver_Choice.Text = "0";

                result_signals = Mic.Recordings;
            }
            private void CalculateScattering_Click(object sender, EventArgs e)
            {
                Chosenfreq = 0;
                double radius = (double)ScatteringRadius.Value;
                double t      = 3 * (radius + (double)Sample_Depth.Value) / C_Sound() * 1000;

                if (LabCenter == null)
                {
                    return;
                }

                if (Analysis_Technique.SelectedIndex == 0)
                {
                    Polygon_Scene Rm      = RC_PachTools.Get_Poly_Scene((double)Rel_Humidity.Value, false, (double)Air_Temp.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked);
                    Empty_Scene   Rm_Ctrl = new Empty_Scene((double)Air_Temp.Value, (double)Rel_Humidity.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked, true, Rm.Min(), Rm.Max());
                    Rm_Ctrl.PointsInScene(new List <Hare.Geometry.Point> {
                        Rm.Min(), Rm.Max()
                    });
                    Rm_Ctrl.partition();

                    if (!Rm.Complete && Rm_Ctrl.Complete)
                    {
                        return;
                    }

                    Hare.Geometry.Point ArrayCenter = new Hare.Geometry.Point(LabCenter.X, LabCenter.Y, LabCenter.Z + (double)Sample_Depth.Value);

                    Hare.Geometry.Point[] Src = new Hare.Geometry.Point[1] {
                        new Hare.Geometry.Point(LabCenter.X, LabCenter.Y, LabCenter.Z + radius + (double)Sample_Depth.Value)
                    };
                    List <Hare.Geometry.Point> Rec = new List <Hare.Geometry.Point>();

                    for (int phi = 0; phi < 18; phi++)
                    {
                        for (int theta = 0; theta < 36; theta++)
                        {
                            double anglePhi   = phi * Math.PI / 18;
                            double angleTheta = theta * Utilities.Numerics.PiX2 / 36;
                            Rec.Add(ArrayCenter + radius * new Hare.Geometry.Point(Math.Cos(angleTheta) * Math.Cos(anglePhi), Math.Sin(angleTheta) * Math.Cos(anglePhi), Math.Sin(anglePhi)));
                        }
                    }

                    //for (int phi = 0; phi < 18; phi++)
                    //    {
                    //        double anglePhi = phi * Math.PI / 18;
                    //        Rec.Add(ArrayCenter + radius * new Rhino.Geometry.Point3d(Math.Cos(anglePhi), 0, Math.Sin(anglePhi)));
                    //    }

                    double fs = 62.5 * Utilities.Numerics.rt2 * Math.Pow(2, comboBox2.SelectedIndex);

                    t += 60 / fs;

                    Numeric.TimeDomain.Microphone_Compact    Mic   = new Numeric.TimeDomain.Microphone_Compact(Rec.ToArray());
                    Numeric.TimeDomain.Signal_Driver_Compact SD    = new Numeric.TimeDomain.Signal_Driver_Compact(Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse, fs, 1, Src);
                    Numeric.TimeDomain.Acoustic_Compact_FDTD FDTDS = new Numeric.TimeDomain.Acoustic_Compact_FDTD(Rm, ref SD, ref Mic, fs, t, Numeric.TimeDomain.Acoustic_Compact_FDTD.GridType.ScatteringLab, Utilities.RC_PachTools.RPttoHPt(LabCenter), radius * 2, radius * 2, radius * 1.2 + (double)Sample_Depth.Value);
                    FDTDS.RuntoCompletion();

                    Numeric.TimeDomain.Microphone_Compact    Micf  = new Numeric.TimeDomain.Microphone_Compact(Rec.ToArray());
                    Numeric.TimeDomain.Signal_Driver_Compact SDf   = new Numeric.TimeDomain.Signal_Driver_Compact(Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse, fs, 1, Src);
                    Numeric.TimeDomain.Acoustic_Compact_FDTD FDTDF = new Numeric.TimeDomain.Acoustic_Compact_FDTD(Rm_Ctrl, ref SDf, ref Micf, fs, t, Numeric.TimeDomain.Acoustic_Compact_FDTD.GridType.ScatteringLab, Utilities.RC_PachTools.RPttoHPt(LabCenter), radius * 2, radius * 2, radius * 1.2 + (double)Sample_Depth.Value);
                    FDTDF.RuntoCompletion();

                    samplefrequency = FDTDS.SampleFrequency;

                    Mic.reset();
                    result_signals = Mic.Recordings[0];
                    Micf.reset();
                    result_signals = Micf.Recordings[0];

                    //Calculate Scattering Coefficients
                    double[][] TimeS = Mic.Recordings[0];
                    double[][] TimeF = Micf.Recordings[0];

                    //Zero packing
                    for (int i = 0; i < TimeS.Length; i++)
                    {
                        Array.Resize(ref TimeS[i], (int)(samplefrequency / 2));
                        Array.Resize(ref TimeF[i], (int)(samplefrequency / 2));
                    }
                    System.Numerics.Complex[][] FS = new System.Numerics.Complex[TimeS.Length][];
                    System.Numerics.Complex[][] FF = new System.Numerics.Complex[TimeS.Length][];

                    for (int i = 0; i < TimeS.Length; i++)
                    {
                        FS[i] = Audio.Pach_SP.FFT_General(TimeS[i], 0);
                        FF[i] = Audio.Pach_SP.FFT_General(TimeF[i], 0);
                    }

                    Scattering = new double[FS[0].Length];

                    for (int i = 0; i < FS[0].Length; i++)
                    {
                        System.Numerics.Complex sumFS2  = 0;
                        System.Numerics.Complex sumFF2  = 0;
                        System.Numerics.Complex sumFSFF = 0;

                        for (int j = 0; j < FS.Length; j++)
                        {
                            sumFS2  += System.Numerics.Complex.Pow(FS[j][i].Magnitude, 2);
                            sumFF2  += System.Numerics.Complex.Pow(FF[j][i].Magnitude, 2);
                            sumFSFF += FS[j][i] * System.Numerics.Complex.Conjugate(FF[j][i]);
                            //sumFS2 += System.Numerics.Complex.Pow(FS[j][i], 2);
                            //sumFF2 += System.Numerics.Complex.Pow(FF[j][i], 2);
                            //sumFSFF += FS[j][i] * System.Numerics.Complex.Conjugate(FF[j][i]);
                        }

                        System.Numerics.Complex sumReflected = sumFSFF / sumFF2;
                        System.Numerics.Complex Ratio        = sumFF2 / sumFS2;
                        Scattering[i] = 1 - System.Numerics.Complex.Abs(sumReflected * sumReflected * Ratio);
                    }
                }
                else if (Analysis_Technique.SelectedIndex == 1)
                {
                    Polygon_Scene Rm      = RC_PachTools.Get_Poly_Scene((double)Rel_Humidity.Value, false, (double)Air_Temp.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked);
                    Empty_Scene   Rm_Ctrl = new Empty_Scene((double)Air_Temp.Value, (double)Rel_Humidity.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked, true, Rm.Min(), Rm.Max());
                    Rm_Ctrl.PointsInScene(new List <Hare.Geometry.Point> {
                        Rm.Min(), Rm.Max()
                    });
                    Rm_Ctrl.partition();

                    if (!Rm.Complete && Rm_Ctrl.Complete)
                    {
                        return;
                    }

                    //if (!Rm.Complete) return;

                    Hare.Geometry.Point ArrayCenter = new Hare.Geometry.Point(LabCenter.X, LabCenter.Y, LabCenter.Z + (double)Sample_Depth.Value);

                    Hare.Geometry.Point[] Src = new Hare.Geometry.Point[1] {
                        new Hare.Geometry.Point(LabCenter.X, LabCenter.Y, LabCenter.Z + radius + (double)Sample_Depth.Value)
                    };
                    List <Hare.Geometry.Point> Rec = new List <Hare.Geometry.Point>();

                    for (int phi = 0; phi < 18; phi++)
                    {
                        for (int theta = 0; theta < 36; theta++)
                        {
                            double anglePhi   = phi * Math.PI / 18;
                            double angleTheta = theta * Utilities.Numerics.PiX2 / 36;
                            Rec.Add(ArrayCenter + radius * new Hare.Geometry.Point(Math.Cos(angleTheta) * Math.Cos(anglePhi), Math.Sin(angleTheta) * Math.Cos(anglePhi), Math.Sin(anglePhi)));
                        }
                    }

                    //for (int phi = 0; phi < 18; phi++)
                    //    {
                    //        double anglePhi = phi * Math.PI / 18;
                    //        Rec.Add(ArrayCenter + radius * new Rhino.Geometry.Point3d(Math.Cos(anglePhi), 0, Math.Sin(anglePhi)));
                    //    }

                    double fs = 62.5 * Utilities.Numerics.rt2 * Math.Pow(2, Analysis_Technique.SelectedIndex);

                    Numeric.TimeDomain.Microphone_Compact    Mic   = new Numeric.TimeDomain.Microphone_Compact(Rec.ToArray());
                    Numeric.TimeDomain.Signal_Driver_Compact SD    = new Numeric.TimeDomain.Signal_Driver_Compact(Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse, fs, 1, Src);
                    Numeric.TimeDomain.Acoustic_Compact_FDTD FDTDS = new Numeric.TimeDomain.Acoustic_Compact_FDTD(Rm, ref SD, ref Mic, fs, t, Numeric.TimeDomain.Acoustic_Compact_FDTD.GridType.TransparencyLab, Utilities.RC_PachTools.RPttoHPt(LabCenter), radius * 4, radius * 4, radius * 1.2 + (double)Sample_Depth.Value);
                    FDTDS.RuntoCompletion();

                    Numeric.TimeDomain.Microphone_Compact    Micf  = new Numeric.TimeDomain.Microphone_Compact(Rec.ToArray());
                    Numeric.TimeDomain.Signal_Driver_Compact SDf   = new Numeric.TimeDomain.Signal_Driver_Compact(Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse, fs, 1, Src);
                    Numeric.TimeDomain.Acoustic_Compact_FDTD FDTDF = new Numeric.TimeDomain.Acoustic_Compact_FDTD(Rm_Ctrl, ref SDf, ref Micf, fs, t, Numeric.TimeDomain.Acoustic_Compact_FDTD.GridType.ScatteringLab, Utilities.RC_PachTools.RPttoHPt(LabCenter), radius * 4, radius * 4, radius * 1.2 + (double)Sample_Depth.Value);
                    FDTDF.RuntoCompletion();

                    int start = (int)Math.Round((2.25 * radius / Rm.Sound_speed(Src[0])) / FDTDS.dt);

                    samplefrequency = FDTDS.SampleFrequency;

                    Mic.reset();
                    result_signals = Mic.Recordings[0];

                    //Calculate Scattering Coefficients
                    double[][] TimeS = Mic.Recordings[0];
                    double[][] TimeF = Micf.Recordings[0];

                    System.Numerics.Complex[][] FS = new System.Numerics.Complex[TimeS.Length][];
                    System.Numerics.Complex[][] FF = new System.Numerics.Complex[TimeS.Length][];

                    for (int i = 0; i < TimeS.Length; i++)
                    {
                        double[] ts = new double[TimeS[i].Length - start];
                        double[] tf = new double[TimeS[i].Length - start];
                        for (int ti = start; ti < TimeS[i].Length; ti++)
                        {
                            ts[ti - start] = TimeS[i][ti];
                            tf[ti - start] = TimeF[i][ti];
                        }
                        FS[i] = Audio.Pach_SP.FFT_General(ts, 0);
                        FF[i] = Audio.Pach_SP.FFT_General(TimeF[i], 0);
                    }

                    Scattering = new double[FS[0].Length];

                    for (int i = 0; i < FS[0].Length; i++)
                    {
                        System.Numerics.Complex sumFF2 = 0;

                        for (int j = 0; j < FS.Length; j++)
                        {
                            sumFF2 += System.Numerics.Complex.Pow(FS[j][i], 2) / System.Numerics.Complex.Pow(FF[j][i], 2);
                        }

                        Scattering[i] = Utilities.AcousticalMath.SPL_Pressure(System.Numerics.Complex.Abs(sumFF2));
                    }
                }
                Update_Scattering_Graph(null, null);
            }
Esempio n. 3
0
            private void CalculateSim_Click(object sender, EventArgs e)
            {
                EigenFrequencies.Items.Clear();
                Chosenfreq = 0;
                FC         = new ForCall(Forw_proc);

                Polygon_Scene Rm = PachTools.Get_Poly_Scene((double)Rel_Humidity.Value, (double)Air_Temp.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked);

                if (!Rm.Complete)
                {
                    return;
                }

                Rhino.Geometry.Point3d[] Src = PachTools.GetSource();
                Rhino.Geometry.Point3d[] Rec = PachTools.GetReceivers().ToArray();
                if (Src.Length < 1 || Rm == null)
                {
                    Rhino.RhinoApp.WriteLine("Model geometry not specified... Exiting calculation...");
                }

                Numeric.TimeDomain.Microphone_Compact Mic = new Numeric.TimeDomain.Microphone_Compact(Rec);
                double fs = 62.5 * Utilities.Numerics.rt2 * Math.Pow(2, Selected_Extent.SelectedIndex);

                //samplefrequency = fs;
                Numeric.TimeDomain.Signal_Driver_Compact SD = new Numeric.TimeDomain.Signal_Driver_Compact(Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse, 1000, 1, PachTools.GetSource());
                FDTD = new Numeric.TimeDomain.Acoustic_Compact_FDTD(Rm, ref SD, ref Mic, fs, (double)CO_TIME.Value);
                FDTD.RuntoCompletion();

                samplefrequency = FDTD.SampleFrequency;

                Mic.reset();
                result_signals = Mic.Recordings[0];
                //System.Numerics.Complex[] source_response = SD.Frequency_Response(result_signals[0].Length);

                //double f_limit = 0.8 * fs / samplefrequency * result_signals[0].Length;
                //double f_top = 1.3 * f_limit;
                //double dpi = Utilities.Numerics.PiX2 / (f_top - f_limit);

                //for (int c = 0; c < result_signals.Length; c++)
                //{
                //    System.Numerics.Complex[] result_response = Audio.Pach_SP.FFT_General(result_signals[c],0);
                //    Array.Resize(ref result_response, result_response.Length / 2);
                //    for (int s = 0; s < result_response.Length; s++)
                //    {
                //        System.Numerics.Complex mod = source_response[s].Magnitude;
                //        if (s > f_limit) mod /= System.Numerics.Complex.Pow(source_response[s], (.5 * Math.Tanh((s-f_limit) * dpi) + 0.5));
                //        result_response[s] /= mod.Magnitude;
                //    }
                //    result_signals[c] = Audio.Pach_SP.IFFT_Real_General(Audio.Pach_SP.Mirror_Spectrum(result_response), 0);
                //}
                //Find Eigenfrequencies
                if (EigenFrequencies.Items.Count > 0)
                {
                    return;
                }
                EigenFrequencies.Items.Clear();
                Find_EigenFrequencies();

                Receiver_Choice.Items.Clear();
                for (int i = 0; i < result_signals.Length; i++)
                {
                    Receiver_Choice.Items.Add(i);
                }
                Time = new double[result_signals[0].Length];
                for (int i = 0; i < Time.Length; i++)
                {
                    Time[i] = (double)i / samplefrequency;
                }
                Receiver_Choice.SelectedIndex = 0;
                Receiver_Choice.Update();
            }
            private void CalculateSim_Click(object sender, EventArgs e)
            {
                EigenFrequencies.Items.Clear();
                Chosenfreq = 0;
                FC = new ForCall(Forw_proc);

                Polygon_Scene Rm = PachTools.Get_Poly_Scene((double)Rel_Humidity.Value, (double)Air_Temp.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked);
                if (!Rm.Complete) return;

                Rhino.Geometry.Point3d[] Src = PachTools.GetSource();
                Rhino.Geometry.Point3d[] Rec = PachTools.GetReceivers().ToArray();
                if (Src.Length < 1 || Rm == null) Rhino.RhinoApp.WriteLine("Model geometry not specified... Exiting calculation...");

                Numeric.TimeDomain.Microphone_Compact Mic = new Numeric.TimeDomain.Microphone_Compact(Rec);
                double fs = 62.5 * Utilities.Numerics.rt2 * Math.Pow(2, Selected_Extent.SelectedIndex);
                //samplefrequency = fs;
                Numeric.TimeDomain.Signal_Driver_Compact SD = new Numeric.TimeDomain.Signal_Driver_Compact(Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse, 1000, 1, PachTools.GetSource());
                FDTD = new Numeric.TimeDomain.Acoustic_Compact_FDTD(Rm, ref SD, ref Mic, fs, (double)CO_TIME.Value);
                FDTD.RuntoCompletion();

                samplefrequency = FDTD.SampleFrequency;

                Mic.reset();
                result_signals = Mic.Recordings[0];
                //System.Numerics.Complex[] source_response = SD.Frequency_Response(result_signals[0].Length);

                //double f_limit = 0.8 * fs / samplefrequency * result_signals[0].Length;
                //double f_top = 1.3 * f_limit;
                //double dpi = Utilities.Numerics.PiX2 / (f_top - f_limit);

                //for (int c = 0; c < result_signals.Length; c++)
                //{
                //    System.Numerics.Complex[] result_response = Audio.Pach_SP.FFT_General(result_signals[c],0);
                //    Array.Resize(ref result_response, result_response.Length / 2);
                //    for (int s = 0; s < result_response.Length; s++)
                //    {
                //        System.Numerics.Complex mod = source_response[s].Magnitude;
                //        if (s > f_limit) mod /= System.Numerics.Complex.Pow(source_response[s], (.5 * Math.Tanh((s-f_limit) * dpi) + 0.5));
                //        result_response[s] /= mod.Magnitude;
                //    }
                //    result_signals[c] = Audio.Pach_SP.IFFT_Real_General(Audio.Pach_SP.Mirror_Spectrum(result_response), 0);
                //}
                //Find Eigenfrequencies
                if (EigenFrequencies.Items.Count > 0) return;
                EigenFrequencies.Items.Clear();
                Find_EigenFrequencies();

                Receiver_Choice.Items.Clear();
                for (int i = 0; i < result_signals.Length; i++) Receiver_Choice.Items.Add(i);
                Time = new double[result_signals[0].Length];
                for (int i = 0; i < Time.Length; i++) Time[i] = (double)i / samplefrequency;
                Receiver_Choice.SelectedIndex = 0;
                Receiver_Choice.Update();

            }
Esempio n. 5
0
            private void CalculateScattering_Click(object sender, EventArgs e)
            {
                Chosenfreq = 0;
                double radius = (double)ScatteringRadius.Value;
                double t      = 4 * (radius + (double)Sample_Depth.Value) / C_Sound() * 1000;

                if (LabCenter == null)
                {
                    return;
                }

                Polygon_Scene Rm      = PachTools.Get_Poly_Scene((double)Rel_Humidity.Value, (double)Air_Temp.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked);
                Empty_Scene   Rm_Ctrl = new Empty_Scene((double)Air_Temp.Value, (double)Rel_Humidity.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked, true, Rm.Min(), Rm.Max());

                Rm_Ctrl.PointsInScene(new List <Hare.Geometry.Point> {
                    Rm.Min(), Rm.Max()
                });
                Rm_Ctrl.partition();

                if (!Rm.Complete && Rm_Ctrl.Complete)
                {
                    return;
                }

                Rhino.Geometry.Point3d ArrayCenter = new Rhino.Geometry.Point3d(LabCenter.X, LabCenter.Y, LabCenter.Z + (double)Sample_Depth.Value);

                Rhino.Geometry.Point3d[] Src = new Rhino.Geometry.Point3d[1] {
                    new Rhino.Geometry.Point3d(LabCenter.X, LabCenter.Y, LabCenter.Z + radius + (double)Sample_Depth.Value)
                };
                List <Rhino.Geometry.Point3d> Rec = new List <Rhino.Geometry.Point3d>();

                for (int phi = 0; phi < 18; phi++)
                {
                    for (int theta = 0; theta < 36; theta++)
                    {
                        double anglePhi   = phi * Math.PI / 18;
                        double angleTheta = theta * Utilities.Numerics.PiX2 / 36;
                        Rec.Add(ArrayCenter + radius * new Rhino.Geometry.Point3d(Math.Cos(angleTheta) * Math.Cos(anglePhi), Math.Sin(angleTheta) * Math.Cos(anglePhi), Math.Sin(anglePhi)));
                    }
                }

                //for (int phi = 0; phi < 18; phi++)
                //    {
                //        double anglePhi = phi * Math.PI / 18;
                //        Rec.Add(ArrayCenter + radius * new Rhino.Geometry.Point3d(Math.Cos(anglePhi), 0, Math.Sin(anglePhi)));
                //    }

                double fs = 62.5 * Utilities.Numerics.rt2 * Math.Pow(2, Scatter_Extent.SelectedIndex);

                Numeric.TimeDomain.Microphone_Compact    Mic   = new Numeric.TimeDomain.Microphone_Compact(Rec.ToArray());
                Numeric.TimeDomain.Signal_Driver_Compact SD    = new Numeric.TimeDomain.Signal_Driver_Compact(Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse, fs, 1, Src);
                Numeric.TimeDomain.Acoustic_Compact_FDTD FDTDS = new Numeric.TimeDomain.Acoustic_Compact_FDTD(Rm, ref SD, ref Mic, fs, t, Numeric.TimeDomain.Acoustic_Compact_FDTD.GridType.ScatteringLab, Utilities.PachTools.RPttoHPt(LabCenter), radius * 2, radius * 2, radius * 1.2 + (double)Sample_Depth.Value);
                FDTDS.RuntoCompletion();

                Numeric.TimeDomain.Microphone_Compact    Micf  = new Numeric.TimeDomain.Microphone_Compact(Rec.ToArray());
                Numeric.TimeDomain.Signal_Driver_Compact SDf   = new Numeric.TimeDomain.Signal_Driver_Compact(Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse, fs, 1, Src);
                Numeric.TimeDomain.Acoustic_Compact_FDTD FDTDF = new Numeric.TimeDomain.Acoustic_Compact_FDTD(Rm_Ctrl, ref SDf, ref Micf, fs, t, Numeric.TimeDomain.Acoustic_Compact_FDTD.GridType.ScatteringLab, Utilities.PachTools.RPttoHPt(LabCenter) + new Hare.Geometry.Point(0, 0, (double)Sample_Depth.Value), radius * 2, radius * 2, radius * 1.2 + (double)Sample_Depth.Value);
                FDTDF.RuntoCompletion();

                samplefrequency = FDTDS.SampleFrequency;

                Mic.reset();
                result_signals = Mic.Recordings[0];
                Micf.reset();
                result_signals = Micf.Recordings[0];

                //Calculate Scattering Coefficients
                double[][] TimeS = Mic.Recordings[0];
                double[][] TimeF = Micf.Recordings[0];

                System.Numerics.Complex[][] FS = new System.Numerics.Complex[TimeS.Length][];
                System.Numerics.Complex[][] FF = new System.Numerics.Complex[TimeS.Length][];

                for (int i = 0; i < TimeS.Length; i++)
                {
                    FS[i] = Audio.Pach_SP.FFT_General(TimeS[i], 0);
                    FF[i] = Audio.Pach_SP.FFT_General(TimeF[i], 0);
                }

                Scattering = new double[FS[0].Length];

                for (int i = 0; i < FS[0].Length; i++)
                {
                    System.Numerics.Complex sumFS2  = 0;
                    System.Numerics.Complex sumFF2  = 0;
                    System.Numerics.Complex sumFSFF = 0;

                    for (int j = 0; j < FS.Length; j++)
                    {
                        sumFS2  += System.Numerics.Complex.Pow(FS[j][i].Magnitude, 2);
                        sumFF2  += System.Numerics.Complex.Pow(FF[j][i].Magnitude, 2);
                        sumFSFF += FS[j][i] * System.Numerics.Complex.Conjugate(FF[j][i]);
                        //sumFS2 += System.Numerics.Complex.Pow(FS[j][i], 2);
                        //sumFF2 += System.Numerics.Complex.Pow(FF[j][i], 2);
                        //sumFSFF += FS[j][i] * System.Numerics.Complex.Conjugate(FF[j][i]);
                    }

                    System.Numerics.Complex sumReflected = sumFSFF / sumFF2;
                    System.Numerics.Complex Ratio        = sumFF2 / sumFS2;
                    Scattering[i] = 1 - System.Numerics.Complex.Abs(sumReflected * sumReflected * Ratio);
                }

                Update_Scattering_Graph(null, null);
            }
            private void CalculateSim_Click(object sender, EventArgs e)
            {
                FC = new ForCall(Forw_proc);

                Polygon_Scene Rm = PachTools.Get_Poly_Scene((double)Rel_Humidity.Value, (double)Air_Temp.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked);
                if (!Rm.Complete) return;

                Rhino.Geometry.Point3d[] Src = PachTools.GetSource();
                Rhino.Geometry.Point3d[] Rec = PachTools.GetReceivers().ToArray();
                if (Src.Length < 1 || Rm == null) Rhino.RhinoApp.WriteLine("Model geometry not specified... Exiting calculation...");

                Numeric.TimeDomain.Microphone_Compact Mic = new Numeric.TimeDomain.Microphone_Compact(Rec);
                double fs = 137.8125 * Math.Pow(2, Selected_Extent.SelectedIndex);
                samplefrequency = fs;
                double df = 1d / ((double)CO_TIME.Value / 1000);
                Numeric.TimeDomain.Signal_Driver_Compact SD = new Numeric.TimeDomain.Signal_Driver_Compact(Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse, df, 1, PachTools.GetSource());
                FDTD = new Numeric.TimeDomain.Acoustic_Compact_FDTD(Rm, ref SD, ref Mic, fs, (double)CO_TIME.Value);

                for (double f = df; f < fs; f += df)
                {
                    FDTD.reset(f, Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse);
                    FDTD.RuntoCompletion();

                    Frequencies.Items.Add(string.Format("{0} Hz.", f), true);
                }

                Receiver_Choice.Text = "0";

                result_signals = Mic.Recordings;
            }