How to have access to the fcfwrite function?

Hello,
I have designed a bandpass filter using the designfilt function and it works as expected. The only annoyance is that it takes around 10 minutes to generate the coefficients on my machine. The result is stored on a persistent variable so that subsequent executions don't have this problem.
I was thinking about saving the filter to a file using the fcfwrite function, as documented here. However, my matlab install simply does not provide this command. I have the DSP toolbox installed, and the fcfileread command is available.
It seems like I'm the first person on the open web to have this issue. I'm running Matlab R2026a on Fedora 44. For now the workaround seems to be storing it on a binary file containing only the coefficients, not nearly as convenient as the built-in function.

2 Comments

designfilt takes 10 minutes to run? Or is designfilt just one step in an algorithm and the algorithm takes 10 minutes to run?
It's a pretty narrow and selective bandpass filter, so probably overkill. The final filter has 6000 coefficients and runs fast enough for my application and the output signal seems to be as intended. When plugged in it takes maybe 6 minutes to generate.
My workaround was to save the numerator coefficients in a file. dsp.FIRFilter is able to regenrate an identical filter.

Sign in to comment.

 Accepted Answer

which -all fcfwrite
'fcfwrite' not found.
d=fdesign.lowpass;
which -all fcfwrite
'fcfwrite' not found.
hd=design(d,'butter');
which -all fcfwrite
/MATLAB/toolbox/signal/signal/+dfilt/@basefilter/fcfwrite.m % dfilt.df2sos method
set(hd,'arithmetic','fixed');
which -all fcfwrite
/MATLAB/toolbox/signal/signal/+dfilt/@basefilter/fcfwrite.m % dfilt.df2sos method
which fcfwrite(hd,'iirfilter.fcf')
/MATLAB/toolbox/signal/signal/+dfilt/@basefilter/fcfwrite.m % dfilt.df2sos method
fcfwrite is a method , As such it is not part of the MATLAB path until the defining class is loaded. It must be called with a dfilt.df2sos object to be invoked.

4 Comments

