Forums

Gaussian Distribution Power Spectrum

Started by imageprocessingx May 31, 2003
I'm trying to plot the power spec of a set of normally distributed
random values. I'm told it should look like a straight line.
However, I'm not seeing this. I'm seeing a 'spike' at the
beginning, or at the end, depending on the shift. Any thoughts?

As you can see, I'm a beginner at Matlab, so places where for loops
exist can be replaced with one line.

Thanks for the help. function y=Gaussian()
fn = 1000; % sampling frequency
% randn('seed',5); % this takes all the
randomness
% out. Verification
purposes only
run = 64;
sample_count = 2^11; % number of discrete samples
sample_run = sample_count - run; % we'll get 40 samples over
a
% our period.

for bv = 1:sample_count
inphaset(bv) = randn; % initialize data vector
end

inphase(run) = 0; % initialize the space
requireed

for dv = 1:sample_run
for dx = 1:run
inphase(dx) = inphase(dx) + inphaset(dv+dx);
end
end

y = fft(inphase); %Compute FFT of data in inphase
% move the DC component to center.
ytshift(y);
sec = length(inphase)/fn; %Compute the number of seconds of data
(acq. rate = 1000)
y(1) =[]; %Delete the first value of the resulting array, which is
the total relative magnitude
mag = abs(y).^2; %Compute square of the magnitude of the FFT (Note
that a Fourier transform is a complex function). The magnitude
squared gives the power spectrum.
power = mag(1:ceil(length(mag)/2)); %Compute the power spectrum from
mag as 1/2 the array (use only positive frequencies which are in the
first 1/2 of the resulting array)
x = (0:length(power)-1)/sec; %Compute the frequencies (x-values) to
match the above magnitudes, scaled to the actual number of seconds
figure(1);
plot(x,power) %Plot the frequency spectrum as Power vs. X

y = x;