I hope this isn't such a dumb question, but I'm finally getting to grips with the inner workings of the DFT.
What I'm having trouble understanding is why the basis complex sinusoids in the "forward" DFT are conjugated, and why the inverse DFT uses non-conjugated complex sinusoids.
I've written a script in MATLAB that attempts to implement what I understand about the DFT (not FFT, I know a fast function for that already exists). I notice that based on this conjugation issue I'm having, when I run a real sinusoid of some frequency through my DFT script, then perform the inverse part I get back the original sinusoid but at what looks like a quarter cycle out of phase.
Can anyone clarify what's going on for me?
(here's my MATLAB code snippet):
%% setup a test sinusoid Fs = 44100; freq = 440.0; amp = 1.0; % setup col signal vector x = generate_sine(freq, 0, amp, Fs, Fs); % set length of DFT (# of bins/frequency resolution) N = 2^13; % get bin resolution from sampling frequency: acts as % a Kth test frequency multiplier for DFTs shorter than % the sampling frequency bin_width = Fs/N; % truncate length of input signal to size of DFT (bins) x(N+1:end) = ; % plot original, truncated signal figure(1) subplot(3,1,1) title('original signal') stem(x, '.'); %% perform DFT using N test sinusoids (bins) % This for loop represents the summation process of the DFT. % -i is an iterator where: % } i = 0 frequency = DC, % } and i > 0 = Kth sinusoid frequency % -in each loop iteration a new test complex sinusoid is % generated based on i iterator which is used a the % frequency number. % -in each loop iteration the dot product of the current test % sinusoid is taken, then stored in a vector of frequency bins for i = 0: N-1 % set current test frequency (Kth frequency) k = bin_width * i; % generate a complex sinusoid vector cp_sin = complex(generate_sine(k, 0, 1, Fs, N) / (N/2), generate_sine(k, pi/2, 1, Fs, N) / (N/2)); % store dot product result in bin number i bins(i+1) = dot(cp_sin,x); bins = bins.'; end % plot DFT result subplot(3,1,2) title('DFT') plot(abs(bins)); xlim([0 N/2]); %% perform inverse DFT for i = 0:N-1 % set current test frequency (Kth frequency) k = bin_width * i; % generate a sinusoid cp_sin = complex(generate_sine(k, 0, 1, Fs, N) * (N/2), generate_sine(k, pi/2, 1, Fs, N) * (N/2)); % perform inverse transform to get original signal back xi(i+1) = (dot(bins,cp_sin))/N; xi = xi.'; end %% plot inverse DFT result subplot(3,1,3) title('IDFT') stem(real(xi), '.'); ylim([-1 1]);