%% Explore Latency of HDL FIR Decimation Object
% The latency of the dsp.HDLFIRDecimation System object™ varies with filter architecture and input vector size. Use the getLatency function to find the latency of a particular configuration. The latency is the number of cycles between the first valid input and the first valid output.
% Create a dsp.HDLFIRDecimation System object™ and request the latency. The default filter is a direct-form systolic architecture. The default data type for the coefficients is 'Same word length as input'. Therefore, when you call the getLatency object function, you must specify an input data type. The default filter has 36 coefficients. This example assumes the data input to your filter is complex-valued. The default coefficients are real-valued. Complexity affects filter latency only when you have complex-valued data and complex-valued coefficients.

inputType = numerictype(1,16,15); % object uses only the word length for coefficient type cast
complexInput = true;
downBy4 = dsp.HDLFIRDecimation('DecimationFactor',4);
L_by4scalar = getLatency(downBy4,inputType,complexInput)

% Check the latency for the same filter with vector input.

vectorSize = 2;
L_by4Vec2 = getLatency(downBy4,inputType,complexInput,vectorSize)

% Check the latency of a transposed architecture.

downBy4.FilterStructure = 'Direct form transposed';
L_by4trans = getLatency(downBy4,inputType,complexInput)

% Check the latency for the transposed filter with vector input.

vectorSize = 4;
L_by4transVec4 = getLatency(downBy4,inputType,complexInput,vectorSize)

% Copyright 2020 The MathWorks, Inc.