Created
July 11, 2016 12:19
-
-
Save eickenberg/8e27c758511841022b801cef333ed284 to your computer and use it in GitHub Desktop.
Code for periodizing a signal in Fourier (corresponds to subsampling in signal space)
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
# Code for periodizing a signal in Fourier (corresponds to subsampling in signal space) | |
def periodize_1d(array, axis, downsampling): | |
axis_shape = array.shape[axis] | |
before_shape = array.shape[:axis] | |
after_shape = array.shape[axis + 1:] | |
new_shape = before_shape + (downsampling, -1) + after_shape | |
return array.reshape(new_shape).mean(axis) | |
def periodize(array, axes, stride): | |
axes = tuple(np.atleast_1d(axes)) | |
downsampling = tuple(np.atleast_1d(stride)) | |
if len(downsampling) == 1: | |
downsampling = downsampling * len(axes) | |
for axis, ds in zip(axes, downsampling): | |
array = periodize_1d(array, axis, ds) | |
return array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment