mil_passive_sonar - Passive Sonar

Utility Functions

mil_passive_sonar.algorithms.run(samples: ndarray, sample_rate: int, v_sound: int, dist_h: float, dist_h4: float)[source]

The traditional passive sonar algorithm.

Parameters
  • samples (np.ndarray) – The samples relevant to the system.

  • sample_rate (int) – The rate at which samples are recorded, in the number of samples per second.

  • v_sound (int) – The velocity of sound in the environment, in m/s. In fresh water, this should be ~1497 m/s.

  • dist_h (float) –

    ???

  • dist_h4 (float) –

    ???

mil_passive_sonar.algorithms.zero_mean(samples: ndarray)[source]

Zero means data by assuming that the first 32 samples are zeros.

mil_passive_sonar.algorithms.normalize(samples: ndarray)[source]

Rescapes samples so each individual channel lies between -1 and 1.

mil_passive_sonar.algorithms.compute_freq(samples: ndarray, sample_rate: int, freq_range, plot: bool = False)[source]

Checks whether samples are likely a solid ping and returns the frequency.

mil_passive_sonar.algorithms.bin_to_freq(bin: int, sample_rate: int, fft_length: int) float[source]

Converts a bin to a frequency bin.

Parameters
  • bin (int) – The bin number.

  • sample_rate (int) – The rate of samples. The number of samples per second.

  • fft_length (int) – The length of the transform; the number of bins.

mil_passive_sonar.algorithms.freq_to_bin(freq: int, sample_rate: int, fft_length: int) float[source]

Converts a frequency pattern to the number of bins in the transform.

Parameters
  • freq (int) –

    ???

  • sample_rate (int) – The rate of samples. The number of samples per second.

  • fft_length (int) – The length of the transform.

mil_passive_sonar.algorithms.preprocess(samples: ndarray, sample_rate: int, desired_sample_rate: int)[source]

Upsamples data to have approx. desired_sample_rate.

Parameters
  • samples (np.ndarray) – The relevant samples to preprocess.

  • sample_rate (int) – The rate to record samples at. Equal to the number of samples per second.

  • desired_sample_rate (int) – The desired sample rate.

mil_passive_sonar.algorithms.bandpass(samples: ndarray, sample_rate: int)[source]

Applies a 20-30khz bandpass FIR filter.

Parameters
  • samples (np.ndarray) – The list of samples.

  • sample_rate (int) – The rate of sampling. The number of samples per second.

mil_passive_sonar.algorithms.compute_deltas(samples: ndarray, sample_rate: int, max_delay: float, template_duration: float, plot: bool = False)[source]

Computes N-1 position deltas for N channels, by making a template for the first channel and matching to all subsequent channels.

Parameters
  • samples (np.ndarray) – The samples relevant to the system.

  • sample_rate (int) – The rate at which samples are recorded, in the number of samples per second.

  • max_delay (float) –

    ???

  • template_duration (float) –

    ???

  • plot (bool) – Whether to plot and show the data.

mil_passive_sonar.algorithms.make_template(channel: ndarray, width: int)[source]

Returns a template of the specified width, with its 25% position being at where the lower-level driver triggered.

Parameters
  • channel (np.ndarray) –

    ???

  • width (int) –

    ???

mil_passive_sonar.algorithms.match_template(channel: ndarray, start: int, stop: int, template: ndarray)[source]

Matches template to channel, returning the point where the start of the template should be placed.

Parameters
  • channel (np.ndarray) –

    ???

  • start (int) – The start of the template in the channel

  • stop (int) – The end of the template in the channel

  • template (np.ndarray) – The template to match the channel to

mil_passive_sonar.algorithms.calculate_error(channel: ndarray, start: int, stop: int, template: ndarray)[source]

Slides the template along channel from start to stop, giving the error of the template and channel at each location.