I don't understand. For example, isn't @doc:mapSymType (the @doc functionality isn't working for me) a sym method? But it shows up with which before loading the sym class
which mapSymType
/MATLAB/toolbox/symbolic/symbolic/@sym/mapSymType.m % sym method
What's distinguishes mapSymType from fcfwrite in this context?
Strange behaviour. I don't have the background knowledge to say whether this is expected.
which -all fcfwrite.m
'fcfwrite.m' not found.
type fcfwrite.m
%FCFWRITE Write a filter coefficient file. % FCFWRITE(H) writes a filter coefficient ASCII-file. H maybe a single % filter object or a vector of objects. A dialog box is displayed to % fill in a file name. The default file name is 'untitled.fcf'. % % If the DSP System Toolbox is installed, FCFWRITE(H) can be % used to write filter coefficient files for multirate filter % objects, MFILTs, and adaptive filter objects, ADAPTFILTs. % % FCFWRITE(H,FILENAME) writes the file to a disk file called % FILENAME in the present working directory. % % FCFWRITE(...,FMT) writes the coefficients in the format FMT. Valid FMT % values are 'hex' for hexadecimal, 'dec' for decimal, or 'bin' for % binary representation. % % The extension '.fcf' will be added to FILENAME if it doesn't already % have an extension. % % See also DFILT/INFO, DFILT. % Author(s): J. Schickler % Copyright 1988-2010 The MathWorks, Inc. % [EOF]
type /MATLAB/toolbox/signal/signal/+dfilt/@basefilter/fcfwrite.m
function fcfwrite(h,filename,fmt) %FCFWRITE Write a filter coefficient file. % FCFWRITE(H) writes a filter coefficient ASCII-file. H maybe a single % filter object or a vector of objects. A dialog box is displayed to % fill in a file name. The default file name is 'untitled.fcf'. % % If the DSP System Toolbox is installed, FCFWRITE(H) can be % used to write filter coefficient files for multirate filter % objects, MFILTs, and adaptive filter objects, ADAPTFILTs. % % FCFWRITE(H,FILENAME) writes the file to a disk file called % FILENAME in the present working directory. % % FCFWRITE(...,FMT) writes the coefficients in the format FMT. Valid FMT % values are 'hex' for hexadecimal, 'dec' for decimal, or 'bin' for % binary representation. % % The extension '.fcf' will be added to FILENAME if it doesn't already % have an extension. % % See also DFILT/INFO, DFILT. % Author(s): P. Costa % Copyright 1988-2010 The MathWorks, Inc. narginchk(1,3); if nargin < 3 fmt = 'dec'; if nargin < 2 filename = []; end end if ~isempty(filename) [filename] = convertStringsToChars(filename); end if isempty(filename), filename = 'untitled.fcf'; dlgStr = getString(message('signal:dfilt:dfilt:ExportFilterCoefficientsToFCFFile')); [filename,pathname] = uiputfile('*.fcf', dlgStr, filename); else % File will be created in present directory s = pwd; pathname = [s filesep]; end if ~isempty(filename), if isempty(findstr(filename,'.')), filename=[filename '.fcf']; end filename = [pathname filename]; end if ~any(filename == 0), save2fcffile(h, filename, fmt); end %-------------------------------------------------------------- function save2fcffile(h, file, fmt) % Write the coefficients out to a file. fid = fopen(file,'w'); % Display header information fprintf(fid,'%s\n',sptfileheader); txt = getfiletxt(h, fmt); switch lower(fmt(1:3)) case 'hex' full_fmt = getString(message('signal:dfilt:dfilt:Hexadecimal')); case 'dec' full_fmt = getString(message('signal:dfilt:dfilt:Decimal')); case 'bin' full_fmt = getString(message('signal:dfilt:dfilt:Binary')); end fprintf(fid, '\n%% %s: %s\n\n', getString(message('signal:dfilt:dfilt:CoefficientFormat')),full_fmt); sz = size(txt); for j = 1:sz(1), % Rows fprintf(fid, '%s\n', num2str(txt(j,:),10)); end fprintf(fid, '\n'); fclose(fid); % Launch the MATLAB editor (to display the generated file) edit(file); % ------------------------------------------------------------------------- function txt = getfiletxt(Hb, fmt) % txt is a character array strs = cell(length(Hb)*4, 1); for idx = 1:length(Hb) strs{idx*4-3} = info(Hb(idx)); strs{idx*4-3} = [repmat('% ', size(strs{idx*4-3}, 1), 1) strs{idx*4-3}]; strs{idx*4-2} = sprintf('\n'); strs{idx*4-1} = dispstr(Hb(idx), fmt); strs{idx*4} = sprintf('\n'); end txt = strvcat(strs{:}); % [EOF]
Thanks for the answer. After running these commands, it starts to show up. It's an unintuitive behaviour, I would think all functions installed as add-ons would be accessible on the path on startup.
Anyways, it seems like fcfwrite cannot save a filter of type dsp.FIRFilter. My workaround is pretty straight forward, I simply save the numerator and denominator coefficients to files and retrieve them later with regular fwrite and fread, and pass other necesary properties as arguments to the function dsp.FIRFilter.
Torsten
Torsten on 16 Nov 2026 at 11:31
Edited: Torsten on 16 Nov 2026 at 11:40
fcfwrite cannot directly save a dsp.FIRFilter System object. The fcfwrite function is a legacy method designed specifically for older filter objects like dfilt, mfilt, and adaptfilt. [1, 2, 3]
To export or save the coefficients of a dsp.FIRFilter, use one of the following workarounds depending on your needs: [1]
1. Convert to a dfilt object first
If you specifically need the .fcf ASCII file format (including options for 'hex', 'dec', or 'bin' formatting), extract the numerator coefficients and wrap them in a legacy dfilt.dffir object before calling fcfwrite: [1, 2]
matlab
% Assuming 'firObj' is your dsp.FIRFilter
hd = dfilt.dffir(firObj.Numerator);
fcfwrite(hd, 'my_filter.fcf');
For later use:
matlab
% 1. Read the .fcf file back into a legacy dfilt object
hd_loaded = fcfread('my_filter.fcf');
% 2. Create a new dsp.FIRFilter using the loaded coefficients
firObj_loaded = dsp.FIRFilter('Numerator', hd_loaded.Numerator);
Important Considerations
  • Precision loss: Because .fcf files store coefficients as ASCII text, you may experience slight floating-point rounding compared to the original binary values unless you specify a high-precision format (such as 'hex') when calling fcfwrite.
  • State reset: The newly created firObj_loaded starts with zeroed internal delay states, even if the original dsp.FIRFilter had already processed data before saving.
  • Fixed-point settings: If your original dsp.FIRFilter used custom fixed-point data types (CoefficientsDataType, ProductDataType, etc.), fcfread will not restore those System object properties automatically—you will need to reapply them manually.
2. Save the entire object as a .mat file
If you only need to reload the filter into MATLAB later without regenerating it, use the standard save command:
matlab
save('my_filter.mat', 'firObj');
% Reload later using: load('my_filter.mat')
3. Export coefficients directly to a text or CSV file
If you want a plain list of coefficients for external C/HDL code or another application, extract the Numerator property and write it directly to a file: [1]
matlab
coeffs = firObj.Numerator;
writematrix(coeffs', 'coefficients.txt');

Sign in to comment.

More Answers (1)

Torsten
Torsten on 15 Nov 2026 at 13:53
Edited: Torsten on 15 Nov 2026 at 14:50
However, my matlab install simply does not provide this command.
The same with R2026b:
which fcfileread
/MATLAB/toolbox/signal/sigtools/fcfileread.m
which fcfwrite
'fcfwrite' not found.
Contact support - looks like a bug for me (or the function is no longer in use or the function works when called, but is not shown by the "which" command):
The content of the function looks empty:
type fcfwrite
%FCFWRITE Write a filter coefficient file. % FCFWRITE(H) writes a filter coefficient ASCII-file. H maybe a single % filter object or a vector of objects. A dialog box is displayed to % fill in a file name. The default file name is 'untitled.fcf'. % % If the DSP System Toolbox is installed, FCFWRITE(H) can be % used to write filter coefficient files for multirate filter % objects, MFILTs, and adaptive filter objects, ADAPTFILTs. % % FCFWRITE(H,FILENAME) writes the file to a disk file called % FILENAME in the present working directory. % % FCFWRITE(...,FMT) writes the coefficients in the format FMT. Valid FMT % values are 'hex' for hexadecimal, 'dec' for decimal, or 'bin' for % binary representation. % % The extension '.fcf' will be added to FILENAME if it doesn't already % have an extension. % % See also DFILT/INFO, DFILT. % Author(s): J. Schickler % Copyright 1988-2010 The MathWorks, Inc. % [EOF]

Products

Release

R2026a

Asked:

on 15 Nov 2026 at 13:33

Edited:

on 16 Nov 2026 at 11:40

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!