主要内容

shiftdata

Shift fi data to operate on specified dimension

Description

[y,perm,nshifts] = shiftdata(x,dim) shifts data in fi object x to permute dimension dim to the first column using the same permutation as the built-in filter function. perm is the permutation vector that the function uses.

Note

Use the shiftdata function in tandem with the unshiftdata function, which shifts the data back to its original shape. These functions are useful for creating functions that work along a certain dimension, like filter, goertzel, sgolayfilt, and sosfilt.

Note

To shift floating-point data, use the shiftdata (Signal Processing Toolbox) and unshiftdata (Signal Processing Toolbox) functions.

example

Examples

collapse all

This example shows how to shift a 3-by-3 magic square, permuting the second dimension to the first column. Then shift the matrix back to its original shape.

Create a 3-by-3 magic square. The default fi object creates a signed fixed-point value with a word length of 16 bits and fraction length of 11 bits.

x = fi(magic(3))
x = 
     8     1     6
     3     5     7
     4     9     2

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 11

Shift the matrix to work along the second dimension. 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

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 11
perm = 1×2

     2     1

nshifts =

     []

Restore the matrix back to its original shape.

y = unshiftdata(x,perm,nshifts)
y = 
     8     1     6
     3     5     7
     4     9     2

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 11

Define the fised-point data to shift as a row vector.

x = fi(1:5)
x = 
     1     2     3     4     5

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 12

Define dim as empty to shift the first nonsingleton dimension of the data to the first column. The shiftdata function returns the data as a column vector, the permutation vector, and the number of shifts.

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

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 12
perm =

     []
nshifts = 
1

Restore the shifted data to its original shape.

y = unshiftdata(x,perm,nshifts)
y = 
     1     2     3     4     5

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 12

Input Arguments

collapse all

Data, specified as a vector or matrix.

Data Types: fi

Dimension to operate along, specified as a positive integer or []. If dim is missing or empty, [], then the function shifts the first nonsingleton dimension to the first column and returns the number of shifts in nshifts.

Output Arguments

collapse all

Shifted data, returned as a vector or matrix.

Permutation used to shift the data, returned as a vector.

Number of shifts, returned as a scalar.

Version History

Introduced in R2008a

See Also