我想实现快速余弦变换。我在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。声学。语音信号。过程。28 (1), 27-34 (1980)。