Python scipy.fftpack.ifft() Examples

The following are 30 code examples of scipy.fftpack.ifft(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module scipy.fftpack , or try the search function .
Example #1
Source File: grid.py    From simnibs with GNU General Public License v3.0 7 votes vote down vote up
def quadrature_cc_1D(N):
    """ Computes the Clenshaw Curtis nodes and weights """
    N = np.int(N)        
    if N == 1:
        knots = 0
        weights = 2
    else:
        n = N - 1
        C = np.zeros((N,2))
        k = 2*(1+np.arange(np.floor(n/2)))
        C[::2,0] = 2/np.hstack((1, 1-k*k))
        C[1,1] = -n
        V = np.vstack((C,np.flipud(C[1:n,:])))
        F = np.real(ifft(V, n=None, axis=0))
        knots = F[0:N,1]
        weights = np.hstack((F[0,0],2*F[1:n,0],F[n,0]))
            
    return knots, weights 
Example #2
Source File: pychebfun.py    From fluids with MIT License 6 votes vote down vote up
def polyval(self, chebcoeff):
        """
        Compute the interpolation values at Chebyshev points.
        chebcoeff: Chebyshev coefficients
        """
        N = len(chebcoeff)
        if N == 1:
            return chebcoeff

        data = even_data(chebcoeff)/2
        data[0] *= 2
        data[N-1] *= 2

        fftdata = 2*(N-1)*fftpack.ifft(data, axis=0)
        complex_values = fftdata[:N]
        # convert to real if input was real
        if np.isrealobj(chebcoeff):
            values = np.real(complex_values)
        else:
            values = complex_values
        return values 
Example #3
Source File: test_basic.py    From Computable with MIT License 6 votes vote down vote up
def test_definition(self):
        x1 = [1,2,3,4,1,2,3,4]
        x1_1 = [1,2+3j,4+1j,2+3j,4,2-3j,4-1j,2-3j]
        x2 = [1,2,3,4,1,2,3,4,5]
        x2_1 = [1,2+3j,4+1j,2+3j,4+5j,4-5j,2-3j,4-1j,2-3j]

        def _test(x, xr):
            y = irfft(np.array(x, dtype=self.rdt))
            y1 = direct_irdft(x)
            self.assertTrue(y.dtype == self.rdt,
                    "Output dtype is %s, expected %s" % (y.dtype, self.rdt))
            assert_array_almost_equal(y,y1, decimal=self.ndec)
            assert_array_almost_equal(y,ifft(xr), decimal=self.ndec)

        _test(x1, x1_1)
        _test(x2, x2_1) 
Example #4
Source File: test_basic.py    From GraphicDesignPatternByPython with MIT License 6 votes vote down vote up
def test_size_accuracy(self):
        # Sanity check for the accuracy for prime and non-prime sized inputs
        if self.rdt == np.float32:
            rtol = 1e-5
        elif self.rdt == np.float64:
            rtol = 1e-10

        for size in LARGE_COMPOSITE_SIZES + LARGE_PRIME_SIZES:
            np.random.seed(1234)
            x = np.random.rand(size).astype(self.rdt)
            y = ifft(fft(x))
            _assert_close_in_norm(x, y, rtol, size, self.rdt)
            y = fft(ifft(x))
            _assert_close_in_norm(x, y, rtol, size, self.rdt)

            x = (x + 1j*np.random.rand(size)).astype(self.cdt)
            y = ifft(fft(x))
            _assert_close_in_norm(x, y, rtol, size, self.rdt)
            y = fft(ifft(x))
            _assert_close_in_norm(x, y, rtol, size, self.rdt) 
Example #5
Source File: test_pdos.py    From pwtools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_pdos_1d():
    pad=lambda x: pad_zeros(x, nadd=len(x)-1)
    n=500; w=welch(n)
    # 1 second signal
    t=np.linspace(0,1,n); dt=t[1]-t[0]
    # sum of sin()s with random freq and phase shift, 10 frequencies from
    # f=0...100 Hz
    v=np.array([np.sin(2*np.pi*f*t + rand()*2*np.pi) for f in rand(10)*100]).sum(0)
    f=np.fft.fftfreq(2*n-1, dt)[:n]

    c1=mirror(ifft(abs(fft(pad(v)))**2.0)[:n].real)
    c2=correlate(v,v,'full')
    c3=mirror(acorr(v,norm=False))
    assert np.allclose(c1, c2)
    assert np.allclose(c1, c3)

    p1=(abs(fft(pad(v)))**2.0)[:n]
    p2=(abs(fft(mirror(acorr(v,norm=False)))))[:n]
    assert np.allclose(p1, p2)

    p1=(abs(fft(pad(v*w)))**2.0)[:n]
    p2=(abs(fft(mirror(acorr(v*w,norm=False)))))[:n]
    assert np.allclose(p1, p2) 
Example #6
Source File: audio_tools.py    From tools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def istft(X, fftsize=128, step="half", wsola=False, mean_normalize=True,
          real=False, compute_onesided=True):
    """
    Compute ISTFT for STFT transformed X
    """
    if real:
        local_ifft = fftpack.irfft
        X_pad = np.zeros((X.shape[0], X.shape[1] + 1)) + 0j
        X_pad[:, :-1] = X
        X = X_pad
    else:
        local_ifft = fftpack.ifft
    if compute_onesided:
        X_pad = np.zeros((X.shape[0], 2 * X.shape[1])) + 0j
        X_pad[:, :fftsize // 2 + 1] = X
        X_pad[:, fftsize // 2 + 1:] = 0
        X = X_pad
    X = local_ifft(X).astype("float64")
    if step == "half":
        X = invert_halfoverlap(X)
    else:
        X = overlap_add(X, step, wsola=wsola)
    if mean_normalize:
        X -= np.mean(X)
    return X 
Example #7
Source File: fourier_pricer.py    From fftoptionlib with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def carr_madan_fraction_fft_call_pricer(N, d_u, d_k, alpha, r, t, S0, q, chf_ln_st):
    rou = (d_u * d_k) / (2 * np.pi)
    beta = np.log(S0) - d_k * N / 2
    u_arr = np.arange(N) * d_u
    k_arr = beta + np.arange(N) * d_k
    delta_arr = np.zeros(N)
    delta_arr[0] = 1
    w_arr = d_u / 3 * (3 + (-1) ** (np.arange(N) + 1) - delta_arr)
    call_chf = (np.exp(-r * t) / ((alpha + 1j * u_arr) * (alpha + 1j * u_arr + 1))) * chf_ln_st(
        u_arr - (alpha + 1) * 1j,
        t, r, q=q, S0=S0)
    x_arr = np.exp(-1j * beta * u_arr) * call_chf * w_arr
    y_arr = np.zeros(2 * N) * 0j
    y_arr[:N] = np.exp(-1j * np.pi * rou * np.arange(N) ** 2) * x_arr
    z_arr = np.zeros(2 * N) * 0j
    z_arr[:N] = np.exp(1j * np.pi * rou * np.arange(N) ** 2)
    z_arr[N:] = np.exp(1j * np.pi * rou * np.arange(N - 1, -1, -1) ** 2)
    ffty = (fft(y_arr))
    fftz = (fft(z_arr))
    fftx = ffty * fftz
    fftpsi = ifft(fftx)
    fft_prices = np.exp(-1j * np.pi * (np.arange(N) ** 2) * rou) * fftpsi[:N]
    call_prices = (np.exp(-alpha * k_arr) / np.pi) * fft_prices.real
    return np.exp(k_arr), call_prices 
Example #8
Source File: whiten.py    From dispel4py with Apache License 2.0 6 votes vote down vote up
def spectralwhitening_smooth(stream, N):
    """
    Apply spectral whitening to data.
    Data is divided by its smoothed (Default: None) amplitude spectrum.
    """
    stream2 = copy.deepcopy(stream)

    for trace in arange(len(stream2)):
        data = stream2[trace].data

        n = len(data)
        nfft = nextpow2(n)

        spec = fft(data, nfft)
        spec_ampl = sqrt(abs(multiply(spec, conjugate(spec))))

        spec_ampl = smooth(spec_ampl, N)

        spec /= spec_ampl  # Do we need to do some smoothing here?
        ret = real(ifft(spec, nfft)[:n])

        stream2[trace].data = ret

    return stream2 
Example #9
Source File: whiten.py    From dispel4py with Apache License 2.0 6 votes vote down vote up
def spectralwhitening(stream):
    """
    Apply spectral whitening to data.
    Data is divided by its smoothed (Default: None) amplitude spectrum.
    """
    stream2 = copy.deepcopy(stream)

    for trace in arange(len(stream2)):
        data = stream2[trace].data

        n = len(data)
        nfft = nextpow2(n)

        spec = fft(data, nfft)
        spec_ampl = sqrt(abs(multiply(spec, conjugate(spec))))

        spec /= spec_ampl  # Do we need to do some smoothing here?
        ret = real(ifft(spec, nfft)[:n])

        stream2[trace].data = ret

    return stream2 
Example #10
Source File: Convolution.py    From ClearMap with GNU General Public License v3.0 6 votes vote down vote up
def _centered(arr, newsize):
    # Return the center newsize portion of the array.
    newsize = numpy.asarray(newsize)
    currsize = numpy.array(arr.shape)
    startind = (currsize - newsize) // 2
    endind = startind + newsize
    myslice = [slice(startind[k], endind[k]) for k in range(len(endind))]
    return arr[tuple(myslice)]


#def _rfftn(a, s=None, axes=None):
#    s, axes = _cook_nd_args(a, s, axes);
#    a = fft.rfft(a, s[-1], axes[-1], overwrite_x = True)
#    for ii in range(len(axes)-1):
#        a = fft.fft(a, s[ii], axes[ii], overwrite_x = True)
#    return a

#def _irfftn(a, s=None, axes=None):   
#    #a = asarray(a).astype('complex64')
#    s, axes = _cook_nd_args(a, s, axes, invreal=1)
#    for ii in range(len(axes)-1):
#        a = fft.ifft(a, s[ii], axes[ii], overwrite_x = True);
#    a = fft.ifft(a, s[-1], axes[-1], overwrite_x = True);
#    a = a.real;
#    return a 
Example #11
Source File: connectivity.py    From spectral_connectivity with GNU General Public License v3.0 5 votes vote down vote up
def _estimate_noise_covariance(minimum_phase):
    '''Given a matrix square root of the cross spectral matrix (
    minimum phase factor), non-parametrically estimate the noise covariance
    of a multivariate autoregressive model (MVAR).

    Parameters
    ----------
    minimum_phase : array, shape (n_time_windows, n_fft_samples,
                                  n_signals, n_signals)
        The matrix square root of a cross spectral matrix.

    Returns
    -------
    noise_covariance : array, shape (n_time_windows, n_signals, n_signals)
        The noise covariance of a MVAR model.

    References
    ----------
    .. [1] Dhamala, M., Rangarajan, G., and Ding, M. (2008). Analyzing
           information flow in brain networks with nonparametric Granger
           causality. NeuroImage 41, 354-362.

    '''
    inverse_fourier_coefficients = ifft(minimum_phase, axis=-3).real
    return _complex_inner_product(
        inverse_fourier_coefficients[..., 0, :, :],
        inverse_fourier_coefficients[..., 0, :, :]).real 
Example #12
Source File: connectivity.py    From spectral_connectivity with GNU General Public License v3.0 5 votes vote down vote up
def _estimate_transfer_function(minimum_phase):
    '''Given a matrix square root of the cross spectral matrix (
    minimum phase factor), non-parametrically estimate the transfer
    function of a multivariate autoregressive model (MVAR).

    Parameters
    ----------
    minimum_phase : array, shape (n_time_windows, n_fft_samples,
                                  n_signals, n_signals)
        The matrix square root of a cross spectral matrix.

    Returns
    -------
    transfer_function : array, shape (n_time_windows, n_fft_samples,
                                      n_signals, n_signals)
        The transfer function of a MVAR model.

    References
    ----------
    .. [1] Dhamala, M., Rangarajan, G., and Ding, M. (2008). Analyzing
           information flow in brain networks with nonparametric Granger
           causality. NeuroImage 41, 354-362.

    '''
    inverse_fourier_coefficients = ifft(minimum_phase, axis=-3).real
    return np.matmul(
        minimum_phase,
        np.linalg.inv(inverse_fourier_coefficients[..., 0:1, :, :])) 
Example #13
Source File: filter_bank.py    From kymatio with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_normalizing_factor(h_f, normalize='l1'):
    """
    Computes the desired normalization factor for a filter defined in Fourier.

    Parameters
    ----------
    h_f : array_like
        numpy vector containing the Fourier transform of a filter
    normalized : string, optional
        desired normalization type, either 'l1' or 'l2'. Defaults to 'l1'.

    Returns
    -------
    norm_factor : float
        such that h_f * norm_factor is the adequately normalized vector.
    """
    h_real = ifft(h_f)
    if np.abs(h_real).sum() < 1e-7:
        raise ValueError('Zero division error is very likely to occur, ' +
                         'aborting computations now.')
    if normalize == 'l1':
        norm_factor = 1. / (np.abs(h_real).sum())
    elif normalize == 'l2':
        norm_factor = 1. / np.sqrt((np.abs(h_real)**2).sum())
    else:
        raise ValueError("Supported normalizations only include 'l1' and 'l2'")
    return norm_factor 
Example #14
Source File: acquire-beidou-b1i.py    From GNSS-DSP-tools with MIT License 5 votes vote down vote up
def search(x,prn,doppler_search,ms):
  fs = 8192000.0
  n = 8192                                         # 1 ms coherent integration
  doppler_min, doppler_max, doppler_incr = doppler_search
  incr = float(b1i.code_length)/n
  c = b1i.code(prn,0,0,incr,n)                     # obtain samples of the B1I code
  c = fft.fft(np.concatenate((c,np.zeros(n))))
  m_metric,m_code,m_doppler = 0,0,0
  for doppler in np.arange(doppler_min,doppler_max,doppler_incr):        # doppler bins
    q = np.zeros(2*n)
    w = nco.nco(-doppler/fs,0,2*n)
    for block in range(ms):                        # incoherent sums
      b = x[(block*n):((block+2)*n)]
      b = b*w
      r = fft.ifft(c*np.conj(fft.fft(b)))
      q = q + np.absolute(r)
    idx = np.argmax(q)
    if q[idx]>m_metric:
      m_metric = q[idx]
      m_code = b1i.code_length*(float(idx)/n)
      m_doppler = doppler
  m_code = m_code%b1i.code_length
  return m_metric,m_code,m_doppler

#
# main program
# 
Example #15
Source File: acquire-beidou-b2bq.py    From GNSS-DSP-tools with MIT License 5 votes vote down vote up
def search(x,prn,doppler_search,ms):
  fs = 3*10230000.0
  n = 3*10230                                       # 1 ms coherent integration
  doppler_min, doppler_max, doppler_incr = doppler_search
  incr = float(b2bq.code_length)/n
  c = b2bq.code(prn,0,0,incr,n)                     # obtain samples of the E5b-I code
  c = fft.fft(np.concatenate((c,np.zeros(n))))
  m_metric,m_code,m_doppler = 0,0,0
  for doppler in np.arange(doppler_min,doppler_max,doppler_incr):        # doppler bins
    q = np.zeros(2*n)
    w = nco.nco(-doppler/fs,0,2*n)
    for block in range(ms):                         # incoherent sums
      b = x[(block*n):((block+2)*n)]
      b = b*w
      r = fft.ifft(c*np.conj(fft.fft(b)))
      q = q + np.absolute(r)
    idx = np.argmax(q)
    if q[idx]>m_metric:
      m_metric = q[idx]
      m_code = b2bq.code_length*(float(idx)/n)
      m_doppler = doppler
  m_code = m_code%b2bq.code_length
  return m_metric,m_code,m_doppler

#
# main program
# 
Example #16
Source File: acquire-galileo-e6b.py    From GNSS-DSP-tools with MIT License 5 votes vote down vote up
def search(x,prn,doppler_search,ms):
  fs = 3*5115000.0
  n = 3*5115                                       # 1 ms coherent integration
  doppler_min, doppler_max, doppler_incr = doppler_search
  incr = float(e6b.code_length)/n
  c = e6b.code(prn,0,0,incr,n)                     # obtain samples of the E6-B code
  c = fft.fft(np.concatenate((c,np.zeros(n))))
  m_metric,m_code,m_doppler = 0,0,0
  for doppler in np.arange(doppler_min,doppler_max,doppler_incr):        # doppler bins
    q = np.zeros(2*n)
    w = nco.nco(-doppler/fs,0,2*n)
    for block in range(ms):                        # incoherent sums
      b = x[(block*n):((block+2)*n)]
      b = b*w
      r = fft.ifft(c*np.conj(fft.fft(b)))
      q = q + np.absolute(r)
    idx = np.argmax(q)
    if q[idx]>m_metric:
      m_metric = q[idx]
      m_code = e6b.code_length*(float(idx)/n)
      m_doppler = doppler
  m_code = m_code%e6b.code_length
  return m_metric,m_code,m_doppler

#
# main program
# 
Example #17
Source File: acquire-galileo-e6c.py    From GNSS-DSP-tools with MIT License 5 votes vote down vote up
def search(x,prn,doppler_search,ms):
  fs = 3*5115000.0
  n = 3*5115                                       # 1 ms coherent integration
  doppler_min, doppler_max, doppler_incr = doppler_search
  incr = float(e6c.code_length)/n
  c = e6c.code(prn,0,0,incr,n)                     # obtain samples of the E1-B code
  c = fft.fft(np.concatenate((c,np.zeros(n))))
  m_metric,m_code,m_doppler = 0,0,0
  for doppler in np.arange(doppler_min,doppler_max,doppler_incr):        # doppler bins
    q = np.zeros(2*n)
    w = nco.nco(-doppler/fs,0,2*n)
    for block in range(ms):                        # incoherent sums
      b = x[(block*n):((block+2)*n)]
      b = b*w
      r = fft.ifft(c*np.conj(fft.fft(b)))
      q = q + np.absolute(r)
    idx = np.argmax(q)
    if q[idx]>m_metric:
      m_metric = q[idx]
      m_code = e6c.code_length*(float(idx)/n)
      m_doppler = doppler
  m_code = m_code%e6c.code_length
  return m_metric,m_code,m_doppler

#
# main program
# 
Example #18
Source File: acquire-gps-l1cd.py    From GNSS-DSP-tools with MIT License 5 votes vote down vote up
def search(x,prn,doppler_search,ms):
  blocks = ms//10
  fs = 8192000.0
  n = 81920                                        # 10 ms coherent integration
  doppler_min, doppler_max, doppler_incr = doppler_search
  incr = float(l1cd.code_length)/n
  c = l1cd.code(prn,0,0,incr,n)                    # obtain samples of the L1Cd code
  boc = nco.boc11(0,0,incr,n)
  c = fft.fft(c*boc)
  m_metric,m_code,m_doppler = 0,0,0
  for doppler in np.arange(doppler_min,doppler_max,doppler_incr):         # doppler bins
    q = np.zeros(n)
    w = nco.nco(-doppler/fs,0,n)
    for block in range(blocks):                    # incoherent sums
      b = x[(block*n):((block+1)*n)]
      b = b*w
      r = fft.ifft(c*np.conj(fft.fft(b)))
      q = q + np.absolute(r)
    idx = np.argmax(q)
    if q[idx]>m_metric:
      m_metric = q[idx]
      m_code = l1cd.code_length*(float(idx)/n)
      m_doppler = doppler
  m_code = m_code%l1cd.code_length
  return m_metric,m_code,m_doppler

#
# main program
# 
Example #19
Source File: transforms.py    From spectral_connectivity with GNU General Public License v3.0 5 votes vote down vote up
def _auto_correlation(data, axis=-1):
    n_time_samples_per_window = data.shape[axis]
    n_fft_samples = next_fast_len(2 * n_time_samples_per_window - 1)
    dpss_fft = fft(data, n_fft_samples, axis=axis)
    power = dpss_fft * dpss_fft.conj()
    return np.real(ifft(power, axis=axis)) 
Example #20
Source File: acquire-galileo-e5bi.py    From GNSS-DSP-tools with MIT License 5 votes vote down vote up
def search(x,prn,doppler_search,ms):
  fs = 3*10230000.0
  n = 3*10230                                       # 1 ms coherent integration
  doppler_min, doppler_max, doppler_incr = doppler_search
  incr = float(e5bi.code_length)/n
  c = e5bi.code(prn,0,0,incr,n)                     # obtain samples of the E5b-I code
  c = fft.fft(np.concatenate((c,np.zeros(n))))
  m_metric,m_code,m_doppler = 0,0,0
  for doppler in np.arange(doppler_min,doppler_max,doppler_incr):        # doppler bins
    q = np.zeros(2*n)
    w = nco.nco(-doppler/fs,0,2*n)
    for block in range(ms):                         # incoherent sums
      b = x[(block*n):((block+2)*n)]
      b = b*w
      r = fft.ifft(c*np.conj(fft.fft(b)))
      q = q + np.absolute(r)
    idx = np.argmax(q)
    if q[idx]>m_metric:
      m_metric = q[idx]
      m_code = e5bi.code_length*(float(idx)/n)
      m_doppler = doppler
  m_code = m_code%e5bi.code_length
  return m_metric,m_code,m_doppler

#
# main program
# 
Example #21
Source File: acquire-glonass-l3ocp.py    From GNSS-DSP-tools with MIT License 5 votes vote down vote up
def search(x,prn,doppler_search,ms):
  fs = 3*10230000.0
  n = 3*10230                                       # 1 ms coherent integration
  doppler_min, doppler_max, doppler_incr = doppler_search
  incr = float(l3ocp.code_length)/n
  c = l3ocp.code(prn,0,0,incr,n)                     # obtain samples of the L3-I code
  c = fft.fft(np.concatenate((c,np.zeros(n))))
  m_metric,m_code,m_doppler = 0,0,0
  for doppler in np.arange(doppler_min,doppler_max,doppler_incr):        # doppler bins
    q = np.zeros(2*n)
    w = nco.nco(-doppler/fs,0,2*n)
    for block in range(ms):                         # incoherent sums
      b = x[(block*n):((block+2)*n)]
      b = b*w
      r = fft.ifft(c*np.conj(fft.fft(b)))
      q = q + np.absolute(r)
    idx = np.argmax(q)
    if q[idx]>m_metric:
      m_metric = q[idx]
      m_code = l3ocp.code_length*(float(idx)/n)
      m_doppler = doppler
  m_code = m_code%l3ocp.code_length
  return m_metric,m_code,m_doppler

#
# main program
# 
Example #22
Source File: acquire-galileo-e5aq.py    From GNSS-DSP-tools with MIT License 5 votes vote down vote up
def search(x,prn,doppler_search,ms):
  fs = 3*10230000.0
  n = 3*10230                                       # 1 ms coherent integration
  doppler_min, doppler_max, doppler_incr = doppler_search
  incr = float(e5aq.code_length)/n
  c = e5aq.code(prn,0,0,incr,n)                     # obtain samples of the E5b-Q code
  c = fft.fft(np.concatenate((c,np.zeros(n))))
  m_metric,m_code,m_doppler = 0,0,0
  for doppler in np.arange(doppler_min,doppler_max,doppler_incr):        # doppler bins
    q = np.zeros(2*n)
    w = nco.nco(-doppler/fs,0,2*n)
    for block in range(ms):                         # incoherent sums
      b = x[(block*n):((block+2)*n)]
      b = b*w
      r = fft.ifft(c*np.conj(fft.fft(b)))
      q = q + np.absolute(r)
    idx = np.argmax(q)
    if q[idx]>m_metric:
      m_metric = q[idx]
      m_code = e5aq.code_length*(float(idx)/n)
      m_doppler = doppler
  m_code = m_code%e5aq.code_length
  return m_metric,m_code,m_doppler

#
# main program
# 
Example #23
Source File: acquire-beidou-b2bi.py    From GNSS-DSP-tools with MIT License 5 votes vote down vote up
def search(x,prn,doppler_search,ms):
  fs = 3*10230000.0
  n = 3*10230                                       # 1 ms coherent integration
  doppler_min, doppler_max, doppler_incr = doppler_search
  incr = float(b2bi.code_length)/n
  c = b2bi.code(prn,0,0,incr,n)                     # obtain samples of the E5b-I code
  c = fft.fft(np.concatenate((c,np.zeros(n))))
  m_metric,m_code,m_doppler = 0,0,0
  for doppler in np.arange(doppler_min,doppler_max,doppler_incr):        # doppler bins
    q = np.zeros(2*n)
    w = nco.nco(-doppler/fs,0,2*n)
    for block in range(ms):                         # incoherent sums
      b = x[(block*n):((block+2)*n)]
      b = b*w
      r = fft.ifft(c*np.conj(fft.fft(b)))
      q = q + np.absolute(r)
    idx = np.argmax(q)
    if q[idx]>m_metric:
      m_metric = q[idx]
      m_code = b2bi.code_length*(float(idx)/n)
      m_doppler = doppler
  m_code = m_code%b2bi.code_length
  return m_metric,m_code,m_doppler

#
# main program
# 
Example #24
Source File: acquire-gps-l2cm.py    From GNSS-DSP-tools with MIT License 5 votes vote down vote up
def search(x,prn,doppler_search,ms):
  blocks = ms//20 - 1
  fs = 4096000.0
  n = 81920                                        # 20 ms coherent integration
  doppler_min, doppler_max, doppler_incr = doppler_search
  incr = float(l2cm.code_length)/n
  c = l2cm.code(prn,0,0,incr,n)                    # obtain samples of the L2CM code
  c = fft.fft(np.concatenate((c,np.zeros(n))))
  m_metric,m_code,m_doppler = 0,0,0
  for doppler in np.arange(doppler_min,doppler_max,doppler_incr):         # doppler bins
    q = np.zeros(2*n)
    w = nco.nco(-doppler/fs,0,2*n)
    for block in range(blocks):                    # incoherent sums
      b = x[(block*n):((block+2)*n)]
      b = b*w
      r = fft.ifft(c*np.conj(fft.fft(b)))
      q = q + np.absolute(r)
    idx = np.argmax(q)
    if q[idx]>m_metric:
      m_metric = q[idx]
      m_code = l2cm.code_length*(float(idx)/n)
      m_doppler = doppler
  m_code = m_code%l2cm.code_length
  return m_metric,m_code,m_doppler

#
# main program
# 
Example #25
Source File: acquire-beidou-b3i.py    From GNSS-DSP-tools with MIT License 5 votes vote down vote up
def search(x,prn,doppler_search,ms):
  fs = 3*10230000.0
  n = 3*10230                                       # 1 ms coherent integration
  doppler_min, doppler_max, doppler_incr = doppler_search
  incr = float(b3i.code_length)/n
  c = b3i.code(prn,0,0,incr,n)                      # obtain samples of the B3I code
  c = fft.fft(np.concatenate((c,np.zeros(n))))
  m_metric,m_code,m_doppler = 0,0,0
  for doppler in np.arange(doppler_min,doppler_max,doppler_incr):        # doppler bins
    q = np.zeros(2*n)
    w = nco.nco(-doppler/fs,0,2*n)
    for block in range(ms):                         # incoherent sums
      b = x[(block*n):((block+2)*n)]
      b = b*w
      r = fft.ifft(c*np.conj(fft.fft(b)))
      q = q + np.absolute(r)
    idx = np.argmax(q)
    if q[idx]>m_metric:
      m_metric = q[idx]
      m_code = b3i.code_length*(float(idx)/n)
      m_doppler = doppler
  m_code = m_code%b3i.code_length
  return m_metric,m_code,m_doppler

#
# main program
# 
Example #26
Source File: acquire-beidou-b2i.py    From GNSS-DSP-tools with MIT License 5 votes vote down vote up
def search(x,prn,doppler_search,ms):
  fs = 8192000.0
  n = 8192                                         # 1 ms coherent integration
  doppler_min, doppler_max, doppler_incr = doppler_search
  incr = float(b1i.code_length)/n
  c = b1i.code(prn,0,0,incr,n)                     # obtain samples of the B1I code
  c = fft.fft(np.concatenate((c,np.zeros(n))))
  m_metric,m_code,m_doppler = 0,0,0
  for doppler in np.arange(doppler_min,doppler_max,doppler_incr):        # doppler bins
    q = np.zeros(2*n)
    w = nco.nco(-doppler/fs,0,2*n)
    for block in range(ms):                        # incoherent sums
      b = x[(block*n):((block+2)*n)]
      b = b*w
      r = fft.ifft(c*np.conj(fft.fft(b)))
      q = q + np.absolute(r)
    idx = np.argmax(q)
    if q[idx]>m_metric:
      m_metric = q[idx]
      m_code = b1i.code_length*(float(idx)/n)
      m_doppler = doppler
  m_code = m_code%b1i.code_length
  return m_metric,m_code,m_doppler

#
# main program
# 
Example #27
Source File: acquire-galileo-e1b.py    From GNSS-DSP-tools with MIT License 5 votes vote down vote up
def search(x,prn,doppler_search,ms):
  blocks = ms//4 - 1
  fs = 8192000.0
  n = 32768                                        # 4 ms coherent integration
  doppler_min, doppler_max, doppler_incr = doppler_search
  incr = float(e1b.code_length)/n
  c = e1b.code(prn,0,0,incr,n)                     # obtain samples of the E1-B code
  boc = nco.boc11(0,0,incr,n)
  c = fft.fft(np.concatenate((c*boc,np.zeros(n))))
  m_metric,m_code,m_doppler = 0,0,0
  for doppler in np.arange(doppler_min,doppler_max,doppler_incr):        # doppler bins
    q = np.zeros(2*n)
    w = nco.nco(-doppler/fs,0,2*n)
    for block in range(blocks):                    # incoherent sums
      b = x[(block*n):((block+2)*n)]
      b = b*w
      r = fft.ifft(c*np.conj(fft.fft(b)))
      q = q + np.absolute(r)
    idx = np.argmax(q)
    if q[idx]>m_metric:
      m_metric = q[idx]
      m_code = e1b.code_length*(float(idx)/n)
      m_doppler = doppler
  m_code = m_code%e1b.code_length
  return m_metric,m_code,m_doppler

#
# main program
# 
Example #28
Source File: acquire-glonass-l3ocd.py    From GNSS-DSP-tools with MIT License 5 votes vote down vote up
def search(x,prn,doppler_search,ms):
  fs = 3*10230000.0
  n = 3*10230                                       # 1 ms coherent integration
  doppler_min, doppler_max, doppler_incr = doppler_search
  incr = float(l3ocd.code_length)/n
  c = l3ocd.code(prn,0,0,incr,n)                     # obtain samples of the L3-I code
  c = fft.fft(np.concatenate((c,np.zeros(n))))
  m_metric,m_code,m_doppler = 0,0,0
  for doppler in np.arange(doppler_min,doppler_max,doppler_incr):        # doppler bins
    q = np.zeros(2*n)
    w = nco.nco(-doppler/fs,0,2*n)
    for block in range(ms):                         # incoherent sums
      b = x[(block*n):((block+2)*n)]
      b = b*w
      r = fft.ifft(c*np.conj(fft.fft(b)))
      q = q + np.absolute(r)
    idx = np.argmax(q)
    if q[idx]>m_metric:
      m_metric = q[idx]
      m_code = l3ocd.code_length*(float(idx)/n)
      m_doppler = doppler
  m_code = m_code%l3ocd.code_length
  return m_metric,m_code,m_doppler

#
# main program
# 
Example #29
Source File: acquire-gps-l5i.py    From GNSS-DSP-tools with MIT License 5 votes vote down vote up
def search(x,prn,doppler_search,ms):
  fs = 3*10230000.0
  n = 3*10230                                       # 1 ms coherent integration
  doppler_min, doppler_max, doppler_incr = doppler_search
  incr = float(l5i.code_length)/n
  c = l5i.code(prn,0,0,incr,n)                      # obtain samples of the L5I code
  c = fft.fft(np.concatenate((c,np.zeros(n))))
  m_metric,m_code,m_doppler = 0,0,0
  for doppler in np.arange(doppler_min,doppler_max,doppler_incr):        # doppler bins
    q = np.zeros(2*n)
    w = nco.nco(-doppler/fs,0,2*n)
    for block in range(ms):                         # incoherent sums
      b = x[(block*n):((block+2)*n)]
      b = b*w
      r = fft.ifft(c*np.conj(fft.fft(b)))
      q = q + np.absolute(r)
    idx = np.argmax(q)
    if q[idx]>m_metric:
      m_metric = q[idx]
      m_code = l5i.code_length*(float(idx)/n)
      m_doppler = doppler
  m_code = m_code%l5i.code_length
  return m_metric,m_code,m_doppler

#
# main program
# 
Example #30
Source File: signal.py    From pyGSTi with Apache License 2.0 5 votes vote down vote up
def idft(modes, null_hypothesis, counts=1):
    """
    Inverts the dft function.

    Parameters
    ----------
    modes : array
        The fourier modes to be transformed to the time domain.

    null_hypothesis : array
        The array that was used in the normalization before the dct. This is
        commonly the mean of the time-domain data vector. All elements of this
        array must be in (0,1).

     counts : int, optional
        A factor in the normalization, that should correspond to the counts-per-timestep (so
        for full time resolution this is 1).

    Returns
    -------
    array
        Inverse of the dft function

    """
    z = _np.sqrt(len(modes)) * _ifft(modes)  # TIM CHECK THIS: len(*modes*) correct?
    x = unstandardizer(z, null_hypothesis, counts)
    return x