I'm attempting to compute a phase-lag index for two signals. In order to do this I must first obtain a cross spectrum density in the time domain for the two signals.
I've experimented somewhat with the wcoher function in matlab, but the input required is assumed to be in scales. I am struggling to understand the relationship between scale and frequency, and particularly how one would convert desired frequencies (between 2 and 150 hz) to scales for coherence computation.
Any helpful resources would be appreciated.
It all depends on wavelet i.e. mother wavelet, and sampling frequency. For example take the simplest case i.e. the Morlet Wavelet that has approximately 1:1 between the wavelet central frequency and the Fourier frequency. Use a Matlab function scal2frq to convert scales to frequency. For your case i.e. at sampling frequency of 256 Hz, 2.08 Hz of Fourier frequency corresponds to wavelet scale of 100, and wavelet scale of 1.4 corresponds to 148.57 Hz.
In its very simplest and loosest form (for just understanding), scale and Fourier frequencies are inversely proportional to each other.
Read: A practical guide to wavelet analysis by C.Torrence.
Related
As above lets Fs is sampling frequency, L is signal's length and t is time range.
As using mdwtdec in Matlab in order to decompose multi-raw signal into specific frequency band, I just notice that decomposed signal's length at 1st level is split into half, and keep slit into half of 1st level signal at 2nd level.
Raw signal's time range calculation: t = 0 --> (L/Fs)
My question is in every decomposition level the Sampling frequency Fs is still the same? and at every decomposition level how I can calculate the time range of each Detail and Approximation coefficient.
Also as verify the frequency band of Discrete Wavelet Transform I applied FFT at each level following this post: https://jp.mathworks.com/help/matlab/ref/fft.html?lang=en
According to this post my first question need to be answered.
Thank you very much.
I'm pretty positive that in discrete wavelet transform, the time series data or signals, if we wish, would be downsampled by a factor of 2, which means that if we would be having 2^10 or 1024 datapoints in our original time series data, in the first level, it would be divided into 2 and our level one sampling frequency would be 2^9 or 512, in second level would decrease to 256, and so on.
However, in continuous wavelet transform, it would most likely remain the same.
Based on the references, I copy some codes here that you might want to test and see, you might want to reduce the number of levels and Fs here and you can define your own x if you wish:
Fs = 1e6;
t = 0:1/Fs:1-1/Fs;
x = cos(2*pi*50*t);
[C,L] = wavedec(x,15,'db4');
details = detcoef(C,L,'cells');
d14recon = wrcoef('d',C,L,'db4',14);
plot(d14recon,'k');
d13recon = wrcoef('d',C,L,'db4',13);
hold on;
plot(d13recon,'r'); %look how small the amplitude is
a13recon = wrcoef('a',C,L,'db4',13);
plot(a13recon,'b');
Useful Links:
I'm not expert about it, you can likely read more about it and find out your desired information. There are also lots of YouTube videos about it.
Discrete wavelet transform relation to sampling frequency of the signal
Single-level discrete 2-D wavelet transform
How can I generate 500 ms worth of noise sampled at 1280 Hz, with a flat frequency distribution between 0.1 - 640 Hz and normally distributed amplitude values?
See the screenshot below for an illustration of the desired output.
Timeplot of waveform, frequency distribution, and histogram of amplitudes
The parameters of your question make the answer trivial:
640 Hz is exactly half of 1280 Hz, so this is the highest frequency (Nyquist) in the Fourier decomposition;
0.1 Hz is way below 1 / 500ms = 2Hz, which is the frequency resolution of your Fourier decomposition, and therefore the lowest positive frequency you can control.
So in your case, the "band-limited" constraint is trivial, and you can simply generate the desired noise with:
duration = 500e-3;
rate = 1280;
amplitude = 500;
npoints = duration * rate;
noise = amplitude * randn( 1, npoints ); % normally distributed white noise
time = (0:npoints-1) / rate;
However, more generally, generating noise in a specific frequency band with constraints on spectrum shape (eg flat) and value statistics (eg normally distributed) can be difficult. There are two simple approximations I can think of:
Working in the time-domain, first enforcing constraints on value statistics by drawing from the distribution of choice, and then filtering the resulting signal using a band-pass FIR filter for example. For this approximation, note that the filter will also affect the distribution of values, and so in general your constraints on value statistics will be poorly met unless you design the filter very carefully.
Working backwards from the Fourier domain, first enforcing constraints on the amplitude coefficients, taking random noise for the phase, and using an inverse transform to come back to the time-domain. For this approximation, note that the phase distribution will affect the temporal distribution of values in non-trivial ways, depending on the amplitude constraints, and that if your sampling rate is much larger than your frequency cutoff, you might need to enforce constraints on harmonic amplitudes as well in order to avoid artefacts.
let us suppose that we have modeled signal using AR model, and suppose we have following model
i used spectral estimation function from matlab
pyulear
now frequencies are given in normalized frequencies and i would like to know how to convert it into real frequencies?from there it is clear that we have four deterministic model and also plus some white noise,actual i want to know approximate frequencies in each deterministic model,i can of course determine this frequencies uisng FFT,periodogram and so on,but i am studying application of AR/ARMA model,so in case of i have such frequencies and pictures,how can i determine actual frequencies?thanks in advance
The frequency is normalized in radians/second where pi is the normalized Nyquist frequency in radians/second. To be able to get the real frequency in radians/s, then scale the f axis with 1/T where T is the sampling time. To then get the frequency in Hz, divide the now scaled frequency with pi.
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.
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.