For my example to work, your t vector must be a column vector, change this line
t = (0.5:1:n) / fSample; % actual time
to
t = (0.5:1:n)' / fSample; % actual time
You can use regress to get the amplitude of the sine and cosine components. Delete this line of your code:
myFFT(fi) = (sum(c .* waveformHW) + 1i * sum(s .* waveformHW))/sum(c.*c.*hwin);
Replace it with
b = regress(waveformHW, [c, s]; % c and s must be column vectors
myFFT(fi) = b(1) + 1i * b(2);