2
$\begingroup$

I am new in matlab and signal processing. The time series that have been used are obtained from accelerometer in a building. As far as I understand both the time series' length and window function length(hamming or hanning) should be same. But for smoothing the fourier amplitude spectrum, optimum window length can vary. How this procedure should be apply in matlab?

How can apply a window function that is shorter than my time series.

Thanks for reading!

$\endgroup$
  • $\begingroup$ What do you mean by "optimum window length can vary"? Are you interested in how the spectrum changes with time or do you want a static spectrum of the whole time series? $\endgroup$ – Matt L. Jun 5 '13 at 8:54
  • $\begingroup$ postimg.org/image/444jyova1 I want to use this method. (spectrum will not vary with time). Window length can be optional. Should ı use overlap or something else? I really confused about using the method. $\endgroup$ – sedef Jun 5 '13 at 9:08
  • $\begingroup$ correct me if i am wrong. i have been trying to find how to apply it in my algorithm . here it is: hamming(other window filters) is applied on the time domain. and its applied before FFT . you multiply output of window function for nth index with you data at the same index program main // data is audio signal data var windowed = new short[data.Length] ; for (int i = 0; i < data.Length; i++) { windowed[i] = (short) (data[i] * HammingWindow( i , data.Length)) ; } // in order to show that windowing is appled before fft var fftResult = FastFourierTransform(windowed ) ; function /// n: Index into f $\endgroup$ – bh_earth0 Nov 21 '16 at 17:18
4
$\begingroup$

The window length should be equal to your transform length, not necessarily the length of your entire data set. The two are the same, of course, if you are going to transform the entire data set at once, but if you are planning to do shorter transforms then you should make the window length equal to the length of those transforms.

$\endgroup$
  • $\begingroup$ Than you so much, I think ı understand what you mean. Also is it proper to add zero path both side of the hanning window, for shorter the transforms as you mentioned? $\endgroup$ – sedef Jun 5 '13 at 14:20
  • 2
    $\begingroup$ No, you should not zero pad unless you have to. Since the length of your transform is less than the length of your data, you don't need to. $\endgroup$ – Jim Clay Jun 5 '13 at 16:59
3
$\begingroup$

Just like what Jim says, unless you are FFT-ing the entire data set at once, without splitting the data into shorter frames, then you will most likely use the length of data set. A quick example is shown below.

Ts = 50e-6;                  % Sampling Time(s)
Fs = 1/Ts;                   % Sampling rate, Sampling Freq (Hz)
f0 = 50;                     % Frequency of interest (Hz)
duraT = 1;

%Calculate time axis
dt = 1/Fs;
tAxis = dt:dt:(duraT-dt);

y = cos(2*pi*f0*tAxis) +  2*sin(2*pi*10*tAxis);   y=y';

L = length (y); % Window Length of FFT    
nfft = 2^nextpow2(L); % Transform length

y_HannWnd = y.*hanning(L);            
Ydft_HannWnd = fft(y_HannWnd,nfft)/L;

   % at all frequencies except zero and the Nyquist
   mYdft = abs(Ydft_HannWnd);
   mYdft = mYdft (1:nfft/2+1);
   mYdft (2:end-1) = 2* mYdft(2:end-1);

f = Fs/2*linspace(0,1,nfft/2+1); 

  figure(1),
  subplot(2,1,1)
  plot(tAxis,y)
  title('Time Domain y(t)');
  xlabel('Time,s'); 
  ylabel('y');
  subplot(2,1,2)  
  plot(f,2*mYdft); % why need *2 ? Bcoz, Hanning Wnd Amplitude Correction Factor = 2
  axis ([0 500 0 5]); %Zoom in 
  title('Amplitude Spectrum with Hann Wnd');
  xlabel('Frequency (Hz)with hanning window'); 
  ylabel('|Y(f)|');
$\endgroup$
  • $\begingroup$ This code is wrong. You are using wrong correction factor for the amplitude. $\endgroup$ – jojek May 4 '16 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.