% frameProcessing.m This function adjust length of signal for video analysis

function [ ZI ] = frameProcessing_movingCoh( blockIndex, referenceMic, spsFormat, stepSize, filtRef, bufferSize, nfft, freqWindowing, ...
                                             virtualMicNumber, fullScaleLevel, extX, extY, extXI, extYI, surfpoint, sps32type )
    
    spsChunk                = spsFormat( ( blockIndex-1 ) * stepSize + 1 : ( blockIndex-1 ) * stepSize + bufferSize, : );
    referenceMicChunk       = referenceMic( ( blockIndex-1 ) * stepSize + 1 : ( blockIndex-1 ) * stepSize + bufferSize, : );
    
    transferFunction        = tfestimate( referenceMicChunk, spsChunk, rectwin( nfft/2 ), [], nfft );
    
    if filtRef == 0
        frf                 = fft( spsChunk, nfft, 1 ) / (nfft/2);
    else
        frf                 = fft( referenceMicChunk, nfft, 1 ) / (nfft/2);
        frf                 = repmat( frf, [ 1, 1, virtualMicNumber ] );
        frf                 = permute( frf, [ 1 3 2 ] );
    end
    
    frfhalf                 = frf( 1 : nfft/2 + 1, :, : ) .* transferFunction .* freqWindowing;
    complexSum              = real( frfhalf ).^2 + imag( frfhalf ).^2;
    complexSum              = sum( complexSum, 3 );
    rmsChunk                = ( sum( complexSum, 1, 'omitnan' ) )' ./ 2;
    splChunk                = ( 10 * log10( rmsChunk ) + fullScaleLevel )';
        
    if virtualMicNumber == 122 || ( virtualMicNumber == 32 && sps32type == 1 )
        [ splChunk ]        = extendSPLdir( splChunk );
    end
      
    [ ZI ]                  = splInterpolation( splChunk, virtualMicNumber, extX, extY, extXI, extYI, surfpoint, sps32type );
    
end