几种常用的FPGA系数表产生方法

1 滤波器系数表

%%========================================
%%==FPGA滤波器核系数转换
%%==把Matlab产生的滤波器系数文件".mat"格式
%%==转换为FPGA滤波器核用的系数文件
%%========================================
clear all;close all;clc;
load('input_file_name.mat');
s = h;
s = round(s*(2^10)/max(abs(s)));    %%量化(这里为10bit)

for( k = 1:length(s) )   %%求补码
    if ( s(k)<0 )
       s1(k) = 2^12 + s(k);
    else
       s1(k) = s(k);
    end
end

%%==按FPGA格式储存
fid_s = fopen('CoeFilterH.coe','wt');
fprintf = (fid_s,'%s\n','radix = 10;');
fprintf = (fid_s,'%s\n','coefdata =');
fprint = (fid_s,'%0.0f,\n',s(1 : end-1));
fprint = (fid_s,'%0.0f;\n',s(end));
fclose(fid_s);

disp('========转换完成========');
return;





2 RAM系数表

%%========================================
%%==FPGA核初值转换
%%==把Matlab产生的RAM初值表".mat"格式
%%==转换为FPGA的RAM核用的初值文件
%%========================================
clear all;close all;clc;
load('input_file_name.mat')'
s=str;
s = round(s*(2^10)/max(abs(s)));    %%量化(这里为10bit)

for( k = 1:length(s) )   %%求补码
    if ( s(k)<0 )
       s1(k) = 2^12 + s(k);
    else
       s1(k) = s(k);
    end
end

%%==按FPGA格式储存
fid_s = fopen('CoeData.coe','wt');
fprintf = (fid_s,'%s\n','MEMORY_INITIALIZATION_RADIX = 10;');
fprintf = (fid_s,'%s\n','MEMORY_INITIALIZATION_VECTOR =');
fprintf = (fid_s,'%0.0f,\n',s(1 : end-1));
fprintf = (fid_s,'%0.0f;\n',s(end));
fclose(fid_s);

disp('========转换完成========');
return;

你可能感兴趣的:(matlab,FPGA)