matlab:coe文件
作者:互联网
深度为4096,位宽为8
1. 正余弦
%% sin-cos wave data write in coe file
clear all ;
clc ;
N = 4096 ;
y = zeros(N , 1) ;
for i = 1:1:N
x = i ;
%y(i,1) = ceil( 127*sin(x*2*pi/N) ) + 127 ;
y(i,1) = ceil( 127*cos(x*2*pi/N) ) + 127 ;
end
plot(y);
hold on;
fid = fopen('cos_4096.coe','wt');
%- standard format
fprintf( fid, 'MEMORY_INITIALIZATION_RADIX = 10;\n');
fprintf( fid, 'MEMORY_INITIALIZATION_VECTOR =\n');
%- write data in coe file
for i = 1:1:N
fprintf(fid,'%d,\n',y(i,1));
end
fclose(fid);
2. 三角波
%% triangle wave data write in coe file
clear all ;
clc ;
N = 4096 ;
y = zeros(N , 1) ;
for i = 1:1:N
if(i < 2049)
y(i,1) = fix( (i/8) - 1 ) ;
else
y(i,1) = fix( ((4096 - i )/8) ) ;
end
end
plot(y);
hold on;
fid = fopen('triangle_4096.coe','wt');
%- standard format
fprintf( fid, 'MEMORY_INITIALIZATION_RADIX = 10;\n');
fprintf( fid, 'MEMORY_INITIALIZATION_VECTOR =\n');
%- write data in coe file
for i = 1:1:N
fprintf(fid,'%d,\n',y(i,1));
end
fclose(fid);
3. 矩形波
%% rectangle wave data write in coe file
clear all ;
clc ;
N = 4096 ;
y = zeros(N , 1) ;
for i = 1:1:N
if(i < 2049)
y(i,1) = 255 ;
else
y(i,1) = 0 ;
end
end
plot(y);
hold on;
fid = fopen('rectangle_4096.coe','wt');
%- standard format
fprintf( fid, 'MEMORY_INITIALIZATION_RADIX = 10;\n');
fprintf( fid, 'MEMORY_INITIALIZATION_VECTOR =\n');
%- write data in coe file
for i = 1:1:N
fprintf(fid,'%d,\n',y(i,1));
end
fclose(fid);
标签:%-,文件,end,4096,fprintf,matlab,fid,coe 来源: https://blog.csdn.net/weixin_43778388/article/details/123605838