Ask about goertzel function m file download

2 views (last 30 days)
MU
MU on 20 Feb 2013
Actually, i want to find the m file of goertzel function in matlab but i do not find it on the website, so does anyone have this function file? Please send it to my email, thanks a lot here is my email, fengfankk@126.com

Answers (1)

Youssef  Khmou
Youssef Khmou on 20 Feb 2013
hi, try this :
function [power] = Goertzel(x,Fg,Fs,N)
% Goertzel algorithm
%
% The Goertzel algorithm searches the input signal x for a specific
% predetermined frequency Fg.
%
% Parameters:
%
% x - Input vector
% Fg - Goertzel test frequency
% Fs - Sample frequenzy
% N - Number of samples used to calculate power
%
% power - Goertzel power of the input vector
%
% Initialize vectors
power = zeros(1,N);
% Initialize coefficients
w_hat = 2*pi*Fg/Fs;
a1 = 2*cos(w_hat);
a2 = -1;
b0 = 1;
b1_re = -cos(w_hat);
b1_im = sin(w_hat);
% Initialize delayline
x1 = 0;
x2 = 0;
% Calculate Goertzel power
for n = 1:N
xi = x(n); % Newest sample
x0 = xi + a1*x1 + a2*x2; % Calculate filter
y_re = b0*x0 + b1_re*x1;
y_im = b1_im*x1;
% Opdater delayline
x2 = x1;
x1 = x0;
power(n) = y_re^2 + y_im^2;
end

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!