深度为4096,位宽为8
%% 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);
%% 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);
%% 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);