matlab:coe文件

2022/3/20 6:29:36

本文主要是介绍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);


这篇关于matlab:coe文件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程