%% Determine the Section and Output Word Lengths and Fraction Lengths
% Using the getFixedPointInfo function, you can determine the word lengths and fraction lengths of the fixed-point sections and the output of the dsp.CICDecimator and dsp.CICInterpolator System objects. The data types of the filter sections and the output depend on the FixedPointDataType property of the filter System object™.
%
%% Full precision
% Create a dsp.CICDecimator object. The default value of the NumSections property is 2. This value indicates that there are two integrator and comb sections. The WLs and FLs vectors returned by the getFixedPointInfo function contain five elements each. The first two elements represent the two integrator sections. The third and fourth elements represent the two comb sections. The last element represents the filter output.

cicD = dsp.CICDecimator

% By default, the FixedPointDataType property of the object is set to 'Full precision'. Calling the getFixedPointInfo function on this object with the input numeric type, nt, yields the following word length and fraction length vectors.

nt = numerictype(1,16,15)
[WLs,FLs] = getFixedPointInfo(cicD,nt) %#ok

% For details on how the word lengths and fraction lengths are computed, see the description for Output Arguments.
% If you lock the cicD object by passing an input to its algorithm, you do not need to pass the nt argument to the getFixedPointInfo function.

input = int64(randn(8,1))
output = cicD(input)
[WLs,FLs] = getFixedPointInfo(cicD) %#ok

% The output and section word lengths are the sum of input word length, 64 in this case, and the number of sections, 2. The output and section fraction lengths are 0 since the input is a built-in integer.
%
%% Minimum section word lengths
% Release the object and change the FixedPointDataType property to 'Minimum section word lengths'. Determine the section and output fixed-point information when the input is fixed-point data, fi(randn(8,2),1,24,15).

release(cicD);
cicD.FixedPointDataType = 'Minimum section word lengths'
inputF = fi(randn(8,2),1,24,15)
[WLs, FLs] = getFixedPointInfo(cicD,numerictype(inputF)) %#ok

%
%% Specify word and fraction lengths
% Change the FixedPointDataType property to 'Specify word and fraction lengths'. Determine the fixed-point information using the getFixedPointInfo function.

cicD.FixedPointDataType = 'Specify word and fraction lengths'
[WLs, FLs] = getFixedPointInfo(cicD,numerictype(inputF)) %#ok

% The section and output word lengths and fraction lengths are assigned as per the respective fixed-point properties of the cicD object. These values are not determined by the input numeric type. To confirm, call the getFixedPointInfo function without passing the numerictype input argument.

[WLs, FLs] = getFixedPointInfo(cicD) %#ok

%
%% Specify word lengths
% To specify the word lengths of the filter section and output, set the FixedPointDataType property to 'Specify word lengths'.

cicD.FixedPointDataType = 'Specify word lengths'

% The getFixedPointInfo function requires the input numeric type because that information is used to compute the section and word fraction lengths.

[WLs, FLs] = getFixedPointInfo(cicD,numerictype(inputF))

% For more details on how the function computes the word and fraction lengths, see the description for Output Arguments.
% Copyright 2012 The MathWorks, Inc.