from
Tektronix RSA3000A/B User-Defined Filter Converter
by Tektronix Development Team
Convert MATLAB filter coefficient files to a RSA3000-compatable format
|
| fcf2csvfilt(strFileName)
|
%% fcf2csvfilt: Convert Matlab FCF filter coefficient file to a CSV file
% that can be used by the RSA3000.
%
% Inputs:
% strFileName:
% File to be read, with path but without extension
%
% Outputs:
% None
%
% Example:
% fcf2csvfilt('C:\matlab\my_filter');
% Loads "C:\matlab\my_filter.fcf", converts the filter data,
% and writes the file as "C:\matlab\my_filter.csv"
%
%
function fcf2csvfilt(strFileName)
nRSAOversampling = 8;
%% Open the input file
fid = fopen([strFileName '.fcf'], 'r');
if -1 == fid
error([strFileName '.fcf could not be opened for reading']);
end
%% Read until you get past the data, then read the data
strDataMarker = 'Numerator:';
nDataFound = 0;
mCoeffs = [];
while ~feof(fid)
strLine = fgetl(fid);
if 0 == nDataFound
if 1 == strncmp(strDataMarker, strLine, length(strDataMarker))
nDataFound = 1;
end
else
mCoeff = sscanf(strLine, '%f%f', [2,1]);
if char(0) ~= mCoeff
mCoeffs = [mCoeffs mCoeff];
end
end
end
if 0 == nDataFound
error(['No filter data found in ' strFileName '.fcf']);
end
%% Close the input
fclose(fid);
%% Open the output file
fid = fopen([strFileName '.csv'], 'w');
if -1 == fid
error([strFileName '.csv could not be opened for writing']);
end
%% Write the header to the outout
fprintf(fid, [num2str(nRSAOversampling) '\n']);
%% Write the coefficients to the output
% For now we're only going to deal with real and complex
% filters.
nCoeffSize = size(mCoeffs);
for n = 1:nCoeffSize(2)
strLine = num2str(mCoeffs(1, n), 20);
if nCoeffSize(1) > 1
strLine = [strLine ', ' num2str(mCoeffs(2,n), 20)];
end
fprintf(fid, [strLine '\n']);
end
%% Close the output file
fclose(fid);
end
|
|
Contact us at files@mathworks.com