edit: This is my first post in this community. I'm sure that my downvoter had a good reason to do so, but could someone please comment and tell me how I can better format my question?
--
I have a DFT algorithm that almost makes sense. The issue is when I go to plot the frequency response. For some reason, the frequency response gets multiplied by the sampling period (see first image).
Understanding this, I can fix it by dividing my frequency response X-axis by sampling period (see second image), but I don't understand why this is an issue in the first place.
Code is posted below - can anyone explain what I am missing? (example uses a 1 Hz sinusoid)
Here's how I think it should work:
But here's what I actually have to do to make it work:
x_t = sin( 2 * pi * t); % Input: 1 Hz Sinusoid
s_f = zeros(N,length(x_t)); % Output: Freq spectrum
%%%% init params
T = 4; % (sec) time window
dt = 0.1; % (sec) sample time
%%%% init comp
N = T / dt; % (ct) num samples
n = 0 : N - 1; % (ct) bucket index vector
t = 0 : dt : T - dt; % (sec) time vector
smpl_freq = 1 / dt; % (Hz) sampling frequency
freq_res = smpl_freq / N; % (Hz) frequency resolution
f = n * freq_res; % (Hz) freq. bucket vector
b = 2*pi*(f/N) .* n.';
anlyz_fn = cos(-b) + i * sin(-b);
%%%% run DFT
for k = 1 : N
val = 2 * sum(anlyz_fn(k,:) * x_t.');
s_f(k) = val;
end
%%%% Plot Results
subplot(2,1,1);
plot(t, x_t);
subplot(2,1,2);
stem(f(1:N)/T , abs(s_f(1:N))/N);