перепиши для python package ru.basisintellect.plugin_LTR11.utils;


import static java.lang.Math.*;

public class FFT_Koef {
    private final int fs;
    private final int dataSize;
    private final int celoe, nn, nn1 ;
    private final double twoPI = PI*2, fh;
    private final double[] ffth, outData;
    private final int uu;


    public FFT_Koef(int fs, int dataSize) {
        this.fs = fs;
        this.dataSize = dataSize;
        this.celoe = (int) (floor(log(dataSize)/log(2)));
        this.nn = (int) round(pow(2,this.celoe));
        this.fh = (double) fs/nn;
        this.nn1 = (int) round(0.5 * nn);
        this.uu = 2 * nn;
        this.ffth = new double[nn1];
        this.outData = new double[uu];
        for (int i = 0; i < nn1; i++) {
           ffth[i] = i * fh;
        }

    }

    public double[] compute(double[] inData){
        return compute(inData, true);
    }

    public double[] compute(double[] inData, boolean forward){
        int isign, i, j, ii, m, mmax, istep, div1, div2, jj;
        double tempr, tempi, wtemp, theta, wpr, wpi, wr, wi, maxi;

        if(dataSize == inData.length){
        for (i = 0; i < dataSize; i++) {
            j = 2 * i;
            outData[j] = inData[i];
            outData[j + 1] = 0;
        }

        }else{
            for (i = 0; i < inData.length; i++) {
                outData[i] = inData[i];
            }
        }
        if(forward)
            isign = -1;
        else
            isign = 1;
        j = 1;
        ii = 1;
        while(ii <= nn){
            i = 2 * ii - 1;
            if(j > i){
                tempr = outData[j-1];
                tempi = outData[j];
                outData[j-1] = outData[i-1];
                outData[j] = outData[i];
                outData[i-1] = tempr;
                outData[i] = tempi;
            }
            m = nn;
            while ((m >= 2)&&(j > m)){
                j -= m;
                m = m / 2;
            }
            j += m;
            ii++;
        }
        mmax = 2;
        while (uu > mmax){
            istep = 2 * mmax;
            theta = twoPI / (isign * mmax);
            wpr = -2 * pow(sin(0.5 * theta), 2);
            wpi = sin(theta);
            wr = 1;
            wi = 0;
            ii = 1;
            div1 = mmax / 2;

            while (ii <= div1){
                m = 2 * ii - 1;
                jj = 0;
                div2 = (uu - m) / istep;

                while (jj <= div2){
                    i = m + jj * istep;
                    j = i + mmax;
                    tempr = wr * outData[j-1] - wi * outData[j];
                    tempi = wr * outData[j] + wi * outData[j - 1];
                    outData[j - 1] = outData[i - 1] - tempr;
                    outData[j] = outData[i] - tempi;
                    outData[i - 1] = outData[i - 1] + tempr;
                    outData[i] = outData[i] + tempi;
                    jj++;
                }
                wtemp = wr;
                wr = wr * wpr - wi * wpi + wr;
                wi = wi * wpr + wtemp * wpi + wi;
                ii++;
            }
            mmax = istep;
        }
        if(forward){
            i = 1;
            while (i <= uu){
                outData[i - 1] = outData[i-1] / nn;
                i++;
            }
        }
        maxi = 0;



        return outData;

    }
}