Example #1
0
def cross_correlation(x, y):
  """
  computes cross correlation between the two signals in the frequency domain. Returns a time series and frequency series
  """
  N = len(x)
  if N != len(y):
    sys.exit("lengths don't agree in liapunov.cross_correlation")
  cfx = fft.complex_forward_float([complex(r,-i) for r,i in x]) # fourier transform
  cfy = fft.complex_forward_float([complex(r,i) for r,i in y])

  fcc = cfy * cfx.conjugate()
  tcc = fft.complex_inverse_float( fcc ) # multiply and take inverse fourier transform

  return [[c.real, c.imag] for c in tcc], [[c.real, c.imag] for c in fcc] # return as a list of reals
Example #2
0
def nmode_fft(t_P, q, verbose=False):
    """
  defines my fft routine in one location

  frequency spacing checked against the GSL documentation on 5/5/2013
  """
    N_m = len(q)
    freq = fft_freq(t_P)  # frequency spacing to match GSL FFT

    fq = []
    for m in range(N_m):
        if verbose:
            print "computing FFT for mode " + str(m)
        if verbose:
            print "\tcasting time domain as complex"
        cq = [complex(l[0], l[1]) for l in q[m]]
        if verbose:
            print "\tcomputing complex FFT"
        cfq = list(fft.complex_forward_float(cq))
        cfq = cfq[len(cfq) / 2 + 1 :] + cfq[: len(cfq) / 2 + 1]
        if len(cfq) != len(freq):
            print len(cfq)
            print len(freq)
            print len_t_P
            sys.exit("Something's wrong in Nmode_utils.nmode_fft: len(cfq) != len(freq)")
        if verbose:
            print "\tappending complex FFT to fq in standard format (list of reals)"
        fq.append([[L.real, L.imag] for L in cfq])

    return freq, fq, N_m
Example #3
0
def single_fft(t_P, A, verbose=False):
  """
  performs the fft over the single value A and returns a list of lists of real numbers
  """
  freq = fft_freq(t_P) # frequency spacing to match GSL FFT

  if verbose: print "computing complex FFT"
  cfA = list(fft.complex_forward_float(A))
  cfA = cfA[len(cfA)/2+1:] + cfA[:len(cfA)/2+1]
  if len(cfA) != len(freq):
    print len(cfA)
    print len(freq)
    print len_t_P
    sys.exit("Something's wrong in Nmode_utils.nmode_fft: len(cfq) != len(freq)")
  if verbose: print "\tconverting complex FFT to standard format (list of reals)"
  fA = [ [L.real, L.imag] for L in cfA ]

  return freq, fA