Exemplo n.º 1
0
    def analysis(self, x):
        """
        Perform frequency analysis of a real input using DFT.

        Parameters
        ----------
        x : numpy array
            Real signal in time domain.

        Returns
        -------
        numpy array
            DFT of input.
        """

        # check for valid input
        if x.shape != self.x.shape:
            raise ValueError(
                'Invalid input dimensions! Got (%d, %d), expecting (%d, %d).' %
                (x.shape[0], x.shape[1], self.x.shape[0], self.x.shape[1]))

        # apply window if needed
        if self.analysis_window is not None:
            np.multiply(self.analysis_window, x, x)

        # apply DFT
        if self.transform == 'fftw':
            self.a[:, ] = x
            self.X[:, ] = self._forward()
        elif self.transform == 'mkl':
            self.X[:, ] = mkl_fft.rfft_numpy(x, self.nfft, axis=self.axis)
        else:
            self.X[:, ] = rfft(x, self.nfft, axis=self.axis)

        return self.X
Exemplo n.º 2
0
    a = pyfftw.empty_aligned([nfft, D], dtype="float32")
    b = pyfftw.empty_aligned([nfft // 2 + 1, D], dtype="complex64")
    c = pyfftw.empty_aligned([nfft, D], dtype="float32")
    forward = pyfftw.FFTW(a, b, axes=(0, ))
    backward = pyfftw.FFTW(b, c, axes=(0, ), direction="FFTW_BACKWARD")

    start_time = time.time()
    for k in range(n_trials):
        forward()
    analysis_time = (time.time() - start_time) / n_trials * 1e6
    start_time = time.time()
    for k in range(n_trials):
        backward()
    synthesis_time = (time.time() - start_time) / n_trials * 1e6
    print(
        "avg fftw w/o class : %f [1e-6 sec], (analysis, synthesis)=(%f, %f) [1e-6 sec]"
        % (analysis_time + synthesis_time, analysis_time, synthesis_time))

if mkl_available:
    start_time = time.time()
    for k in range(n_trials):
        X = mkl_fft.rfft_numpy(x)
    analysis_time = (time.time() - start_time) / n_trials * 1e6
    start_time = time.time()
    for k in range(n_trials):
        x_r = mkl_fft.irfft_numpy(X)
    synthesis_time = (time.time() - start_time) / n_trials * 1e6
    print(
        "avg mkl w/o class : %f [1e-6 sec], (analysis, synthesis)=(%f, %f) [1e-6 sec]"
        % (analysis_time + synthesis_time, analysis_time, synthesis_time))