I'm trying to generate a random frequency spectrum and then use ifft
to find the corresponding time domain vector.
I'm using the following code:
for i = 1:64
randNum = (rand() + 1i * rand())/sqrt(2); % Needs to be normalized by sqrt(2)
randFreq(i) = randNum;
end
randVec = ifft(randFreq);
Note that I'm aware of mvnrnd
, however for technical reasons I need to use a for
loop and generate each element individually. I also need to generate the random frequency spectrum and then use an inverse transform, I can't directly generate a random vector in the time domain.
If I plot the magnitude of the random vector (plot(abs(randVec))
), I always get a graph of this form.
There's always a spike at n=0
and all the other elements are significantly smaller in magnitude. I was hoping for some insight into why this was happening.
My question is not a duplicate of Create random values in vector Matlab, they are completely different questions that just happen to be on the same topic. I'm specifically asking about the behaviour of my ifft
. It's not a duplicate of spike in my inverse fourier transform either. In that question, the spike could be caused by some idiosyncrasy of the data, however in my case the data is completely random.
The rand function generates arrays of random numbers whose elements are uniformly distributed in the interval ( 0 , 1 ). Y = rand(n) returns an n -by- n matrix of random entries. An error message appears if n is not a scalar. Y = rand(m,n) or Y = rand([m n]) returns an m -by- n matrix of random entries.
Use the rand function to draw the values from a uniform distribution in the open interval, (50,100). a = 50; b = 100; r = (b-a). *rand(1000,1) + a; Verify the values in r are within the specified range.
The way you generate the random values for the frequency components, they are not symmetrically distributed about zero. Specifically, the obtained real and imaginary parts have an ideal average of .5/sqrt(2)
. The actual (sample) average will be close to that.
When you apply the IDFT, the average over all frequencies corresponds to the first sample in the time domain. To see this, set n = 0 in the IDFT expression:
So you get a larger absolute value at that first sample because the average over frequency is larger than it "should".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With