Signal Processing Toolbox 
Compute the DFT using the secondorder Goertzel algorithm
Syntax
Description
goertzel
computes the discrete Fourier transform (DFT) of specific indices in a vector or matrix.
y = goertzel(x,i)
returns the DFT of vector x
at the indices in vector i,
computed using the secondorder Goertzel algorithm. If x
is a matrix, goertzel
computes each column separately. The indices in vector i
must be integer values from 1 to N, where N is the length of the first matrix dimension of x
that is greater than 1. The resulting y
has the same dimensions as x
. If i
is omitted, it is assumed to be [1:N], which results in a full DFT computation.
y = goertzel(x,i,dim)
returns the discrete Fourier transform (DFT) of matrix x
at the indices in vector i,
computed along the dimension dim
of x
.
Note
fft computes all DFT values at all indices, while goertzel computes DFT values at a specified subset of indices (i.e., a portion of the signal's frequency range). If less than log_{2}(N) points are required, goertzel is more efficient than the Fast Fourier Transform (fft ).

Two examples where goertzel
can be useful are spectral analysis of very large signals and dualtone multifrequency (DTMF) signal detection.
Examples
Generate an 8Hz sinusoid and use the Goertzel algorithm to detect it using the first 20 indices:
Fs = 1024; Ts = 1/Fs; f = 8; N = 1024; t = Ts*(0:N1)'; x = sin(2*pi*f*t); % Generate 8 Hz sinusoid figure(1); plot(t,x); figure(2); periodogram(x,[],[],Fs);
% Use periodogram to obtain the PSD
% (computed with all N points of signal) vec = 1:20; X = goertzel(x,vec);
% Now use Goertzel to obtain the PSD figure(3);
% only in the region of interest plot(vec1,20*log10(abs(X)));
Algorithm
goertzel
implements this transfer function
where N is the length of the signal and k is the index of the computed DFT. k is related to the indices in vector i
above as k = i
 1.
The signal flow graph for this transfer function is
To compute X[k] for a particular k, the Goertzel algorithm requires 4N real multiplications and 4N real additions. Although this is less efficient than computing the DFT by the direct method, Goertzel uses recursion to compute
which are evaluated only at n = N. The direct DFT does not use recursion and must compute each complex term separately.
See Also
References
[1] Burrus, C.S. and T.W. Parks. DFT/FFT and Convolution Algorithms. John Wiley & Sons, 1985, pp. 3226.
[2] Mitra, Sanjit K. Digital Signal Processing: A ComputerBased Approach. New York, NY: McGrawHill, 1998, pp. 520523.
gmonopuls  grpdelay 