I'm interested in knowing:
1. Why the frequency content has a larger magnitude at low frequencies
2. Why the magnitude is zero at frequencies which are composed of multiples of the rectangular pulse's period
\$x(t)\$:
\$X(j\omega)\$:
Best Answer
Take a look at these two periodic-signal transformations: -
The first example has a duty cycle of 0.27 and as can be seen (if you did a fourier transformation), the spectral content at closest to 3f is quite small. Should the rectangular wave have a duty-cycle of exactly one-third, the spectral content at 3f would be zero.
Similar story for a 50:50 AC square wave; the duty cycle is 0.5 therefore the spectral content at 2f (and 4f and 6f etc..) is always zero.
Picture stolen from here and please note that the article continues to show how the fourier spectrum is evaluated (for further reading).
The non-periodic example in your question produces a continuous spectrum but the nulls and the peaks still align with the examples above.
As for the low frequency being so high in the OP's example, it's because the pulse has significant DC content
Intuitively the DFT and FT are similar. As the other poster pointed out, the main difference is that sampling in the time domain is equivalent to repetition in the Frequency domain, so the DFT will have repeated spectra at multiples of the sample frequency.
Two problems here.
i) abs(real(y)) is incorrectly being used. You need the absolute value (or magnitude) of both the imaginary and real components ... abs(y).
ii) You're seeing the effect of spectral leakage because the DFT assumes a repetitive signal; i.e. the maths "assumes" the signal you applied is repeated infinitely. Your signal will have discontinuities in this case.
Try the following code:
t = [-10*pi:pi/10:9.9*pi]
x = sin(t)
y = fft(x)
z = abs(y)
But why is the first entry in the FFT results not the fundamental?
Typically the 0'th entry stores the DC term. In some schemes, the [N/2]'th entry might be the DC term and the [N/2+1]'th entry would be the fundamental.
I applied an LC filter, by iterating through the FFT results and multiplying each bin by the filter gain at that frequency. I then did an inverse FFT, ... The result has both real and imaginary components.
Did you consider the phase effect of the filter? You should be multiplying by a complex value accounting for both the magnitude and phase response of the LC filter.
Even then, due to finite precision issues, you will often still get non-zero imaginary components in the inverse-transformed time-domain signal. But usually these are very small, for example on the order of \$10^{-15}\times\$ the real components. These are usually dealt with by simply ignoring them (taking the real part of the result only). Some tools even offer a built-in function (Mathematica's Chop, for example) to eliminate these artifacts.
Best Answer
Take a look at these two periodic-signal transformations: -
The first example has a duty cycle of 0.27 and as can be seen (if you did a fourier transformation), the spectral content at closest to 3f is quite small. Should the rectangular wave have a duty-cycle of exactly one-third, the spectral content at 3f would be zero.
Similar story for a 50:50 AC square wave; the duty cycle is 0.5 therefore the spectral content at 2f (and 4f and 6f etc..) is always zero.
Picture stolen from here and please note that the article continues to show how the fourier spectrum is evaluated (for further reading).
The non-periodic example in your question produces a continuous spectrum but the nulls and the peaks still align with the examples above.
As for the low frequency being so high in the OP's example, it's because the pulse has significant DC content