Goertzel Algorithm for calculating amplitude and angle
8 views (last 30 days)
Show older comments
Ismoil Odinaev
on 11 Apr 2021
Commented: Ismoil Odinaev
on 12 Apr 2021
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;
0 Comments
Accepted Answer
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.
More Answers (0)
See Also
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!