Main Content

digitrevorder

Permute input into digit-reversed order

Description

y = digitrevorder(x,r) returns the input data x in digit-reversed order. The digit-reversal is computed using the number system base (radix base) r.

example

[y,i] = digitrevorder(x,r) returns the digit-reversed input data and digit-reversed indices, such that y = x(i).

Examples

collapse all

Obtain the digit-reversed, radix base-3 ordered output of a vector containing 9 values. Obtain the same result by converting to base 3 and reversing the digits.

x = (0:8)';

y = digitrevorder(x,3);

c1 = dec2base(x,3);
c2 = fliplr(c1);
c3 = base2dec(c2,3);

T = table(x,y,c1,c2,c3)
T=9×5 table
    x    y    c1    c2    c3
    _    _    __    __    __

    0    0    00    00    0 
    1    3    01    10    3 
    2    6    02    20    6 
    3    1    10    01    1 
    4    4    11    11    4 
    5    7    12    21    7 
    6    2    20    02    2 
    7    5    21    12    5 
    8    8    22    22    8 

Input Arguments

collapse all

Input data, specified as a vector or matrix. The length of x must be an integer power of r. If x is a matrix, the digit reversal occurs on the first dimension of x with size greater than 1.

Radix base, specified as an integer in the range [2, 36].

Output Arguments

collapse all

Digit-reversed data, returned as a vector or matrix. y is the same size as x.

Digit-reversed indices, returned as a vector or matrix.

Note

MATLAB® matrices use 1-based indexing, so the first index of y will be 1, not 0.

More About

collapse all

Tips

  • The digitrevorder function is useful for pre-ordering a vector of filter coefficients for use in frequency-domain filtering algorithms, in which the fft and ifft transforms are computed without digit-reversed ordering for improved run-time efficiency.

Extended Capabilities

expand all

Version History

Introduced before R2006a

See Also

| |