matlab应用,DDS之Matlab应用

实验二告一段落了,其中有些东西还是拿出来总结下:
(Matlab应用)
一、直接生成mif文件:
可以直接使用文件操作,生成文件,不需要手动添加mif格式说明或者改扩展名
1.sin表
>> depth=1024; %存储单元数;
widths=10; %数据宽度为10位;
%N=0:1: 1024;
%s=sin(pi*N/512);
fidc=fopen('sin.mif','wt'); %以“wt”的形式打开,\n为换行
%写入dds.mif%
fprintf(fidc,'depth=%d;\n',depth);
fprintf(fidc,'width=%d;\n',widths);
fprintf(fidc,'address_radix= uns;\n');
fprintf(fidc,'data_radix = uns;\n');
fprintf(fidc,'Content Begin\n');
for(x=1:depth)
fprintf(fidc,'%d:%d;\n',x-1, round(511*sin(pi*(x-1)/512)+512));
end
fprintf(fidc,'end;');
fclose(fidc);
2.三角波mif表(实际上并未用到三角波的表)
>>
>> depth=1024; %存储单元数;
widths=10; %数据宽度为10位;
N=0:1: 1024;
%s=sin(pi*N/512);
x1=round(511*sawtooth(2*pi*(N-1)/1024,0.5)+512);
plot(N,x1),axis([0,1024,0,1024]);
fidc=fopen('triangle.mif','wt'); %以“wt”的形式打开,\n为换行
%写入dds.mif%
fprintf(fidc,'depth=%d;\n',depth);
fprintf(fidc,'width=%d;\n',widths);
fprintf(fidc,'address_radix=uns;\n');
fprintf(fidc,'data_radix = uns;\n');
fprintf(fidc,'Content Begin\n');
for(x=1:depth)
fprintf(fidc,'%d:%d;\n',x-1, round(511*sawtooth(pi*(x-1)/512,0.5)+512));
end
fprintf(fidc,'end;');
fclose(fidc);
二、函数作图
功能:在相同坐标轴下,分别画出正弦,三角,锯齿,方波图像
用于实验报告
>>
>> N=0:1: 1024;
x1=round(511*sin(pi*(N-1)/512)+512);
x2=round(511*sawtooth(2*pi*(N-1)/1024,0.5)+512);
subplot(411)
plot(N,x1),axis([0,1024,-100,1200]);
subplot(412)
plot(N,x2),axis([0,1024,-100,1200]);
x3=round(511*sawtooth(2*pi*(N-1)/1024,1)+512);
subplot(413)
plot(N,x3),axis([0,1024,0,1024]);
x4=1024*(1-rectpuls(N,1024));
subplot(414)
plot(N,x4),axis([0,1024,-100,1200]);
>>
结果如图所示



over。
Tags:  matlab应用

延伸阅读

最新评论

发表评论