white noise has flat power spectral density - matlab

I am trying to prove that the white noise has constant power spectral density using matlab
but the amplitude of the spectrum looks like random amplitude.
can anyone tell me why?
here is my code.
noise = randn(1,10000);
fft_noise=fft(noise);
plot(abs(fft_noise(1:5000)))
thanks.

You need to average a bunch (law of large numbers) of FFTs of white noise to approach the average power spectral density.

If you take the FFT of an independent set of random variables from the same distribution, then you'll get an independent set of random variables from the same distribution since the inverse Fourier transform is (more or less) the same as the Fourier transform. The point is that the expected value for each frequency is the same.

you need to multiple the fft by the complex conjugate of the fft to show a flat PSD. i.e. change
fft_noise=fft(noise);
to
fft_noise=fft(noise).*conj(fft(noise));

Related

Calculating standard deviation from power spectral density

I have set of data (x) for power spectral density (Gaussian white noise), and I am trying to find the standard deviation from it. The result looks wrong because I know that the standard deviation must be with a range of 5.
I used below code
sd=std(x)
Data
Thanks
Take the inverse fourier transform, and look at the element at time zero. Note that this is actually just the sum of all the values (\int{X(w)e^{iwt}}dw | t=0 = \int X(w) dw), with some scaling constant applied which depends on how you defined the psd in a discrete frequency domain
The power spectral density, S_xx(w), is equal to F{R_xx(tau)}, the fourier transform of the autocorrelation, R_xx(tau) = E[x(t)x(t+tau)].
Since you want the standard deviation, you can get R_xx(0) = E[x(t)^2], and then std^2 = E[x(t)^2] - E[x(t)]^2.
Unfortunately, it seems you have no way to recover E[x(t)]. Perhaps you already know this is 0?

How to produce quadruple density wavelet coefficients?

I refer to this paper, second-page right-column second-paragraph, where it is stated how to produce quadruple density wavelet coefficients:
if we do not down sample the wavelet coefficients we generate
wavelets with double density, where wavelets of level n are centered every 1/2*2^n. To generate the quadruple density dictionary,we compute the scaling coefficients with double density by not down sampling
them. The next step is to calculate double density wavelet coefficients on the two sets of scaling coefficients - even
and odd - separately.
I am confused how to get two sets of scaling coefficients - even and odd. What does it mean by even and odd?
Is that like, split the original image matrix into two matrices with those only even-index (0,0) (0,2)..... and odd-index (0,1),(0,3)...? What is the advantage?
Thanks
Those who has interest for Overcomplete Wavelet Transform, please look at these two links.
http://www.dahlsys.com/cuda/overcomplete_wavelet/index.html
http://eeweb.poly.edu/~onur/source.html
Thanks

making pink noise (1/f) using list of frequencies

making pink noise (1/f) using list of frequencies
I would like to see what type of noise I would get if I used just the frequency in my voice. I created a matlab/octave array using fft to get the [frequency,amplitude,phase] to reproduce my vocal signal.
I would like to take this file/data and use it to create pink noise (1/f). Of course when I use 1/f for the frequency the numbers become very small does anyone have any ideas how to use my own vocal frequencies that I get from doing a fft in matlab to create pink noise (1/f).
Thanks
If I am correct, what you are doing is generating noise based on a 1/f frequency. However if you read the following article: http://en.wikipedia.org/wiki/Pink_noise the frequencies are the same except that the power spectral density is S is proportional to 1/f. Hence you should not be generating noise of frequency 1/f.
I would suggest reading this page for the necessary algorithms.
However if the problem you are facing is that the volume is too low, try amplifying the synthesized noise by multiplying the result by a factor ex.: pinkNoise = pinkNoise * 100
This might do the trick: compute the mean power in your spectrum from the amplitude A = A(f), where f is the frequency.
P = mean(A.^2);
Spread that over your frequency range:
N = length(f);
invfnorm = 1./[1:N];
Anew = sqrt(P*invfnorm/sum(invfnorm));
Anew has the property of having the same total power density as the original spectrum, and power decaying as 1/f.
Substitute Anew for A and inverse FFT your new spectrum to generate the new waveform.

FFT: Match samples to frequency

