文档库 最新最全的文档下载
当前位置:文档库 › matlab单音信号生成实例

matlab单音信号生成实例

clear all;close all;fclose all;clc;

f= 1.536e6;
fs=153.6e6;
num = 100;
width=16;
hex_w = ceil(width/4);
fprintf('every period point is %d ,generate data length is %d\n', fs/f,num);
n = 0:f/fs:(f/fs*(num-1));
for loop = 1:2
if(loop == 1)%cos
fid = fopen('data/cos.txt', 'w');
data = cos(2*pi*n);
else%sin
fid = fopen('data/sin.txt', 'w');
data = sin(2*pi*n);
end
%convert decimal into hex
for n2= 1:num;%量化
if(data(n2)>0 || data(n2)==0)
data(n2) = round(data(n2)*(2^(width-1)-1));
else%x+2^n
data(n2) = round(data(n2)*2^(width-1));
end

if(data(n2)< 0 )%负数转补码
data(n2) = data(n2)+ 2^width ;
end

fprintf(fid, '%s\n', dec2hex(data(n2),hex_w));
end
fclose(fid);
end


disp('done');

相关文档
相关文档 最新文档