%generate data , 2's
N = 1024;
x = (0:1/N:1-1/N)*2*pi;
data_sin = fopen('data_sin.txt','w');
y1 = cos(x);
y2 = sin(x);
%length(y1)
%浮点转为二进制补码
for n = 1:N
if y1(n) < 0
y1(n) = round(2^16 + y1(n)*2^14);
if y1(n) == 65536
y1(n) = 0;
end
else
y1(n) = round(y1(n)*2^14);
end
if y2(n) < 0
y2(n) = round(2^16 + y2(n)*2^14);
if y2(n) == 65536
y2(n) = 0;
end
else
y2(n) = round(y2(n)*2^14);
end
end
for m = 1:2*14
for n = 1:N
%y(n) = round((y1(n)+1)*2^14)*2^16+round((y2(n)+1)*2^14);
fprintf(data_sin,'%s',dec2bin(y1(n),16));
fprintf(data_sin,'%s\n',dec2bin(y2(n),16));
end
end