public double[] getSpectrum() { Complex[] tmp = tfr.getTFRAsDoubleArray()[2]; double[] spectrum = new double[tmp.Length]; for (int s = 0; s < tmp.Length; s++) { spectrum[s] = tmp[s].Magnitude; } return(spectrum); }
public double[] inverse(TFR tfr) { int nf = tfr.getTFRAsDoubleArray().Length - 1; int nw = tfr.getTFRAsDoubleArray()[0].Length; int ns = nf * hopSize + nw; double[] output = new double[ns]; fftw_complexarray mdin = new fftw_complexarray(nw); fftw_complexarray mdout = new fftw_complexarray(nw); fftw_plan plan; int hopInd = 0; Complex[] buf = new Complex[nw]; try { for (int hop = 0; hop <= nf * hopSize; hop += hopSize) { mdout.SetData(buf); mdin.SetData(tfr.getTFRAsDoubleArray()[hopInd++]); plan = fftw_plan.dft_1d(winLength, mdin, mdout, fftw_direction.Backward, fftw_flags.Estimate); plan.Execute(); buf = mdout.GetData_Complex(); for (int sample = 0; sample < nw; sample++) { output[sample + hop] = output[sample + hop] + (buf[sample].Real / nw) * win[sample].Real; } } return(output); } catch (Exception) { return(output); } }
public double[] inverse(TFR tfr, ref double[] output_signal_prev, bool last) { int nf = tfr.getTFRAsDoubleArray().Length - 1; int nw = tfr.getTFRAsDoubleArray()[0].Length; int ns = nf * hopSize + nw; double[] output_signal_tmp = new double[ns]; double[] output_signal = new double[output_signal_tmp.Length - 3 * hopSize]; fftw_complexarray mdin = new fftw_complexarray(nw); fftw_complexarray mdout = new fftw_complexarray(nw); fftw_plan plan; if (output_signal_prev == null) { output_signal_prev = new double[3 * hopSize]; } for (int sample = 0; sample < hopSize * 3; sample++) { output_signal_tmp[sample] = output_signal_prev[sample]; } int hopInd = 0; Complex[] buf = new Complex[nw]; try { for (int hop = 0; hop <= nf * hopSize; hop += hopSize) { mdout.SetData(buf); mdin.SetData(tfr.getTFRAsDoubleArray()[hopInd++]); plan = fftw_plan.dft_1d(winLength, mdin, mdout, fftw_direction.Backward, fftw_flags.Estimate); plan.Execute(); buf = mdout.GetData_Complex(); for (int sample = 0; sample < nw; sample++) { output_signal_tmp[sample + hop] = output_signal_tmp[sample + hop] + (buf[sample].Real / nw) * win[sample].Real; } } for (int sample = 0; sample < hopSize * 3; sample++) { output_signal_prev[sample] = output_signal_tmp[output_signal_tmp.Length - hopSize * 3 + sample]; } for (int sample = 0; sample < output_signal.Length; sample++) { output_signal[sample] = output_signal_tmp[sample]; } if (last) { return(output_signal_tmp); } else { return(output_signal); } } catch (Exception) { if (last) { return(output_signal_tmp); } else { return(output_signal); } } }