我想实现快速余弦变换。我在Wikipedia上读到,有一个DCT的快速版本,其计算方法与FFT类似。我尝试阅读引用的Makhoul *论文,了解Scipy中也使用的FTPACK和FFTW实现,但是我无法提取实际的算法。这是我到目前为止所拥有的:
FFT代码:
def fft(x):
if x.size ==1:
return x
N = x.size
x0 = my_fft(x[0:N:2])
x1 = my_fft(x[0+1:N:2])
k = numpy.arange(N/2)
e = numpy.exp(-2j*numpy.pi*k/N)
l = x0 + x1 * e
r = x0 - x1 * e
return numpy.hstack([l,r])
DCT代码:
def dct(x):
k = 0
N = x.size
xk = numpy.zeros(N)
for k in range(N):
for n in range(N):
xn = x[n]
xk[k] += xn*numpy.cos(numpy.pi/N*(n+1/2.0)*k)
return xk
FCT试用:
def my_fct(x):
if x.size ==1:
return x
N = x.size
x0 = my_fct(x[0:N:2]) # have to be set to zero?
x1 = my_fct(x[0+1:N:2])
k = numpy.arange(N/2)
n = # ???
c = numpy.cos(numpy.pi/N*(n+1/2.0)*k)
l = x0 #???
r = x0 #???
return numpy.hstack([l,r])
* J。Makhoul,“一维和二维快速余弦变换”,IEEE Trans。co 语音信号 程序 28(1),27-34(1980)。