image thumbnail
from GUI for DTMF Generator-Decoder using Goertzel's Algorithm by Pranam Janney
GUI for DTMF generator-decoder using Goertzel's algorithm.

cal_k(Num_of_samples,Fs,Fm);
function k = cal_k(Num_of_samples,Fs,Fm);
%
%
%            Function to calculate the DFT Coeff index array
%
%  Author: Pranam Janney           Date: 15/05/04     Time: 17:50          
%  Email: pranamjanney@yahoo.com
%
%  Usage:
%          k = cal_k(Num_of_samples,Fs,Fm);
% Inputs:
%          Num_of_samples = Number of samples
%          Fs = sampling frequency
%          Fm = array of frequencies for which DFT coeff 
%               has to be calculated
% Outputs:
%         k = array of DFT coeff
%
%
len_Fm = length(Fm);
k1(1:len_Fm) = ((Fm(1:len_Fm) * Num_of_samples)/Fs);% for N = 205

%  the K values are fine is "CEIL" except for two "25" and"35" which has to be "FLOOR"   
for i = 1 : len_Fm
    if ( ceil(k1(i)) - k1(i) ) >= 0.5    % if the diff between Ceil and real value 
        k(i) = floor(k1(i));             % is less than 0.5 -> ceil the value
    else                                 %  else floor it 
        k(i) = ceil(k1(i));
    end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Contact us at files@mathworks.com