-# some decompositions that can accelerate the calculations by several orders
-# of magnitude...
-
-
-# The Lee algorithm splits a DCT calculation of size N into two DCT
-# calculations of size N/2
-
-def unscaled_DCT_Lee (N, input, output):
- even_input = vector(N/2)
- odd_input = vector(N/2)
- even_output = vector(N/2)
- odd_output = vector(N/2)
-
- for i in range(N/2):
- even_input[i] = input[i] + input[N-1-i]
- odd_input[i] = input[i] - input[N-1-i]
-
- for i in range(N/2):
- odd_input[i] = odd_input[i] * (0.5 / cos (((2*i+1)*pi)/(2*N)))
-
- unscaled_DCT (N/2, even_input, even_output)
- unscaled_DCT (N/2, odd_input, odd_output)
-
- for i in range(N/2-1):
- odd_output[i] = odd_output[i] + odd_output[i+1]
-
- for i in range(N/2):
- output[2*i] = even_output[i]
- output[2*i+1] = odd_output[i];
-
-# Notes about this algorithm :
-
-# The algorithm can be easily inverted to calculate the IDCT instead :
-# each of the basic stages are separately inversible...
-
-# This function does N adds, then N/2 muls, then 2 recursive calls with
-# size N/2, then N/2-1 adds again. The total number of operations will be
-# N*log2(N)/2 multiplies and less than 3*N*log2(N)/2 additions.
-# (exactly N*(3*log2(N)/2-1) + 1 additions). So this is much
-# faster than the canonical algorithm.
-
-# Some of the multiplication coefficient, 0.5/cos(...) can get quite large.
-# This means that a small error in the input will give a large error on the
-# output... For a DCT of size N the biggest coefficient will be at i=N/2-1
-# and it will be slighly more than N/pi which can be large for large N's.
-
-# In the IDCT however, the multiplication coefficients for the reverse
-# transformation are of the form 2*cos(...) so they can not get big and there
-# is no accuracy problem.
-
-# You can find another description of this algorithm at
-# http://www.intel.com/drg/mmx/appnotes/ap533.htm
-
-
-# The AAN algorithm uses another approach, transforming a DCT calculation into
-# a DFT calculation of size 2N:
-
-def unscaled_DCT_AAN (N, input, output):
- DFT_input = vector (2*N)
- DFT_output = vector (2*N)
-
- for i in range(N):
- DFT_input[i] = input[i]
- DFT_input[2*N-1-i] = input[i]
-
- unscaled_DFT (2*N, DFT_input, DFT_output)
-
- for i in range(N):
- output[i] = DFT_output[i].real * (0.5 / cos ((i*pi)/(2*N)))
-
-# Notes about the AAN algorithm :
-
-# The cost of this function is N real multiplies and a DFT of size 2*N. The
-# DFT to calculate has special properties : the inputs are real and symmetric.
-# Also, we only need to calculate the real parts of the N first DFT outputs.
-# We will see how we can take advantage of that later.
-
-# We can invert this algorithm to calculate the IDCT. The final multiply
-# stage is trivially invertible. The DFT stage is invertible too, but we have
-# to take into account the special properties of this particular DFT for that.
-
-# Once again we have to take care of numerical precision for the DFT : the
-# output coefficients can get large, so that a small error in the input will
-# give a large error on the output... For a DCT of size N the biggest
-# coefficient will be at i=N/2-1 and it will be slightly more than N/pi
-
-# You can find another description of this algorithm at this url :
-# www.cmlab.csie.ntu.edu.tw/cml/dsp/training/coding/transform/fastdct.html
-
-
-# The DFT calculation can be decomposed into smaller DFT calculations just like
-# the Lee algorithm does for DCT calculations. This is a well known and studied
-# problem. One of the available explanations of this process is at this url :