public static Complex[] get_pink_noise(int size) { Complex[] res = new Complex[size]; for (int i = 0; i < (size + 1) / 2; ++i) { double mag = Math.Pow((double)i, -0.5f); double phase = (2 * GlobalMembersSpectrogram.random_double() - 1) * Math.PI; //+-pi random phase Complex complex = new Complex(mag * Math.Cos(phase), mag * Math.Sin(phase)); res[i] = complex; } return(res); }
public double[] synt_sine(Bitmap image, int samplerate) { int samples = image.Width * samplerate / pixpersec; Complex[] spectrum = new Complex[samples / 2 + 1]; double filterscale = ((double)spectrum.Length * 2) / samplerate; Filterbank filterbank = Filterbank.get_filterbank(frequency_axis, filterscale, basefreq, bandwidth, overlap); for (int bandidx = 0; bandidx < image.Height; ++bandidx) { //if (cancelled()) // return List<int>(); band_progress(bandidx, image.Height - 1); double[] envelope = envelope_from_spectrogram(image, bandidx); // random phase between +-pi double phase = (2 * GlobalMembersSpectrogram.random_double() - 1) * Math.PI; double[] bandsignal = new double[envelope.Length * 2]; for (int j = 0; j < 4; ++j) { double sine = Math.Cos(j * Math.PI / 2 + phase); for (int i = j; i < bandsignal.Length; i += 4) { bandsignal[i] = envelope[i / 2] * sine; } } Complex[] filterband = GlobalMembersSpectrogram.padded_FFT(bandsignal); for (int i = 0; i < filterband.Length; ++i) { double x = (double)i / filterband.Length; // normalized blackman window antiderivative filterband[i] *= x - ((0.5 / (2.0 * Math.PI)) * Math.Sin(2.0 * Math.PI * x) + (0.08 / (4.0 * Math.PI)) * Math.Sin(4.0 * Math.PI * x) / 0.42); } Console.Out.WriteLine("spectrum size: {0}", spectrum.Length); //std::cout << bandidx << ". filterband size: " << filterband.Length << "; start: " << filterbank->get_band(bandidx).first <<"; end: " << filterbank->get_band(bandidx).second << "\n"; double center = filterbank.get_center(bandidx); double offset = Math.Max((uint)0, center - filterband.Length / 2); Console.Out.WriteLine("offset: {0} = {1} hz", offset, offset / filterscale); for (uint i = 0; i < filterband.Length; ++i) { if (offset + i > 0 && offset + i < spectrum.Length) { spectrum[(int)(offset + i)] += filterband[i]; } } } double[] @out = GlobalMembersSpectrogram.padded_IFFT(spectrum); Console.Out.WriteLine("samples: {0} -> {1}", @out.Length, samples); GlobalMembersSpectrogram.normalize_signal(ref @out); return(@out); }