1 Star 0 Fork 0

alfar/GNSS-DSP-tools

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
acquire-gps-l1cp.py 2.23 KB
一键复制 编辑 原始数据 按行查看 历史
Peter Monta 提交于 2018-08-13 10:11 . set python scripts to executable
#!/usr/bin/env python
import sys
import os
import numpy as np
import scipy.signal
import scipy.fftpack as fft
import gnsstools.gps.l1cp as l1cp
import gnsstools.nco as nco
import gnsstools.io as io
#
# Acquisition search
#
def search(x,prn):
fs = 8192000.0
n = 81920 # 10 ms coherent integration
incr = float(l1cp.code_length)/n
c = l1cp.code(prn,0,0,incr,n) # obtain samples of the L1Cp 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(-7000,7000,20): # doppler bins
q = np.zeros(n)
w = nco.nco(-doppler/fs,0,n)
for block in range(8): # 8 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 = l1cp.code_length*(float(idx)/n)
m_doppler = doppler
m_code = m_code%l1cp.code_length
return m_metric,m_code,m_doppler
#
# main program
#
# parse command-line arguments
# example:
# ./acquire-gps-l1cp.py /dev/stdin 69984000 -9334875
filename = sys.argv[1] # input data, raw file, i/q interleaved, 8 bit signed (two's complement)
fs = float(sys.argv[2]) # sampling rate, Hz
coffset = float(sys.argv[3]) # offset to L1C GPS carrier, Hz (positive or negative)
# read first 85 ms of file
n = int(fs*0.085)
fp = open(filename,"rb")
x = io.get_samples_complex(fp,n)
# resample to 8.192 MHz
fsr = 8192000.0/fs
nco.mix(x,-coffset/fs,0)
h = scipy.signal.firwin(161,4e6/(fs/2),window='hanning')
x = scipy.signal.filtfilt(h,[1],x)
xr = np.interp((1/fsr)*np.arange(85*8192),np.arange(len(x)),np.real(x))
xi = np.interp((1/fsr)*np.arange(85*8192),np.arange(len(x)),np.imag(x))
x = xr+(1j)*xi
# iterate (in parallel) over PRNs of interest
def worker(p):
x,prn = p
metric,code,doppler = search(x,prn)
return 'prn %3d doppler % 7.1f metric % 7.1f code_offset %6.1f' % (prn,doppler,metric,code)
import multiprocessing as mp
#prns = list(range(1,33))+[193,194,195,199]
prns = [193,194,195,199]
cpus = mp.cpu_count()
results = mp.Pool(cpus).map(worker, map(lambda prn: (x,prn),prns))
for r in results:
print(r)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/alfar999/GNSS-DSP-tools.git
git@gitee.com:alfar999/GNSS-DSP-tools.git
alfar999
GNSS-DSP-tools
GNSS-DSP-tools
master

搜索帮助