-
-
Notifications
You must be signed in to change notification settings - Fork 782
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8022 from takagi/cusignal-pulse_compression
Add `cupyx.signal.pulse_compression` from cuSignal's non SciPy-compat API
- Loading branch information
Showing
7 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from cupyx.signal.radartools import pulse_compression # NOQA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from cupyx.signal.radartools._radartools import pulse_compression # NOQA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
""" | ||
Some of the functions defined here were ported directly from CuSignal under | ||
terms of the MIT license, under the following notice: | ||
Copyright (c) 2019-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. | ||
""" | ||
|
||
import cupy as cp | ||
from cupyx.scipy.signal import windows | ||
|
||
|
||
def pulse_compression(x, template, normalize=False, window=None, nfft=None): | ||
""" | ||
Pulse Compression is used to increase the range resolution and SNR | ||
by performing matched filtering of the transmitted pulse (template) | ||
with the received signal (x) | ||
Parameters | ||
---------- | ||
x : ndarray | ||
Received signal, assume 2D array with [num_pulses, sample_per_pulse] | ||
template : ndarray | ||
Transmitted signal, assume 1D array | ||
normalize : bool | ||
Normalize transmitted signal | ||
window : array_like, callable, string, float, or tuple, optional | ||
Specifies the window applied to the signal in the Fourier | ||
domain. | ||
nfft : int, size of FFT for pulse compression. Default is number of | ||
samples per pulse | ||
Returns | ||
------- | ||
compressedIQ : ndarray | ||
Pulse compressed output | ||
""" | ||
[num_pulses, samples_per_pulse] = x.shape | ||
|
||
if nfft is None: | ||
nfft = samples_per_pulse | ||
|
||
if window is not None: | ||
Nx = len(template) | ||
if callable(window): | ||
W = window(cp.fft.fftfreq(Nx)) | ||
elif isinstance(window, cp.ndarray): | ||
if window.shape != (Nx,): | ||
raise ValueError("window must have the same length as data") | ||
W = window | ||
else: | ||
W = windows.get_window(window, Nx, False) | ||
|
||
template = cp.multiply(template, W) | ||
|
||
if normalize is True: | ||
template = cp.divide(template, cp.linalg.norm(template)) | ||
|
||
fft_x = cp.fft.fft(x, nfft) | ||
fft_template = cp.conj( | ||
cp.tile(cp.fft.fft(template, nfft), (num_pulses, 1))) | ||
compressedIQ = cp.fft.ifft(cp.multiply(fft_x, fft_template), nfft) | ||
|
||
return compressedIQ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
21 changes: 21 additions & 0 deletions
21
tests/cupyx_tests/signal_tests/radartools_tests/test_radartools.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import pytest | ||
|
||
import cupy | ||
from cupyx import signal | ||
|
||
|
||
class TestPulseCompression: | ||
|
||
@pytest.mark.parametrize('dtype', [cupy.float32, cupy.float64]) | ||
def test_pulse_compression(self, dtype): | ||
num_pulses = 128 | ||
num_samples_per_pulse = 9000 | ||
template_length = 1000 | ||
|
||
shape = num_pulses, num_samples_per_pulse | ||
x = cupy.random.randn(*shape, dtype=dtype) + \ | ||
1j * cupy.random.rand(*shape, dtype=dtype) | ||
template = cupy.random.randn(template_length, dtype=dtype) + \ | ||
1j * cupy.random.randn(template_length, dtype=dtype) | ||
|
||
signal.pulse_compression(x, template, normalize=True, window='hamming') |