I'm trying to find a link between the Fourier-Transformation of aperiodic Signals and the FFT of them. So to start with a basic example, let's take a rectangular pulse with width 0.1s and amplitude of 1 shifted by 0.05. Using correspondency, i can calculate the expected spectrum: $X(f) = 0.1 \cdot sinc(0.1f) \cdot e^{j 2 \pi f \cdot 0.05} $
But now, when i generate the Signal with the follwing Matlab-Code:
f_abt = 50e3;
x=0:1/f_abt:1;
y=zeros(1,length(x));
for ii=1:length(x)
if x(ii)<=.1
y(ii)=1;
end
end
And calculate the spectrum of it, the result is depending on the length of the signal. So, when i compute the one-sided spectrum from the signal generated above (1s duration), i get:
Then, when i put the signal length to 2s (everything else unchanged):
x=0:1/f_abt:2;
I guess the difference comes from the FFT-Algorithm i use. When doing FFT, i normalize the Values by Nfft, so it makes complete sense that my amplitudes change when i change the Signal length.
My question is: How do i get the right spectrum and how do i know it is right, e.g. when i can't calculate it 'by hand' using correspondencies? I'm having issues finding the connection between my "real", time limited signal and its FFT and the "theoretical" rectangular pulse.
Code I use for calculation of one-sided spectrum:
function [f_xa, mag, phase] = calc_fft_f(ta, xa)
N_a = numel(xa);
fft_xa = fft(xa);
P2_norm = fft_xa/(N_a);
if (mod(N_a,2))
P1_norm_single = P2_norm(1:ceil(end/2));
P1_norm_single(2:end) = 2*P1_norm_single(2:end);
else
P1_norm_single = P2_norm(1:(end/2)+1);
P1_norm_single(2:end-1) = 2*P1_norm_single(2:end-1);
end
mag = abs(P1_norm_single);
phase = rad2deg(angle(P1_norm_single));
Fsa = 1/(ta(2)-ta(1));
f_xa = Fsa*(0:(length(mag)-1))/N_a;
end
Thanks in advance!