The square wave will be more audible. 50 Hz is fairly low and most speakers will not reproduce that frequency very well. Since a sine wave will have only 50 Hz there may not be that much audio reaching the human ear, and even then the human ear will not respond very efficiently to it. A square wave, on the other hand, will have lots of harmonics that the speaker will reproduce very well and the harmonic frequencies will be spread right through the ideal frequency range for human hearing (300Hz to 3 KHz).
This is a windowing artifact.
The linked code pads out a 10,000 sample signal with zeroes so that the length is a power of two.
%% Author :- Embedded Laboratory
%%This Project shows how to apply FFT on a signal and its physical
% significance.
fSampling = 10000; %Sampling Frequency
tSampling = 1/fSampling; %Sampling Time
L = 10000; %Length of Signal
t = (0:L-1)*tSampling; %Time Vector
F = 100; %Frequency of Signal
%% Signal Without Noise
xsig = sin(2*pi*F*t);
...
%%Frequency Transform of above Signal
subplot(2,1,2)
NFFT = 2^nextpow2(L);
Xsig = fft(xsig,NFFT)/L;
...
Note that in the above code, the FFT is taken with the FFT size NFFT
which is the next power of 2 bigger than the signal length (in this case, 16,384.) From the Mathworks fft()
documentation:
Y = fft(X,n)
returns the n-point DFT. fft(X)
is equivalent to fft(X, n)
where n
is the size of X
in the first nonsingleton dimension. If the length of X
is less than n
, X
is padded with trailing zeros to length n
. If the length of X
is greater than n
, the sequence X
is truncated. When X
is a matrix, the length of the columns are adjusted in the same manner.
This means that you are not actually taking a FFT of a 'pure sine wave' - you are taking the FFT of a sine wave with a flat signal after it.
This is equivalent to taking the FFT of a sine wave multiplied with a square window function. The FFT spectrum is then the convolution of the sine wave frequency spectrum (an impulse function) with the square wave frequency spectrum (sinc(f).)
If you change L = 16,384
so that there is no zero-padding of the signal, you will observe a perfect
FFT.
Further search keywords: "Spectral Leakage", "Window Function", "Hamming Window".
Edit: I cleaned up some material I wrote on this topic back in university, which goes into substantially more detail. I've posted that on my blog.
Best Answer
You're confusing bandwidth with the fundamental frequency, or repetition rate.
A square wave behaves the exact same way as a sine wave, in that as its fundamental frequency increases, you will see more cycles in a given amount of time.
Square waves theoretically have infinite bandwidth. (I seem to recall seven times the fundamental as a practical rule of thumb from school.) Intuitively, more higher harmonics are needed to sharpen the rising and falling edges.
Plotting it out as a summation of sines is easy and will help with your understanding.