width = 8;
depth = 64;
index = linspace(0, 2*pi, depth);
sin_value = sin(index);
sin_value = sin_value * (2^(width-1) -1 );
sin_value = fix(sin_value);
toVerilog = mod(sin_value+256, 256);
fid = fopen('Data_Input.txt', 'wt');
fprintf(fid, '%02x 00\n', toVerilog);
fclose(fid);
% 计算用于verilog的Wn的参数,均乘以255
fid = fopen('Data_Parameter.txt', 'wt');
for i = 1:6
N = 2^i;
for j = 0:N/2-1
real_f = cos(2*pi*j/N);
imag_f =-sin(2*pi*j/N);
real_d = fix(real_f * 127);
imag_d = fix(imag_f * 127);
real_d = mod(real_d + 256, 256);
imag_d = mod(imag_d + 256, 256);
%fprintf(fid, '(%02d.%02d) %02x %02x \t%1.4f %1.4f\n',i, j, real_d, imag_d, real_f, imag_f);
fprintf(fid, '%02x %02x\n',real_d, imag_d);
end
end
fclose(fid);
% 计算FFT
n = 0:depth-1;
y = fft(sin_value);
for i = 1 : depth
yreal(i) = fix(real(y(i)));
yimag(i) = fix(imag(y(i)));
end
yint = [yreal; yimag]'; % 最终比对用FFT结果