You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: my_srp_phat003.m
    path of file: ./repos/Microphone-sound-source-localization
    
    the code of the file until where you have to start completion: function y = my_srp_phat003(gcc_all, mic, v, fs)
% 本函数也是搜索法确定声源位置的测试，区别在于选用了球坐标
% 本函数用来实现声源定位
% 输入：GCC-PHAT矩阵，麦克风位置，声速，采样率
% 输出：声源位置
% 说明：这里主要使用直角坐标搜索+SRP-PHAT方法
% 给定搜索界限，绘图，并输出迭代界限
% 改变为极坐标


    
function y = my_srp_phat003(gcc_all, mic, v, fs)
% 本函数也是搜索法确定声源位置的测试，区别在于选用了球坐标
% 本函数用来实现声源定位
% 输入：GCC-PHAT矩阵，麦克风位置，声速，采样率
% 输出：声源位置
% 说明：这里主要使用直角坐标搜索+SRP-PHAT方法
% 给定搜索界限，绘图，并输出迭代界限
% 改变为极坐标

% --------------------------------------------------------------
% 搜索初始化
energycac = 0; % 用于判决的阈值
frameLen = (size(gcc_all,2)+1)/2;
plotcac = []; % 用来缓存矩阵

% --------------------------------------------------------------
% 三重循环进行搜索
for r = 0.1:1:10.1                                 % 极径，分辨率为1，注意最好别从零开始
    for theta = 60*(pi/180):5*(pi/180):90*(pi/180) % 俯仰角，分辨率为2
        for phi = 0:5*(pi/180):90*(pi/180)         % 方位角，分辨率为2
            % 转换为直角坐标
            kx = r*sin(theta)*cos(phi);
            ky = r*sin(theta)*sin(phi);
            kz = r*cos(theta);
            obj = [kx,ky,kz]; % 目标位置
            % 计算距离差
            discac = abs(obj-mic(1,:));
            distance1 = sqrt(sum(discac.^2)); % 目标到1号麦克风距离
            discac = abs(obj-mic(2,:));
            distance2 = sqrt(sum(discac.^2)); % 目标到2号麦克风距离
            discac = abs(obj-mic(3,:));
            distance3 = sqrt(sum(discac.^2)); % 目标到3号麦克风距离
            discac = abs(obj-mic(4,:));
            distance4 = sqrt(sum(discac.^2)); % 目标到4号麦克风距离 
            % 计算时延点数矩阵
            delaycac = [2*(distance1-distance2)/v*fs;
                        2*(distance1-distance3)/v*fs;
                        2*(distance1-distance4)/v*fs;
                        2*(distance2-distance3)/v*fs;
                        2*(distance2-distance4)/v*fs;
                        2*(distance3-distance4)/v*fs
                       ];
            % 进行sinc加权计算SRP
            energy_xx_cac = zeros(1,6);
            for zz = 1:6
                index = frameLen+floor(delaycac(zz))+(-3:4);
                energy_xx_cac(zz) = my_sinc(gcc_all(zz,index),index,frameLen+delaycac(zz));
            end