MATLAB代码
24x24图片转coe文件
load('testset_image.mat')
a = image(1,:);
b = reshape(a,[24,24])';
c = reshape(b,[1,24*24]);
fid = fopen('image_24x24.coe','wt');
fprintf(fid,'memory_initialization_radix=10;\n');
fprintf(fid,'memory_initialization_vector=\n');
fprintf(fid,'%d,\n',c(1,:));
fclose(fid);
参数转coe文件
load('weight1.mat')
FIR_factor = a;
FIR_factor;
data_out = FIR_factor.*10000;
data_out = round(data_out);
data_out = [data_out(:,1,1,1);data_out(:,2,1,1);data_out(:,3,1,1);data_out(:,4,1,1);data_out(:,5,1,1);...
data_out(:,1,1,2);data_out(:,2,1,2);data_out(:,3,1,2);data_out(:,4,1,2);data_out(:,5,1,2);...
data_out(:,1,1,3);data_out(:,2,1,3);data_out(:,3,1,3);data_out(:,4,1,3);data_out(:,5,1,3);]
for ii = 1:length(data_out)
if data_out(ii) < 0
data_out(ii) = -data_out(ii) + 32768;
end
end
fid = fopen('weight1_coe.coe','wt');
fprintf(fid,'memory_initialization_radix=16;\n');
fprintf(fid,'memory_initialization_vector=\n');
fprintf(fid,'%X,\n',data_out);
fclose(fid);