Engee documentation

shiftdata

Shifting data to perform an operation on a given dimension.

Library

EngeeDSP

Syntax

Function call

  • y, perm, nshifts = shiftdata(x, dim) — shifts data x to rearrange the measurement dim in the first column, using the same permutation as the built-in function filter. Argument perm — this is the permutation used by the function.

Use the function shiftdata in combination with the function unshiftdata, which returns the data to its original state. These functions are useful for creating functions that work along a specific dimension, such as filter and sosfilt.

Arguments

Input arguments

# x — input data

+ vector | the matrix

Details

Input data specified as a vector or matrix.

Типы данных

Float32, Float64

# dim — measurement for performing an operation

+ positive scalar

Details

The measurement for performing filtering, specified as a positive integer scalar.

If dim if not specified, the function shifts the first nonunit dimension to the first column and returns the number of shifts in nshifts.

Типы данных

Float32, Float64

Output arguments

# y — data after the shift

+ vector | the matrix

Details

The data after the shift, returned as a vector or matrix.

# perm — permutation

+ vector

Details

The permutation used to shift the data, returned as a vector.

# nshifts — number of shifts

+ scalar

Details

The number of shifts returned as a scalar.

Examples

Rearranging the dimensions of the magic Square

Details

Let’s perform the shifts in the magic square 3×3 by rearranging the second dimension into the first column. Let’s return the matrix to its original position using the function unshiftdata.

Let’s define a magic square 3×3.

import EngeeDSP.Functions: shiftdata
import EngeeDSP.Functions: unshiftdata
x = [2 9 4; 7 5 3; 6 1 8]
3×3 Matrix{Int64}:
 8  1  6
 3  5  7
 4  9  2

Let’s shift the matrix to work along the second dimension. Let’s return the permutation vector, the number of shifts, and the shifted matrix.

x, perm, nshifts = shiftdata(x, 2)
(x = [8 3 4; 1 5 9; 6 7 2], perm = (2, 1), nshifts = Any[])

Let’s restore the matrix to its original state.

y = unshiftdata(x, perm)
3×3 Matrix{Int64}:
 8  1  6
 3  5  7
 4  9  2

Rearranging the array to work with the first non-single dimension

Details

Let’s define the data for the shift as a row vector.

import EngeeDSP.Functions: shiftdata
import EngeeDSP.Functions: unshiftdata
x = [1 2 3 4 5]
1×5 Matrix{Int64}:
 1  2  3  4  5

To move the first data dimension, which is not the only element in the array, to the first column, we will not specify dim. Function shiftdata returns data in the form of a column vector, a vector of permutations, and the number of shifts.

x, perm, nshifts = shiftdata(x)
(x = [1, 2, 3, 4, 5], perm = Any[], nshifts = 1)

Restoring the data to its original state.

y = unshiftdata(x, perm, nshifts)
1×5 Matrix{Int64}:
 1  2  3  4  5