Mean of the rand function goes against theory

1 view (last 30 days)
I was working on the signal from which I expect to obtain three impulses where the first and the third impulse are situated at Hz which is correct for what the FT of should describe. Furthermore the middle impulse "also known as the DC term" is also apparent as expected however the underlying issue is that this middle impulse supposed to be since the rand function generates numbers from a uniform distribution in the range of which explains why (Note that the "0" additive term comes from the fact that is even symmetric). Now the big question is why is that the FT obtained showed the middle impulse (DC term) having a noise amplitude slightly less than ? Below I present the code I used:
function [X] = FTCos(N)
On the command window:
Any theoratical and practical explanation is much welcomed and thank you!
Update: I am theorizing that a reason to obtain the DC term close to and not equal to 0.5 Hz is because the noise generated isn't precisely uniformly distributed.

Accepted Answer

David Goodmanson
David Goodmanson on 2 May 2021
Edited: David Goodmanson on 2 May 2021
Hi Tarek,
the reason that you don't see 0.5 is that you are taking a finite number of samples, 1024, from the distribution. Due to statistical fluctuations you would not expect to see exactly 0.5 for the mean of the sample. Running your code a bunch of times, sometimes the center peak is a bit greater than 0.5, sometimes a bit less.
The set of random points also produces a small imaginary part to the fft transform, which the plot is warning about but otherwise ignoring.
  1 Comment
Tarek Hajj Shehadi
Tarek Hajj Shehadi on 2 May 2021
David, thank you very much for your answer it makes sense now :)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by