[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Does Octave contain Fast-Fourier Transforms built in?
From: |
Francesco Potorti` |
Subject: |
Does Octave contain Fast-Fourier Transforms built in? |
Date: |
Thu, 08 Feb 1996 16:08 +0100 (MET) |
I wrote some functions for that purpose:
----------- spectre.m ---------------
function A = spectre(x, n)
# Given a vector X, compute its one-sided power spectre in N points plus
# the null frequency by repeatedly applying the fft to overlapping chunks of
# 2*N points.
# Faster if N is a power of 2. The variance of each element in the computed
# vector is approximately equal to avg*N/length(X), where avg is the
# element's average. Gives a vector of length N+1.
if (length(x) < 2*n)
x = postpad (x, 2*n);
endif
A = 0;
iterations = max (1, floor(length(x)/n)-1);
for i = 0:iterations-1
a = fft (x(i*n+1:(i+2)*n));
A = A + abs(a(1:n+1)).^2;
A = A + abs(flipud(fliplr(postpad(a(n+1:2*n), n+1)))).^2;
endfor
A = A / n^2;
endfunction
---------------- autocov.m --------------------
function A = autocov(x)
# Given a vector X, computes a vector of the same shape, whose length
# is one less than the argument, representing the autocovariance of X.
A = x - mean(x);
A = fftconv(A, fliplr(flipud(A)));
A = A(length(x) : 2*length(x)-1);
A = A / length(x);
endfunction
---------------------- autocorr.m --------------------
function A = autocorr(x)
# Given a vector X, computes a vector of the same shape, whose length
# is one less than the argument, representing the autocorrelation of X.
# The autocorrelation is simply the normalised autocovariance.
A = autocov(x);
A = A / A(1);
endfunction