Commit 9298048b authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

add missing helper files

parent 8376503e
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
function sh_gains = SH_GainComputation(dirs_deg, max_order)
% Computation of real-valued spherical harmonic coefficients in ACN/orthonormal
% normalization format

num_sh = (max_order+1)^2;
az_rad = dirs_deg(:,1)*pi/180;
coel_rad = pi/2-dirs_deg(:,2)*pi/180;
num_el = length(coel_rad);

% Compute real-valued spherical harmonic coefficients
sh_gains = zeros(num_sh,num_el);
indx = 0;
% l: SH-level (SH-order)
for l = 0:max_order    
    P = legendre(l,cos(coel_rad)).';

    % m: SH-mode
    for m = -l:l
        indx = indx + 1;
        % N3D normalization term
        norm_term = sqrt((2*l+1)*factorial(l-abs(m))/(4*pi*factorial(l+abs(m))));
            
        % trigonometric term
        if m > 0
            trg_term = sqrt(2)*cos(m*az_rad);
        elseif m == 0
            trg_term = 1;
        else
            trg_term = -sqrt(2)*sin(m*az_rad);
        end
        
        % associate Legendre function (with compensation of the Condon-Shortley phase term)
        Pnm = P(:,abs(m)+1)*(-1)^m;
        
        % final direct gain
        sh_gains(indx,:) = norm_term.*Pnm.*trg_term;        
    end 
end

end
 No newline at end of file
+3 −0
Original line number Diff line number Diff line
version https://git-lfs.github.com/spec/v1
oid sha256:386bbd3a02c3b95280fff7bd8f5240ee60f8858889cad0f6147e930f5f2aa7e2
size 1246
+54 −0
Original line number Diff line number Diff line
function writeData3L(fid_source, startstring, data)
indices=size(data);

indent = 4;

fprintf(fid_source,startstring);
fprintf(fid_source,'=\n{');
for A = 1:indices(1)
    fprintf(fid_source,'\n');
    fprintf(fid_source,repmat(' ',1,indent));
    fprintf(fid_source,'{');
    for B = 1:indices(2)
        fprintf(fid_source,'\n');
        fprintf(fid_source,repmat(' ',1,indent*2));  
        fprintf(fid_source,'{');
        if( indices(3) > 10 ) 
            fprintf(fid_source,'\n');
            fprintf(fid_source,repmat(' ',1,indent*3));    
        end
        counter=1;
        for C = 1:indices(3)
            fprintf(fid_source,'%+ff',real(data(A,B,C)));
            if C < indices(3)
                if mod(counter,10) == 0
                    fprintf(fid_source,',');
                else
                    fprintf(fid_source,', ');
                end
            end
            if mod(counter,10) == 0 && counter ~= indices(3)
                fprintf(fid_source,'\n');
                fprintf(fid_source,repmat(' ',1,indent*3));
            end
            counter = counter+1;
        end
        if( indices(3) > 10 ) 
            fprintf(fid_source,'\n');
            fprintf(fid_source,repmat(' ',1,indent*2));
        end
        fprintf(fid_source,'}');
        if B < indices(2)
            fprintf(fid_source,',');
        end
    end
    fprintf(fid_source,'\n');
    fprintf(fid_source,repmat(' ',1,indent));
    fprintf(fid_source,'}');
    if A < indices(1)
        fprintf(fid_source,',');
    end
end
fprintf(fid_source,'\n};\n\n');

end % function
 No newline at end of file