Digital Signal Processing

The CR-Nimble library has some handy digital signal processing routines implemented in JAX. They are available as part of the cr.nimble.dsp package.

Signal Energy

energy(data[, axis])

Computes the energy of the signal along the specified axis

Thresholding

hard_threshold(x, K)

Returns the indices and corresponding values of largest K non-zero entries in a vector x

hard_threshold_sorted(x, K)

Returns the sorted indices and corresponding values of largest K non-zero entries in a vector x

hard_threshold_by(x, t)

Sets all entries in x to be zero which are less than t in magnitude

largest_indices_by(x, t)

Returns the locations of all entries in x which are larger than t in magnitude

energy_threshold(signal, fraction)

Keeps only as much coefficients in signal so as to capture a fraction of signal energy

hard_threshold_tau(x, tau)

Hard thresholding as per [CCSW14]

soft_threshold_tau(x, tau)

Soft thresholding as per [CCSW14]

half_threshold_tau(x, tau)

Half thresholding as per [CCSW14]

hard_threshold_percentile(x, perc)

Percentile hard thresholding as per [CCSW14]

soft_threshold_percentile(x, perc)

Percentile soft thresholding as per [CCSW14]

half_threshold_percentile(x, perc)

Percentile half thresholding as per [CCSW14]

gamma_to_tau_half_threshold(gamma)

Converts gamma to tau for half thresholding as per [CCSW14]

gamma_to_tau_hard_threshold(gamma)

Converts gamma to tau for hard thresholding as per [CCSW14]

Scaling

scale_to_0_1(x)

Scales a signal to the range of 0 and 1

scale_0_mean_1_var(data[, axis])

Normalizes a data vector (data - mu) / sigma

Quantization

quantize_1(x, n)

Quantizes a signal to n bits where signal values are bounded by 1

Spectrum Analysis

norm_freq(frequency, sampling_rate)

Returns the normalized frequency

frequency_spectrum(x[, dt])

Frequency spectrum of 1D data using FFT

power_spectrum(x[, dt])

Power spectrum of 1D data using FFT

Interpolation

interpft(x, N)

Interpolates x to n points in Fourier Transform domain

Windowing

sliding_windows_rw(x, wlen, overlap)

Converts a signal into sliding windows (per row) with the specified overlap

sliding_windows_cw(x, wlen, overlap)

Converts a signal into sliding windows (per column) with the specified overlap

Sparse Signals

Following functions analyze, transform, or construct signals which are known to be sparse.

nonzero_values(x)

Returns the values of non-zero entries in x

nonzero_indices(x)

Returns the indices of non-zero entries in x

support(x)

Returns the indices of non-zero entries in x

largest_indices(x, K)

Returns the indices of K largest entries in x by magnitude

sparse_approximation(x, K)

Keeps only largest K non-zero entries by magnitude in a vector x

build_signal_from_indices_and_values(length, …)

Builds a sparse signal from its non-zero entries (specified by their indices and values)

Matrices of Sparse Signals

Following functions analyze, transform, or construct collections of sparse signals organized as matrices.

randomize_rows(key, X)

Randomizes the rows in X

randomize_cols(key, X)

Randomizes the columns in X

Sparse representation matrices (row-wise)

take_along_rows(X, indices)

Picks K entries from each row of X specified by indices matrix

largest_indices_rw(X, K)

Returns the indices of K largest entries by magnitude in each row of X

sparse_approximation_rw(X, K)

Keeps only largest K non-zero entries by magnitude in each row of X

Sparse representation matrices (column-wise)

take_along_cols(X, indices)

Picks K entries from each column of X specified by indices matrix

largest_indices_cw(X, K)

Returns the indices of K largest entries by magnitude in each column of X

sparse_approximation_cw(X, K)

Keeps only largest K non-zero entries by magnitude in each column of X

Artificial Noise

awgn_at_snr_ms(key, signal, snr)

Generates noise for the signal at the specified SNR based on signal energy

awgn_at_snr_std(key, signal, snr)

Generates noise for the signal at the specified SNR based on std ratio

Synthetic Signals

pulse

Generates a pulse signal which is 1 between start and end times and 0 everwhere else

transient_sine_wave

Generates a transient sinusoid between start and end times

decaying_sine_wave

Generates a decaying sinusoid :param fs: Sample rate of signal in Hz.

chirp

Generates a frequency sweep from low to high over time.

chirp_centered

Generates a frequency sweep from low to high over time defined by central frequency and bandwidth.

gaussian_pulse

Generates a Gaussian modulated sinusoid

picket_fence

Generates a picket fence signal

heavi_sine

Returns a HeaviSine signal as proposed by Donoho et al. in Wavelab.

bumps

Returns a Bumps signal as proposed by Donoho et al. in Wavelab.

blocks

Returns a Blocks signal as proposed by Donoho et al. in Wavelab.

doppler

Returns a Doppler signal as proposed by Donoho et al. in Wavelab.

ramp

Returns a Ramp signal as proposed by Donoho et al. in Wavelab.

cusp

Returns a Cusp signal as proposed by Donoho et al. in Wavelab.

sing

Returns a Sing signal as proposed by Donoho et al. in Wavelab.

hi_sine

Returns a HiSine signal as proposed by Donoho et al. in Wavelab.

lo_sine

Returns a LoSine signal as proposed by Donoho et al. in Wavelab.

lin_chirp

Returns a LinChirp signal as proposed by Donoho et al. in Wavelab.

two_chirp

Returns a TwoChirp signal as proposed by Donoho et al. in Wavelab.

quad_chirp

Returns a QuadChirp signal as proposed by Donoho et al. in Wavelab.

mish_mash

Returns a MishMash signal as proposed by Donoho et al. in Wavelab.

werner_sorrows

Returns a WernerSorrows signal as proposed by Donoho et al. in Wavelab.

leopold

Returns a Leopold signal as proposed by Donoho et al. in Wavelab.

Discrete Cosine Transform

dct

Computes the 1D Type-II DCT transform

idct

Computes the 1D Type-II Inverse DCT transform

orthonormal_dct

Computes the 1D Type-II DCT transform such that the transform is orthonormal

orthonormal_idct

Computes the 1D Type-II IDCT transform such that the transform is orthonormal

Fast Walsh Hadamard Transform

There is no separate Inverse Fast Walsh Hadamard Transform as FWHT is the inverse of itself except for a normalization factor. In other words, x == fwht(fwht(x)) / n where n is the length of x.

fwht

Computes the Fast Walsh Hadamard Transform over columns

Utilities

time_values

Returns a sequence of time values sampled at a specific frequency for a specific duration