Ejemplo n.º 1
0
    def calc(self, x, n=5):
        f = lambda fd: array(
            [e**(-2j * pi * fd * n / self.fs) for n in arange(self.N)])

        # Filters.
        a = [1.0]
        b_coarse = signal.firwin(60, 20e3 / self.fs)
        b_medium = signal.firwin(60, 1e3 / self.fs)
        b_fine = signal.firwin(60, 0.4e3 / self.fs)

        # Truncate and reshape input signal.
        x = reshape(self.truncate(x, self.N), (-1, self.N))[:n]

        # Coarse acquisition.
        # Hvorfor virker conj(fft.fft naar fft.ifft ikke funker??
        X = conj(fft.fft(x))
        r = sum(array([abs(fft.ifft(self.LC * X_i)) for X_i in X]), axis=0)
        (f_coarse, ca_delay) = self.argmax_2d(r)
        f_coarse = self.doppler_range[f_coarse]
        p_debug("Coarse f: %f Hz." % (f_coarse))

        # Remove C/A code from input signal.
        x = x * ca_code.ca_code(svn=self.svn, fs=self.fs, ca_shift=ca_delay)

        # Mix down to f_coarse and reduce BW to 1kHz.
        x = x * f(f_coarse)
        x = signal.lfilter(b_coarse, a, x)

        # Medium resolution calculation.
        f_medium = arange(-400, 400 + 1, 400)
        Xk = [abs(self.dft(x[0], f_i)) for f_i in f_medium]
        f_medium = f_medium[argmax(Xk)]
        if x.ndim < 2:
            x = reshape(x, (1, -1))
        p_debug("Medium f: %f Hz." % f_medium)

        # Mix down to f_medium and reduce BW to 400 Hz.
        x = x * f(f_medium)
        x = signal.lfilter(b_medium, a, x)

        # Fine frequency calculation.
        Xk = self.dft(x, f_medium)
        theta = angle(Xk)

        d_theta = array(
            [theta[n] - theta[n - 1] for n in range(1, len(theta))])

        def foo_theta(d_theta):
            tmp = d_theta
            if abs(d_theta) > self.threshold:
                d_theta = tmp - 2 * pi
                if abs(d_theta) > self.threshold:
                    d_theta = tmp + 2 * pi
                    if abs(d_theta) > self.threshold:
                        d_theta = tmp - pi
                        if abs(d_theta) > self.threshold:
                            d_theta = tmp - 3 * pi
                            if abs(d_theta) > self.threshold:
                                d_theta = tmp + pi
            return d_theta

        d_theta = array(map(foo_theta, d_theta))
        f_fine = d_theta.mean() / (2 * pi * 1e-3)
        p_debug("Fine frequency: %f Hz." % f_fine)

        return (f_coarse + f_medium + f_fine, ca_delay)
Ejemplo n.º 2
0
    def calc(self, x, n=5):
        f = lambda fd: array([ e**( -2j*pi*fd*n/self.fs) for n in arange(self.N)])

        # Filters.
        a = [1.0]
        b_coarse = signal.firwin( 60, 20e3/self.fs)
        b_medium = signal.firwin( 60, 1e3/self.fs)
        b_fine = signal.firwin( 60, 0.4e3/self.fs)

        # Truncate and reshape input signal.
        x = reshape ( self.truncate( x, self.N), (-1, self.N))[:n]

        # Coarse acquisition. 
        # Hvorfor virker conj(fft.fft naar fft.ifft ikke funker??
        X = conj(fft.fft(x))
        r = sum( array([ abs(fft.ifft( self.LC*X_i)) for X_i in X ]), axis=0)
        (f_coarse, ca_delay) = self.argmax_2d(r)
        f_coarse = self.doppler_range[ f_coarse ]
        p_debug( "Coarse f: %f Hz." % (f_coarse) )


        # Remove C/A code from input signal.
        x = x * ca_code.ca_code(svn=self.svn, fs=self.fs, ca_shift=ca_delay)

        # Mix down to f_coarse and reduce BW to 1kHz.
        x = x * f(f_coarse)
        x = signal.lfilter( b_coarse, a, x )

        # Medium resolution calculation.
        f_medium = arange(-400, 400+1, 400)
        Xk = [ abs(self.dft(x[0],f_i)) for f_i in f_medium ]
        f_medium = f_medium[ argmax(Xk) ]
        if x.ndim < 2:
            x = reshape(x, (1,-1))
        p_debug( "Medium f: %f Hz." % f_medium )

        # Mix down to f_medium and reduce BW to 400 Hz.
        x = x * f(f_medium)
        x = signal.lfilter( b_medium, a, x )


        # Fine frequency calculation.
        Xk = self.dft(x, f_medium)
        theta = angle(Xk)

        d_theta = array([ theta[n] - theta[n-1] for n in range(1, len(theta)) ])

        def foo_theta(d_theta):
            tmp = d_theta
            if abs(d_theta) > self.threshold:
                d_theta = tmp - 2*pi
                if abs(d_theta) > self.threshold:
                    d_theta = tmp + 2*pi
                    if abs(d_theta) > self.threshold:
                        d_theta = tmp - pi
                        if abs(d_theta) > self.threshold:
                            d_theta = tmp - 3*pi
                            if abs(d_theta) > self.threshold:
                                d_theta = tmp + pi
            return d_theta

        d_theta = array( map( foo_theta, d_theta))
        f_fine = d_theta.mean()/(2*pi*1e-3)
        p_debug( "Fine frequency: %f Hz." % f_fine )

        return (f_coarse + f_medium + f_fine, ca_delay)
Ejemplo n.º 3
0
 def local_code(self, shift=0):
     code = ca_code.ca_code(svn=self.svn, fs=self.fs, ca_shift=shift)
     f = lambda fd: array(
         [e**(2j * pi * fd * n / self.fs) for n in range(len(code))])
     lc = array([code * f(fd) for fd in self.doppler_range])
     return (lc, fft.fft(lc))
Ejemplo n.º 4
0
 def local_code(self, shift=0):
     code = ca_code.ca_code(svn=self.svn, fs=self.fs, ca_shift=shift)
     f = lambda fd: array( [ e**(2j*pi*fd*n/self.fs) for n in range(len(code))] )
     lc = array( [code*f(fd) for fd in self.doppler_range ] )
     return ( lc, fft.fft(lc))