DATAWRAP

12 views (last 30 days)
Cesare
Cesare on 28 Mar 2011
Answered: Zeeshan Salam on 5 Nov 2019
I've noticed that MATLAB uses datawrap to compute spectra (or spectrum-related quantities) when the user asks for a number NFFT of frequencies that is smaller than the WINDOW-LENGTH/2+1 (if WINDOW-LENGTH is even) rule. Essentially datawrap chuncks the data into smaller segments and then averages the segments together. Am I right? Since I think that this would really be bad for my data: why is it implemented like that? and why is it not documented in the helps? Many thanks in advance, Cesare
  1 Comment
Honglei Chen
Honglei Chen on 28 Mar 2011
Could you be more specific about where you see this? I don't see why WINDOW-LENGTH/2 is so special. Maybe I'm missing something.

Sign in to comment.

Answers (4)

Cesare
Cesare on 30 Mar 2011
I'll try to be more precise. For real time series of length N the spectral functions usually return N/2+1 frequency bins if N is even and (N+1)/2 if N is odd. However, functions as SPECTROGRAM have the option to specify the number of output bins through an input variable which is usually called NFFT. I digged into the code and found out that what these functions do when NFFT is smaller then the default number of bins, is to wrap the data. This means that the data array is cut into smaller chuncks which are then averaged together. This is not documented in the function help and I wonder whether it is good practice. Cesare

Honglei Chen
Honglei Chen on 30 Mar 2011
Hi Cesare,
If I understand your question correctly, your problem is more related to why MATLAB wrap the data, the particular length is just a specific case. I'll try to explain the reason for wrapping the data.
The calculation of signal spectrum, such as periodogram, uses FFT internally, where the length of FFT is denoted as NFFT. In theory, when using FFT, the signal in both time domain and frequency domain are discrete and periodic, where the period is given by NFFT. Hence, if you specify an NFFT that is less than the signal length, it actually introduces the aliasing in the time domain and make the signal (even if its length is N>NFFT) periodic with NFFT. When you take FFT of this sequence, you are working with this aliased sequence. This is what datawrap do for you.
For example, if you have a sequence 1 2 3 4 5, assuming that your period is also 5, you have
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
--------------------------------
... 1 2 3 4 5 ...
i.e., your original series. Now assume you have a period of 3, then it looks like
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
------------------------
... 5 7 3 ...
A sequence that is wrapped around and has only a length of 3. Note that
>> datawrap(1:5,3)
ans =
5 7 3
HTH.

Cesare
Cesare on 28 Feb 2012
The signal need not be periodic, take for example autoregressive models. They have a very well defined periodogram but are not necessarily periodic. I believe that the internal wrapping could end up in dangerous phase cancellation without the user knowing it. Cesare
  1 Comment
Honglei Chen
Honglei Chen on 28 Feb 2012
Your signal may not be periodic to start with. But if you use FFT, it samples the signal in both time and frequency, which in turn makes the signal periodic in both frequency and time, and that's where the circular convolution behavior kicks in.

Sign in to comment.


Zeeshan Salam
Zeeshan Salam on 5 Nov 2019
how i wrap these two curves?
%define x for both curves
x_ref = 0:0.01:1;
x = 0:0.01:1;
%define the reference curve and the other curve
c_ref = sin(x_ref*2*pi);
y = 0.5+0.5*sin(x*2*pi);
%plot both curves
figure(1)
plot (x_ref,c_ref,'r');
hold on
plot(x,y,'b');
axis([min(x_ref)-1,max(x_ref)+1,min(c_ref)-1,max((c_ref))+1]);
legend('c_{ref}','y')

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!