1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > matlab如何与ccs关联 CCS与Matlab

matlab如何与ccs关联 CCS与Matlab

时间:2019-03-06 11:51:34

相关推荐

matlab如何与ccs关联 CCS与Matlab

matlab向dsp传递.dat文件

x=2*sin(2*pi*100*m*dt);

for m=1:200;

if x(m)>=0 y(m)=x(m);

else y(m)=4+x(m);

end;

end;

y=y*16384;

fid=fopen('input.dat','w');%打开文件,'w'是将此文件定义为可写的,fid是此文件的整数标示

fprintf(fid,'1651 1 0 1 0/n');%输出文件头,文件头必须是dsp所能识别的,就如此句程序所设定的

fprintf(fid,'0x%x/n',round(y));%输出y数组,并写到与fid标示符相同的文件,即yinput.dat文件里。round是取y值的最近的数,即如果是1.2,就取1,如果1.6,就取2.

fclose(fid); %关闭fid标示符的文件。

fid=fopen('input.dat','w');%打开文件,属性设置为写

fprintf(fid,'1651 1 0 1 0/n');%输出文件头,只有此文件头dsp芯片才能识别

fprintf(fid,'0x%x/n',round(x));%输出十六进制的x

fclose(fid);关闭

这里x要转换成二进制补码,这也是我发此贴的目的所在。只是个人的理解,如果有问题,请大侠们改正,为更多dsp学习者们提供借鉴。

首先确定x的范围,譬如x=【-2,2】,那么,我们采用定点Q14,那么就是要乘以16384,如果x<0,还要转化成其补码。补码应该是用模加上x,即4+x,然后再将此数乘以16384.

转载请注明出自DSP交流网 DSP学习第一论坛 DSP技术应用与推广平台 DSP开发服务平台/bbs/,本贴地址:/bbs/viewthread.php?tid=4537

其在CCS中的使用方法可以有一下命令:

File->Data->Load

File->Data->Store

File->File I/O

红尘出品,转载请注明出处。 to mayerx:我按你说的方法试了一下,不知道负数应该怎样处理?你说的“生成的数据转化为合适Q值的十六进制数据”看了不是很明白.我的小程序如下,错的地方请指正,谢谢!x=8*sin(0.5*2*pi*[1:1000]/300)+3*sin(40*2*pi*[1:1000]/300);%产生数据fid=fopen('input.dat','w');%打开文件fprintf(fid,'1651 1 0 1 0/n');%输出文件头fprintf(fid,'0x%x/n',round(x));%输出fclose(fid); ************************888我知道怎么用matlab产生dsp 需要的数据文件,程序附在下面.% Creat a data file of the sinewave, which DSP chip can load .%clear all;Fs=8000; %Sampling Frequecy of AD535 chip=8KHz%f1=100; %Frequency of Sine Wave" y=10*sin(2*pi*f1*[0: 160]/Fs); % Number of Sampling point=160, and create sine wave%plot(y);grid on;reply=input('Please input category of data: '); % input category of data%fid=fopen(sine1.dat', 'w'); %creat a data file in the given folder%fprintf(fid, '1651 %d 0 0 0 /n', reply); % output the head file of .dat file %switch reply % output data into the .dat file according to the category of data%case 1fprintf(fid, '0x%x/n', y); % output 32bit hexadecimal data % case 2fprintf(fid, '%d/n', round(y)); % output 32bit float data %case 3fprintf(fid, '%12.1f/n', round(y)); % output 40bit long inter data %case 4fprintf(fid, '%f/n', y); % outout 32bit integer data % endfclose(fid); % close the .dat file % *************************************************88对于负数,应当采用补码,用模减去该数的绝对值. 你的程序中有如下问题没有考虑:x=8*sin(0.5*2*pi*[1:1000]/300)+3*sin(40*2*pi*[1:1000]/300);%产生数据%%此后要对X中的各个元素需要转化为合适的定点数,比如你的各元素在-11~11之间,则选用Q11,其示数范围在-16≤x≤15.9995117,否则保存结果应当还是浮点数.用浮点数A转换成定点数B:B =(int)A×2^Q来进行转换,如果是负数,还需要求补.fid=fopen('input.dat','w');%打开文件fprintf(fid,'1651 1 0 1 0/n');%输出文件头fprintf(fid,'0x%x/n',round(x));%输出fclose(fid);

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。