📄 readme.txt
字号:
网上流传的方法很多试过都不顶用,错误很多,有的生成的格式不对
这里说明以下几点注意
1.选择dsp的Q14 Q15 根据这个对信号*2^Q
2.注意生成信号变成十六进制负数变补码问题 取值范围+x
3.注意信号与dsp要处理信号的采样率问题 要同步才能减小误差
4.写为.dat文件用 dlmwrite 或者 fopen语句
5.注意变为dsp可读格式fprintf(fid,'1651 1 0 1 0\n');%输出文件头1是16进制
6.注意对应的输出要'0x%x\n'而不是d% 这个很关键 否则会出错的
fprintf(fid,'0x%x\n',round(y));%输出
详见示例喽
将sine.text文件黏贴到matlab中试一下吧 根据需要生成自己要的文件
% Creat a data file of the sinewave, which DSP chip can load .%
clear all;
Fs=44100; %Sampling Frequecy of AIC23=44.1KHz%
f1=500; %Frequency of Sine Wave"
y=32768*sin(2*pi*f1*[0: 2048]/Fs); % Number of Sampling point=2048, 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 1
fprintf(fid, '0x%x\n', y); % output 32bit hexadecimal data %
case 2
fprintf(fid, '%d\n', round(y)); % output 32bit float data %
case 3
fprintf(fid, '%12.1f\n', round(y)); % output 40bit long inter data %
case 4
fprintf(fid, '%f\n', y); % outout 32bit integer data %
end
fclose(fid); % close the .dat file %
对于负数,应当采用补码,用模减去该数的绝对值.
此后要对X中的各个元素需要转化为合适的定点数,dsp5509音频Q15格式,用浮点数A转换成定点数B: B =(int)A×2^Q来进行转换,如果是负数,还需要求补. *32768
负数求补x= 2+x
要加个for循环??
比较正负 逐点比较
2048点的采样率为标准声卡 dsp5509 Q15格式
验证成功
% Creat a data file of the sinewave, which DSP chip can load .%
clear all;
Fs=44100; %Sampling Frequecy of AIC23=44.1KHz%
f1=500; %Frequency of Sine Wave"
for m=1:2048;
x=sin(2*pi*f1*[0: 2048]/Fs); % Number of Sampling point=2048, and create sine wave%
if x(m)>=0 y(m)=x(m);
else y(m)=2+x(m);
end;
end;
y=y*32768;
fid=fopen('sine.dat','w');%打开文件
fprintf(fid,'1651 1 0 1 0\n');%输出文件头
fprintf(fid,'0x%x\n',round(y));%输出
fclose(fid);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -