goertzel.m and discrete Fourier transforms
2 views (last 30 days)
Show older comments
My question is whether the error messages on lines 75 through 81 of Matlab's implementation of the Goertzel algorithm are necessary.
It is my understanding that they are intended to keep the frequencies within the bounds of [0 2*pi] (for the first two) and as integer values with respect to the data length (for the last one).
For the first concern, frequencies outside of the [0 siz(1)) range can just be modulated to the equivalent frequency within [0 siz(1)). For the second, it takes a small modification of the algorithm to allow for frequencies that correspond to non-integers in the DFT. Multiplying the output of goertzelmex by exp(-2i*pi*INDVEC) yields the correct DFT output (note that this factor simplifies to 1 in the case that INDVEC is populated by all integer values).
The "if" statement corresponding to the integer error is not even correctly posed if we are trying to avoid non-integers, as the error occurs only if all of the indices are non-integer. Replacing lines 70 through 90 with the following would allow users to get non-integer frequencies, negative frequencies, etc.:
if isempty(INDVEC),
Y = fft(X,[],1);
else
% guarantee frequencies are within 0:siz(1)
INDVEC = mod(INDVEC,siz(1));
% Initialize Y with the correct dimension
Y = zeros([length(INDVEC),siz(2:end)]);
% Call goertzelmex
for k = 1:prod(siz(2:end)),
Y(:,k) = goertzelmex(X(:,k),INDVEC).*exp(-2i*pi*INDVEC);
end
end
0 Comments
Answers (0)
See Also
Categories
Find more on Transforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!