Parameters
  • channel (np.ndarray) –

    ???

  • start (int) – The start of the template in the channel

  • stop (int) – The end of the template in the channel

  • template (np.ndarray) – The template to match the channel to

mil_passive_sonar.algorithms.find_minimum(data: ndarray)[source]

Finds the sub-sample position of the minimum in a continuous signal, by first finding the lowest absolute value, then doing quadratic interpolation.

Parameters

data (np.ndarray) – The relevant signal.

mil_passive_sonar.algorithms.compute_pos_4hyd(deltas: ndarray, sample_rate: int, v_sound: int, dist_h: float, dist_h4: float)[source]

Solves the 4 hydrophone case (3 deltas) for heading, declination, and sph_dist using a bunch of trig. Future work would be to phrase this as a NLLSQ problem or something, and adapt it to more hydrophones.

Parameters
  • samples (np.ndarray) – The samples relevant to the system.

  • sample_rate (int) – The rate at which samples are recorded, in the number of samples per second.

  • v_sound (int) – The velocity of sound in the environment, in m/s. In fresh water, this should be ~1497 m/s.

  • dist_h (float) –

    ???

  • dist_h4 (float) –

    ???

TxHydrophonesClient

class mil_passive_sonar.TxHydrophonesClient(nh: NodeHandle)[source]

TxROS abstraction for interacting with the nodes in this package.

dir_callback

The method that is called when a ping is received.

Type

Optional[Callable]

Construct a client.

Parameters

nh (NodeHandle) – The TxROS node handler.

disable() None[source]

Disable listening to pings for position estimation.

enable() None[source]

Enable listening to pings for position estimation.

get_direction() Future[source]

Get the next processed direction to the pinger.

Returns

A Future object which can be used to get the next message of the pinger’s direction.

Return type

asycio.Future

get_last_position() PointStamped[source]

Get the last processed position of the pinger.

Returns

A cached value of the last position of the pinger.

Return type

PointStamped

get_position() Future[source]

Get the next processed position of the pinger.

Returns

A Future object which can be used to get the next message of the pinger’s position.

Return type

asyncio.Future

heading_cb(heading_msg: Vector3Stamped)[source]

Callback for pings received.

Parameters

heading_msg (Vector3Stamped) – The passed-in message representing the heading.

reset() None[source]

Reset the position estimation of the pinger.

set_callback(cb: Callable)[source]

Set a callback for when a ping is received.

Parameters

cb (Callable) – The callback to set. The callback should have a single parameter that takes a Vector3Stamped message representing the heading towards the pinger.

StreamedBandpass

class mil_passive_sonar.streamed_bandpass.StreamedBandpass(lower: float, upper: float, trans_width: float, order: float, rate: Optional[float] = None)[source]
Class for bandpass filtering sequential batches of data. Takes care of the

overlap-adding that needs to be done when filtering sequential batches of data individually.

lower

The lower bound of the desired frequency.

Type

float

upper

The upper bound of the desired frequency.

Type

float

trans_width

A magical special filter property!

Type

float

order

Filter order for the bandpass filter. Higher is better, but slower to compute.

Type

float

rate

The rate at which data is sent.

Type

Optional[float]

h

The Remez exchange algorithm, if defined. Constructed when the filter is made.

Type

Optional[np.ndarray]

Constructs the class using the variables provided. Checks if the class is ready to make a filter, and if so, the filter is constructed.

Parameters
  • lower (float) – The lower bound of the desired frequency.

  • upper (float) – The upper bound of the desired frequency.

  • trans_width (float) – A magical special filter property!

  • order (float) – Filter order for the bandpass filter. Higher is better, but slower to compute.

  • rate (Optional[float]) – The rate at which data is sent.

convolve(data: ndarray) ndarray[source]

Does the filtering.

Parameters

data (np.ndarray) – Numpy array of shape (samples, channels).

Returns

The resulting filtered data.

Return type

np.ndarray

is_ready_to_make_filter() bool[source]

