MATLAB: Is implementing the “fft” formula in documentation giving me opposite sign for imaginary part

MATLAB

Why is implementing the "fft" formula in documentation giving me opposite sign for imaginary part?
I implemented the formula in "fft" documentation:
>> help fft
But the "imag" part is opposite to what I got using the built-in "fft":
>> t = linspace(0, 0.5 , 2048);
>> Signal = cos(2*pi*t*50).';
>>
>> X = fft(Signal);
>>
>> N = length(Signal);
>> Y = zeros(N,1);
>> for k = 1:N
Y(k) = sum(Signal .* exp(-1j*2*pi*(k-1)*(0:N-1)/N)');
>> end
>>
>> plot(imga(X))
>> hold on
>> plot(imag(Y))

Best Answer

The problem is in this line of code:
>> Y(k) = sum(Signal .* exp(-1j*2*pi*(k-1)*(0:N-1)/N)');
The transpose operator (') is doing a complex conjugate transpose. Please use .' instead.