If we have a set of time series data, y, consisting of 100 data points. One can apply a N (odd) Hamming window as a weighted moving average to decrease the noise. Say, if we choose 7 point Hamming window, H, [0.0800 0.3100 0.7700 1.0000 0.7700 0.3100 0.0800], and perform a weighted moving average on y. In Matlab, I am doing conv(y, H./sum(H), 'same').

Since this is a convolution, I am wondering that by convolution theorem, one should be able to obtain identical results in Fourier domain, because convolution should become multiplication in the Fourier domain.

However, the FFT of y will have 100 complex numbers, and Hamming window will also have 7 complex numbers. What would be an equivalent operation of a weighted moving average in the Fourier domain?



Fistly, you need to pad the data (y) and the filter (Hamming window). The minimum required length to avoid circular convolution = data length + filter length - 1. In this case, it is 100 + 7 - 1 = 106. For convenient, you may choose power of 2 length, in this case 128.

So, pad the data to 128, do fft on it.

Pad the filter to 128, do fft on it.

Multiply both ffts.

Do ifft.

  • $\begingroup$ Thanks. It works. However there is a minor nuance. Notice that in the Matlab code, conv(y, H./sum(H), 'same'), was used because it is equivalent to a centered moving average. This process keeps the peak position at the identical place. In the Fourier domain, the peak position is moving to the right, which is equivalent to conv(y, H./sum(H)). Is there any trick to avoid that? $\endgroup$ – M. Farooq Jul 18 '19 at 3:27
  • 1
    $\begingroup$ @M.Farooq Just discard the first 3 values, based on the reference. But if you don't want to do that, you may pad the filter as H = {1, 0.77, 0.31, 0.08, ...padding..., 0.08, 0.31, 0.77} $\endgroup$ – mfcc64 Jul 18 '19 at 6:02
  • $\begingroup$ Discarding the edge points works very well. Just curious, what is the mathematical basis of re-ordering the set of Hamming values before convolution. $\endgroup$ – M. Farooq Jul 18 '19 at 19:53
  • $\begingroup$ @M.Farooq Shifting 3 points to the left (cyclically) makes the filter zero-phase. Zero-Phase Filters $\endgroup$ – mfcc64 Jul 19 '19 at 8:21

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.