%% Sine LUT Generator
clear, clc;

% parameters
phaseBit = 9;
amplitudeBit = 14;

% calculate
% phase = 2^phaseBit;
phase = 500;
amplitude = 2^amplitudeBit;

T = 1;
dt = 1/phase;
t = 0:dt:T-dt;
y = sin(2*pi*t) * ((amplitude-1)/2) + (amplitude-1 - (amplitude-1)/2); % with offste
y = int32(y);

x_bin = (dec2bin([0:phase-1],phaseBit));
y_bin = (dec2bin(y,amplitudeBit));

% plot result
plot([0:phase-1],y)
 
% write to text
fileID = fopen('Sine_LUT.vhd','w');
fprintf(fileID,'process(address_cnt)\nbegin\ncase address_cnt is\n');
for i = [1:length(x_bin)]
fprintf(fileID,'when "%s" => sin_out_tmp <= "%s";\n',x_bin(i,:),y_bin(i,:));
end
fprintf(fileID,'when others => sin_out_tmp <= "%s";\nend case;\nend process;',dec2bin(0,amplitudeBit));
fclose(fileID);