Mean of the rand function goes against theory
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Tarek Hajj Shehadi
le 2 Mai 2021
Modifié(e) : David Goodmanson
le 2 Mai 2021
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/604900/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/604905/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/604925/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/604910/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/604915/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/604935/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/604925/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/604910/image.png)
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.
0 commentaires
Réponse acceptée
David Goodmanson
le 2 Mai 2021
Modifié(e) : David Goodmanson
le 2 Mai 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Fourier Analysis and Filtering dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!