Main Content

2-D DCT

Compute 2-D discrete cosine transform (DCT)

  • 2-D DCT block

Libraries:
Computer Vision Toolbox / Transforms

Description

The 2-D DCT block calculates the two-dimensional discrete cosine transform of an image. Suppose f(x,y) is the input image of dimension M-by-N, the equation for the 2-D DCT is

F(m,n)=2MNC(m)C(n)x=0M1y=0N1f(x,y)cos(2x+1)mπ2Mcos(2y+1)nπ2N

where C(m)=C(n)=1/2 for m,n=0 and C(m),C(n)=1 otherwise.

The number of rows and columns of the input image must be power of 2. You can also use this block to compute 1-D DCT of a vector.

Examples

Ports

Input

expand all

Input data, specified as a numeric matrix or a vector. The size of the input data must be power of 2.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point

Output

expand all

Output data containing the DCT coefficients, returned as a matrix or vector. The size and the datatype of the output is same as that of the input.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point

Parameters

expand all

Main Tab

Use this parameter to specify how the block computes the sine and cosine terms in the DCT algorithm.

  • If you select Trigonometric fcn, the block computes the sine and cosine values during the simulation.

  • If you select Table lookup, the block computes and stores the trigonometric values before the simulation starts. In this case, the block requires extra memory. Table lookup is the default.

Data Types Tab

Fixed-point operational parameters

Use this parameter to specify the rounding mode for the block to use when the specified data type and scaling cannot exactly represent the result of a fixed-point calculation. See Rounding Modes for more information on the available values.

Note

The sine table values do not obey this parameter; they always round to Nearest.

When you select this parameter, the block saturates the result of its fixed-point operation. When you clear this parameter, the block wraps the result of its fixed-point operation.

For details on saturate and wrap, see Overflow Handling for fixed-point operations.

Note

The sine table values do not obey this parameter; instead, they are always saturated.

Fixed-point data types

Use this parameter to specify the word length of the values of the sine table. The fraction length of the sine table values always equals the word length minus one.

The sine table values do not obey the Rounding mode and Saturate on integer overflow parameters; instead, they are always saturated and rounded to Nearest.

Use this parameter to specify the product output data type. See Fixed-Point Data Types and Multiplication Data Types for illustrations depicting the use of the product output data type in this block.

Use this parameter to specify the accumulator data type. See Fixed-Point Data Types for illustrations depicting the use of the accumulator data type in this block.

Use this parameter to specify the output data type. See Fixed-Point Data Types for illustrations depicting the use of the output data type in this block. When you set this parameter to

  • Inherit: Inherit via internal rule, the block calculates the output word length and fraction length automatically. The internal rule first calculates an ideal output word length and fraction length using the following equations:

    WLideal output=WLinput+floor(log2(DCT length1))+1

    FLideal output=FLinput

    Using these ideal results, the internal rule then selects word lengths and fraction lengths that are appropriate for your hardware. For more information, see Specify Fixed-Point Attributes for Blocks (DSP System Toolbox).

Select this parameter to prevent the fixed-point tools from overriding the data types you specify on the block mask. For more information, see fxptdlg (Fixed-Point Designer), a reference page on the Fixed-Point Tool.

Block Characteristics

Data Types

double | fixed point | integer | single

Multidimensional Signals

no

Variable-Size Signals

no

More About

expand all

References

[1] Chen, W.H, C.H. Smith, and S.C. Fralick, “A fast computational algorithm for the discrete cosine transform,” IEEE Trans. Communications, 25 (1977): 1004-1009.

[2] Wang, Z. “Fast algorithms for the discrete W transform and for the discrete Fourier transform,” IEEE Trans. Acoust., Speech, Signal Processing, 32 (August 1984): 803-816.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced before R2006a

See Also

Blocks

Functions