public BluesteinTransformlet(int R, int N, Complex[] u)
            : base(R, N, u)
        {
            // figure out the right Bluestein length and create a transformer for it
            Nb = SetBluesteinLength(2 * R - 1);
            ft = new FourierTransformer(Nb);

            // compute the Bluestein coeffcients and compute the FT of the filter based on them
            b = ComputeBluesteinCoefficients(R);
            Complex[] c = new Complex[Nb];
            c[0] = 1.0;
            for (int i = 1; i < R; i++) {
                c[i] = b[i].Conjugate;
                c[Nb - i] = c[i];
            }
            bt = ft.Transform(c);
        }
Example #2
0
        public BluesteinTransformlet(int R, int N, Complex[] u) : base(R, N, u)
        {
            // figure out the right Bluestein length and create a transformer for it
            Nb = SetBluesteinLength(2 * R - 1);
            ft = new FourierTransformer(Nb);

            // compute the Bluestein coeffcients and compute the FT of the filter based on them
            b = ComputeBluesteinCoefficients(R);
            Complex[] c = new Complex[Nb];
            c[0] = 1.0;
            for (int i = 1; i < R; i++)
            {
                c[i]      = b[i].Conjugate;
                c[Nb - i] = c[i];
            }
            bt = ft.Transform(c);
        }
Example #3
0
        public static List<double> AmplitudeFromLR2(int snapsize, double[] l, int i_skip, int i_count, double lowpass = 2.5, Dictionary<int, double> mw = null)
        {
            FourierTransformer ft = new FourierTransformer(snapsize);
            var xxa = new Complex[i_count];

            if (mw.Count == i_count)
                for (int j = 0; j < i_count; j++)
                    xxa[j] = new Complex(l[j + i_skip] * mw[j], l[j + i_skip] * mw[j]);
            else
                return null;

            var ftt = ft.Transform(xxa).Take((int)(i_count / (2 * lowpass))); // TAKING ONLY LEFT HALF OF FFT RESULT

            List<double> pow_re_im = new List<double>();
            //ftt.ToList().ForEach(t => pow_re_im.Add(Math.Log(ComplexMath.Abs(t))));
            //ftt.ToList().ForEach(t => pow_re_im.Add(Math.Sqrt(Math.Max(Math.Log(ComplexMath.Abs(t)),0))));
            ftt.ToList().ForEach(t => pow_re_im.Add(Math.Pow(Math.Max(Math.Log(ComplexMath.Abs(t)), 0), 2)));

            return pow_re_im;
        }
Example #4
0
            public bool MakeSnaps(int _snapsize, int _snapcount, string _path, int smooth_size)
            {
                try
                {
                    using (Mp3FileReader pcm = new Mp3FileReader(_path))
                    {
                        int samplesDesired = _snapsize;
                        int blockscount = _snapcount;

                        snap_size = _snapsize;
                        snap_count = _snapcount;
                        total_samples = pcm.Length;
                        length = pcm.TotalTime.Seconds;
                        path = _path;

                        if ((pcm.WaveFormat.SampleRate != 44100) || (pcm.WaveFormat.BitsPerSample != 16))
                            return false;

                        for (int i = 0; i < blockscount; i++)
                        {
                            byte[] buffer = new byte[samplesDesired * 4];
                            short[] left = new short[samplesDesired];
                            short[] right = new short[samplesDesired];
                            double[] leftd = new double[samplesDesired];
                            double[] rightd = new double[samplesDesired];

                            int bytesRead = 0;

                            //for (int j = 0; j < 1; j++) ///////////
                            int seek_counter = 0;
                        seek: pcm.Seek((i + 1) * (i + 1) * (i + 1) * blockscount * samplesDesired % (total_samples - samplesDesired), SeekOrigin.Begin);
                            seek_counter++;

                            bytesRead = pcm.Read(buffer, 0, 4 * samplesDesired);

                            int index = 0;
                            for (int sample = 0; sample < bytesRead / 4; sample++)
                            {
                                left[sample] = BitConverter.ToInt16(buffer, index); index += 2;
                                right[sample] = BitConverter.ToInt16(buffer, index); index += 2;
                            }

                            if (left.Average(t => Math.Abs(t)) == 0)
                                if (seek_counter > 5)
                                    return false;
                                else
                                    goto seek;

                            //snap_log10_energy.Add(Math.Log10(left.Average(t => Math.Abs(t))));

                            leftd = Normalize(left, left.Length);
                            rightd = Normalize(right, right.Length);

                            //alglib.complex[] fl;
                            //alglib.fftr1d(leftd, out fl);
                            //fl[0].x;

                            FourierTransformer ft = new FourierTransformer(samplesDesired);
                            var xxa = new Complex[leftd.Length];

                            for (int j = 0; j < leftd.Length; j++)
                                xxa[j] = new Complex(leftd[j], rightd[j]);

                            var ftt = ft.Transform(xxa);

                            List<double> pow_re_im = new List<double>();
                            //List<double> arg_re_im = new List<double>();

                            ftt.ToList().ForEach(t => pow_re_im.Add(ComplexMath.Abs(t)));
                            //ftt.ToList().ForEach(t => arg_re_im.Add(ComplexMath.Arg(t)));

                            /*if (Double.IsNaN(MC_Log10_Energy(pow_re_im)))
                                if (seek_counter > 5)
                                    return false;
                                else
                                    goto seek;*/

                            fft_snaps.Add(pow_re_im);
                            //fft_smoothed_snaps.Add(Smoothen(pow_re_im, smooth_size));

                            //pow_re_im = Normalize(pow_re_im);

                            /*
                            var f_pwri = pow_re_im.Average(t => Math.Abs(t));
                            for (int k = 0; k < pow_re_im.Count; k++)
                                pow_re_im[k] = (Math.Abs(pow_re_im[k]) >= f_pwri * 1.5) ? pow_re_im[k] : 0;
                            */

                            /*
                            FourierTransformer ft2 = new FourierTransformer(samplesDesired);
                            var xx2 = new List<Complex>();
                            for (int j = 0; j < pow_re_im.Count; j++)
                            {
                                xx2.Add(new Complex(pow_re_im[j], arg_re_im[j]));
                            }
                            var ftt2 = ft2.Transform(xx2);
                            //var ftt2 = ft2.Transform(ftt);

                            List<double> pow_re_im2 = new List<double>();
                            ftt2.ToList().ForEach(t => pow_re_im2.Add(ComplexMath.Abs(t)));
                            pow_re_im2 = Normalize(pow_re_im2);
                            fft2_snaps.Add(pow_re_im2);
                            fft2_smoothed_snaps.Add(Smoothen(pow_re_im2, smooth_size));
                            */
                        }
                        pcm.Close();
                    }
                }
                catch (Exception e)
                {
                return false;
                }

                return true;
            }