Implement a function that calculates 1D Discrete Cosine Transform (DCT-II) for each row of a given input matrix so that the outputs are in columns.
For example:
Input:
[1 0 0 0]
Gives:
mydct([1 0 0 0])
ans =
0.5
0.65328
0.5
0.2706
Solution Stats
Problem Comments
1 Comment
Solution Comments
Show comments
Loading...
Problem Recent Solvers21
Suggested Problems
-
Replace NaNs with the number that appears to its left in the row.
3062 Solvers
-
344 Solvers
-
What is the distance from point P(x,y) to the line Ax + By + C = 0?
554 Solvers
-
Map all the indices of an Array Indices into a Vector giving Index vs Row and Column
47 Solvers
-
Who is the smartest MATLAB programmer?
789 Solvers
More from this Author4
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
A fair warning to the challenger: the requested DCT-II is the orthogonal version, which means it needs to be multiplied by sqrt(2/N) where N is the size of the row, and the first element of the DCT x0 needs to be multiplied by 1/sqrt(2). It took me a while to understand. Wikipedia's formula is almost right, but it is missing those terms, which are mentioned only further below. Look at MATLAB's documentation (DCT-2), https://www.mathworks.com/help/signal/ref/dct.html, to find the proper formula.