let us assume,
I have a vector t with the times in seconds of my samples. (These samples are not equally distributed on the time domain.
Also I have a vector data containing the samplevalues at the time t.
t and data have the same length.
If I plot the graph some sort of periodical signal is obtained.
now I could perform: abs(fft(data)) to get my spectrum, which is then plotted over the amount of data points on the x-axis.
How can I obtain my spectrum regarding the times in vector t and plot it?
I want to see which frequencies in 1/s or which period in s my signal contains.
Thanks for your help.
[Not the OP's intention]: FFT will give you the spectrum (global) for any number of input data points. You cannot have a specific data point (in time) associated with parts (or the full) spectrum.
What you can do instead is use spectrogram and obtain the Short-Time Fourier Transform (STFT). This will give you a NxM discrete grid of time-frequency FT values (N: FT frequency bins, M: signal time-windows).
By localizing the (overlapping) STFT windows on your data samples of interest you will get N frequency magnitude values, thus the distribution of short-term spectrum estimates as the signal changes in time.
See also the possibly relevant answer here: https://stackoverflow.com/a/12085728/651951
EDIT/UPDATE:
For unevenly spaced data you need to consider the Non-Uniform DFT (and Non-uniform FFT implementations). See the relevant question/answer here https://scicomp.stackexchange.com/q/593
The primary approaches for NFFT or NUFFT, are based on creating a uniform grid through local convolutions/interpolation, running FFT on this and undoing the convolutional effect of the interpolation filter.
You can read more:
A. Dutt and V. Rokhlin, Fast Fourier transforms for nonequispaced data, SIAM J. Sci. Comput., 14, 1993.
L. Greengard and J.-Y. Lee, Accelerating the Nonuniform Fast Fourier Transform, SIAM Review, 46 (3), 2004.
Pippig, M. und Potts, D., Particle Simulation Based on Nonequispaced Fast Fourier Transforms, in: Fast Methods for Long-Range Interactions in Complex Systems, 2011.
For an implementation (with an interface to MATLAB) try NFFT and possibly its parallelized version PNFFT. You may find a nice walk-through on how to set-up and use here.
You can resample or interpolate your sample points to get another set of sample points that are equally spaced in t. The chosen spacing or sample rate of the second set of equally spaced sample points will allow you to infer frequencies to the result of an FFT of that second set.
The results may be noisy or include aliasing unless the initial data set is bandlimited to a sufficiently low frequency to allow interpolation. If bandlimited, then you might try something like cubic splines as an interpolation method.
Although it may look like one can get a high FFT bin frequency resolution by resampling to a larger number of data points, the actual useful resolution accuracy will be more related to the original number of samples.

How to get coefficients for sine/cosine function from complex FFT in Matlab?

I'm working on a control system that measures the movement of a vibrating robot arm. Because there is some deadtime, I need to look into the future of the somewhat noisy signal.
My idea was to use the frequencies in the sampled signal and produce a fourier function that could be used for extrapolation.
My question: I already have the FFT of the signal vector (containing 60-100 values e.g.) and can see the main frequencies in the amplitude spectrum. Now I want to have a function f(t) which fits to the signal, removes some noise, and can be used to predict the near future of the signal. How do I calculate the coefficients for the sine/cosine functions out of the complex FFT data?
Thank you so much!
AFAIR FFT essentially produces output as a sum of sine functions with different frequencies. The importance of each frequency is the height of each peak. So what you really want to do here is filter out some frequencies (ie. high frequencies for the arm to move gently) and then come back to the time domain.
In matlab this should be like going through the vector of what you got from fft, setting some values to 0 (or doing something more complex to it) and then use ifft to come back to time domain and make the prediction based on what you get.
There's also one thing you should consider while doing this - Nyquist frequency - this means that the highest frequency that you get on your fft is half of the sampling frequency.
If you use an FFT for data that isn't periodic within the FFT aperture length, then you may need to use a window to reduce spurious frequencies due to "spectral leakage". Frequency estimation techniques to better estimate "between bin" frequency content may also be appropriate. The phase of each cosine sinusoid, relative to the edge of the window, is usually atan2(imag[i], real[i]). The frequency depends on the sample rate and bin number versus the length of the FFT.
You might also want to look into using a Kalman filter instead of an FFT.
Added: If your signal isn't exactly integer periodic in the FFT length, then you may want to do an fftshift before the FFT to move the resulting phase measurement reference point to the center of your data vector, instead of a possibly discontinuous circular edge.