Checks whether the filter is ready to be made. Checks that the lower variable is not None.

Returns

Whether or not the filter can be made.

Return type

bool

make_filter() None[source]

Makes the data filter.

Raises

Exception – Some necessary parameters of the class are None.

HydrophoneTrigger

class mil_passive_sonar.scripts.triggering.HydrophoneTrigger[source]

ROS Node meant to trigger only when a ping happens in our target frequency range.

Subscribes to raw hydrophone samples on /samples.

Publishes samples (of gradient) from right around the triggering on /pings when a ping is detected and found to be in the target frequency range.

Optionally, you can publish a plot of the frequency response of the filter on /filter_debug by service calling /filter_debug_trigger.

general_lower

The lower bound of the frequency range. Set to the frequency of the lowest frequency pinger - 10 kHz.

Type

int

general_upper

The upper bound of the frequency range. Set to the frequency of the lowest frequency pinger - 10 kHz.

Type

int

time

The amount of time that has passed since recording started, according to the messages received.

Type

float

window_time

The maximum number of seconds to wait for another ping.

Type

float

pub

A publisher for the /pings topic. Publishes Triggered messages.

Type

rospy.Publisher

sub

A subscriber to the /samples topic. Receives either a Ping or HydrophoneSamplesStamped message, and sends the message to hydrophones_cb().

Type

Optional[rospy.Subscriber]

trigger_debug

A plotter responsible for publishing debug data about the triggering behavior of the system.

Type

Plotter

enable(req: SetBoolRequest) SetBoolResponse[source]

Enables the system; can be called through a SetBoolRequest request.

Parameters

req (SetBoolRequest) – The service request.

Returns

The response to the service request.

Return type

SetBoolResponse

filter_response(req: TriggerRequest) TriggerResponse[source]

Filters the debug service. Serves as a callback to the service.

Parameters

req (TriggerRequest) – The trigger request.

Returns

The response to the request.

Return type

TriggerResponse

hydrophones_cb(msg: Union[Ping, HydrophoneSamplesStamped]) None[source]

The callback to the hydrophone samples topic. Can receive either a Ping or HydrophoneSamplesStamped message.

Parameters

msg (Union[Ping, HydrophoneSamplesStamped]) – The message that can be received by the callback.

reset(req: TriggerRequest) TriggerResponse[source]

Resets the system using the :meth`.get_params` method.

Parameters

req (TriggerRequest) – The request received.

Returns

Whether the reset request was successful.

Return type

TriggerResponse

PingLocator

Methods
class mil_passive_sonar.scripts.ping_locator.PingLocator[source]

Subscribers to /pings, and publishes vector to the pinger on /direction. Creates a node named ping_locator.

enable(req: SetBoolRequest) SetBoolResponse[source]

Sets the locator to enabled. Doesn’t immediately do anything.

Parameters

req (SetBoolRequest) – The service request.

Returns

The service response.

Return type

SetBoolResponse

ping_cb(msg) None[source]

Callback called with each new ping. With each call, creates a Vector3Stamped message containing the direction of the pinger.

Parameters

msg (Triggered) – The received message, with numpy formatting.

SylphaseSonarToRosNode

Functions
class SylphaseSonarToRosNode

ROS node which reads in the TCP stream produced by the Sylphase passive sonar board. Publishes the data to a topic as a message.

Public Functions

SylphaseSonarToRosNode(ros::NodeHandle nh, ros::NodeHandle private_nh)

Constructor with a node handle and private node handle. Upon construction, gets the IP, port, the frame of reference, and the number of seconds to capture.

void run()

Attempts to read messages forever from the TCP socket. Messages are published as a HydrophoneSamples type.

If an error is encountered, then waits 5 seconds and then tries to connect to the socket again.

Public Members

const size_t SAMPLES_PER_SECOND = 1.2E6

Sampling frequency of the Sylphase board.

const size_t CHANNELS = 4

Number of channels in the Sylphase board.