# Mean of the rand function goes against theory

조회 수: 1(최근 30일)
Tarek Hajj Shehadi 2021년 5월 2일
편집: David Goodmanson 2021년 5월 2일
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)
f=linspace(-51.2,51.2,N);
t=linspace(-5,5,N);
C=cos(2*pi*t)+rand(1,N);
X=fftshift(fft(C))/N;
plot(f,X,'b')
On the command window:
N=1024;
[X]=FTCos(N)
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.

댓글을 달려면 로그인하십시오.

### 채택된 답변

David Goodmanson 2021년 5월 2일
편집: David Goodmanson 2021년 5월 2일
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표시숨기기 없음
Tarek Hajj Shehadi 2021년 5월 2일
David, thank you very much for your answer it makes sense now :)

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

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

Start Hunting!