Main Content

fcfwrite

Write file containing filter coefficients

Syntax

fcfwrite(h)
fcfwrite(h,filename)
fcfwrite(...,'fmt')

Description

fcfwrite(h) writes a filter coefficient ASCII file in a folder you choose, or your current MATLAB® working folder. h can be a single filter object or a vector of filter objects. On execution, fcfwrite opens the Export Filter Coefficients to .FCF File dialog box to let you assign a file name for the output file. You can choose the destination folder within this dialog as well.

The default file name is untitled.fcf. When you have DSP System Toolbox™ software, you can use fcfwrite(h) to write filter coefficient files for multirate filters, adaptive filters, and discrete-time filters.

fcfwrite(h,filename) writes the filter coefficients and general information to a text file called filename in your present MATLAB working folder and opens the file in the MATLAB editor for you to review or modify.

If you do not include a file extension in filename, fcfwrite adds the extension fcf to filename.

fcfwrite(...,'fmt') writes the filter coefficients in the format specified by the input argument fmt. Valid fmt values are hex for hexadecimal, dec for decimal, or bin for binary representation of the filter coefficients.

Examples

To demonstrate fcfwrite, create a fixed-point IIR filter at the command line, and then write the filter coefficients to a file named iirfilter.fcf.

d=fdesign.lowpass;
hd=design(d,'butter');
set(hd,'arithmetic','fixed');
fcfwrite(hd,'iirfilter.fcf');

Here is the output from fcfwrite as it appears in the MATLAB editor. Not shown here is the filename — iirfilter.fcf as specified and some comments at the top of the file.

%
%
% Coefficient Format: Decimal
%
% Discrete-Time IIR Filter (real)    
% -------------------------------  
% Filter Structure    : Direct-Form II, Second-Order 
%                          Sections
% Number of Sections  : 13   
% Stable              : Yes    
% Linear Phase        : No   
% Arithmetic          : fixed   
% Numerator           : s16,13 -> [-4 4) 
% Denominator         : s16,14 -> [-2 2)    
% Scale Values        : s16,14 -> [-2 2)  
% Input               : s16,15 -> [-1 1)  
% Section Input       : s16,8 -> [-128 128)   
% Section Output      : s16,10 -> [-32 32) 
% Output              : s16,10 -> [-32 32)  
% State               : s16,15 -> [-1 1)  
% Numerator Prod      : s32,28 -> [-8 8) 
% Denominator Prod    : s32,29 -> [-4 4)  
% Numerator Accum     : s40,28 -> [-2048 2048)  
% Denominator Accum   : s40,29 -> [-1024 1024)
% Round Mode          : convergent  
% Overflow Mode       : wrap    
% Cast Before Sum     : true   
 
  
SOS matrix:    
1  2  1  1  -0.22222900390625  0.88262939453125  
1  2  1  1  -0.19903564453125  0.68621826171875 
1  2  1  1  -0.18060302734375  0.5303955078125  
1  2  1  1  -0.1658935546875   0.40570068359375 
1  2  1  1  -0.154052734375    0.305419921875   
1  2  1  1  -0.14453125        0.22479248046875 
1  2  1  1  -0.136962890625    0.16015625       
1  2  1  1  -0.13092041015625  0.10906982421875 
1  2  1  1  -0.126220703125    0.06939697265625 
1  2  1  1  -0.12274169921875  0.0399169921875  
1  2  1  1  -0.12030029296875  0.01947021484375 
1  2  1  1  -0.118896484375    0.0074462890625  
1  1  0  1  -0.0592041015625   0   
         
Scale Values: 
0.41510009765625     
0.371826171875       
0.33746337890625     
0.3099365234375      
0.287841796875       
0.27008056640625     
0.25579833984375     
0.2445068359375      
0.23577880859375     
0.22930908203125     
0.22479248046875     
0.22216796875        
0.47039794921875     
1       

To write two or more filters out to one file, provide the filters as a vector to fcfwrite:

fcfwrite([hd hd1 hd2])

Version History

Introduced in R2011a