Goertzel Algorithm for calculating amplitude and angle

7 views (last 30 days)
Hello everybody!
I have written a script that describes Goertzel Algorithm. The script is given below. The algorithm calculates correct real part but incorrect imaginary part of original signal. So how to receive the correct imaginary part?
Sampling frequency (N) & nominal frequency (f) with simulation interval (t) are given as:
N = 80; % points/period
f = 50; % Hz
t = 0.02; % s
Time array is:
TimeArray = 0:1/f/N:t;
Original signal array is equal:
x = cos(2*pi*f*TimeArray);
The first part of Goertzel Algorithm is given below.
% W - z^-1
% H(z) = ---------------------------
% 1 - alpha * z^-1 + z^-2
%
% W = W_N^(-k) = exp(2i*pi*k/N).
% alpha = 2*cos(2*pi*k/N).
k = 50; % Spectral sample number
om = 2*pi*k/N;
w = exp(-1i*om);
%alpha
alpha = 2*cos(om);
s1 = 0; s2 = 0;
for h7 = 1:length(x)
s0 = alpha * s1 - s2 + x (h7);
s2 = s1;
s1 = s0;
end
The second part of Goertzel Algorithm is Xk. Xk is the algorithm output. Here Xk gives out complex number. However Xk gives me correct real and incorrect imaginary of complex number.
Xk = s1 - w * s2;

Accepted Answer

Alan Stevens
Alan Stevens on 11 Apr 2021
Should it be more like this
N = 80; % points/period
f = 50; % Hz
t = 0.02; % s
TimeArray = 0:1/f/N:t;
x = 2*cos(2*pi*f*TimeArray);
% W - z^-1
% H(z) = ---------------------------
% 1 - alpha * z^-1 + z^-2
%
% W = W_N^(-k) = exp(2i*pi*k/N).
% alpha = 2*cos(2*pi*k/N).
k = 50; % Spectral sample number
om = 2*pi*k/N;
w = exp(-1i*om);
%alpha
alpha = 2*cos(om);
s(1) = 0; s(2) = 0;
for h7 = 3:length(x)
s(h7) = x(h7) + alpha*s(h7-1) - s(h7-2);
end
Xk = s(2:end) - w * s(1:end-1);
disp(Xk)
Your value of om is larger than pi, which means you might have aliasing according to the Wikipedia article.
  2 Comments
Ismoil Odinaev
Ismoil Odinaev on 11 Apr 2021
The difference between DFT and Goertzel algorithm is that the second one doesn't need to do many complex multiplications by exp(j*2*pi*k/N) for every sample of original signal, and instead operates with real numbers.
Ismoil Odinaev
Ismoil Odinaev on 12 Apr 2021
"Your value of om is larger than pi, which means you might have aliasing according to the Wikipedia article" i think it is because of my k is incorrect. It should be not 50 but 1. Thank you!

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB Mobile 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!