# Import functions and libraries
from __future__ import division
import numpy as np
from scipy import signal
from numpy import *
from rtsonar import rtsonar
The function rtsonar()
in rtsonar.py
provides a wrapper to create a real-time sonar plot using user-defined processing functions. Copy and paste your functions genPulseTrain(), genChirpPulse(), crossCorr(), findDelay(), and dist2time() to the code cell below. Scroll down to the bottom and you should be able to run rtsonar()
!
The detection resolution and sensitivity will depend on the parameters you will choose for the sonar. The longer the pulse is, the worse time resolution you will get, but much stronger matched filtering amplitude. You can buy the time resolution by using pulse compression with chirp pulses at the expense of increasing the bandwidth.
# Copy and paste your 5 functions here:
# genPulseTrain()
# genChirpPulse()
# crossCorr()
# findDelay()
# dist2time()
# Run this for Real-time Sonar
fs = 44100 # Sampling frequency
f0 = 10000 # Chirp initial frequency
f1 = 18000 # Chirp ending frequency
Npulse = 460 # Length of Chirp Pulse
Nrep = 40 # Number of repitition in a pulse train (determines vertical length of plot )
Nseg = 4096 # Number of samples between pulses (determines maximum time-of-arrival)
Nplot = 300 # Number of pixels in plot along horizontal direction (higher resolution is slower)
maxdist = 300 # Maximum distance in cm
temperature = 20 # Temperature
functions = (genChirpPulse, genPulseTrain, crossCorr, findDelay, dist2time) #join the functions together
stop_flag = rtsonar( f0, f1, fs, Npulse, Nseg, Nrep, Nplot, maxdist, temperature, functions )
# Run this to stop the sonar
stop_flag.set()