function [ Ew Ex Ey Ez ] = uhj_decode( L, R, T, Q )
    %UHJ_DECODE -- UHJ to E-format ( = B-format decoded from UHJ)
    %
    % decoding equations from
    %   Gerzon, "Ambisonics in Multichannel Broadcasting and Video,"
    %     J. Audio Eng. Soc., Vol. 33(11), Nov. 1985. p. 859
    %   and http://en.wikipedia.org/wiki/Ambisonic_UHJ_format
    
    
    S = (L+R) / 2;
    D = (L-R) / 2;
    
    jS = -imag(hilbert(S));
    jD = -imag(hilbert(D));
    
    switch nargin
        case 2
            Ew = 0.982*S + 0.164*jD;
            Ex = 0.419*S - 0.828*jD;
            Ey = 0.763*D + 0.385*jS;
        case {3,4}
            jT = -imag(hilbert(T));
            Ew = 0.982*S + 0.197*(0.828*jD + 0.768*jT);
            Ex = 0.419*S - 0.828*jD + 0.768*jT;
            Ey = 0.796*D - 0.676*T + 0.187*jS;
            
            if (nargin==4) && (nargout==4)
                Ez = 1.023*Q;
            end
    end
    
end
