1
$\begingroup$

I am working on filtering of data using the Moving average filter in MATLAB.

My data is recorded temperature values on the Y-axis and Time(in seconds) on the X-axis

(I'm getting the magnitude response curve of the Moving average filter as attached)

enter image description here

The shape of the curve seems fair for the moving average filter, according to the theory but,

I want to ask, why am I getting all the magnitude value for MA filter positive? (is this correct?)

Implementing other filters like Butterworth etc. on the same data gives the magnitude values to be negative (image attached)

enter image description here

Here is my MATLAB Code for MA (if it helps)

%T.Temp is table column containing Temperature values in double format.

MovAvg = dsp.MovingAverage(5)

movAvgOut = MovAvg(T.Temp)

fvtool(movAvgOut)

%Gives output the first image I attached

Any help is appreciated. Thank you.

Ps - DSP is not my field. This work is part of a bigger project i'm involved in, and need some help. Please bear with me if I sound irrational.

$\endgroup$
  • $\begingroup$ What are your coefficients? All ones? $\endgroup$ – jojek Jul 21 at 12:45
  • $\begingroup$ Just shift your vertical scale. They are not based the same. $\endgroup$ – Cedron Dawg Jul 21 at 12:48
  • $\begingroup$ @jojek I have implemented MA using the sliding window, and as per the documentation, in this - all values are given equal importance/weightage. So, Yes, I guess all coefficients are 1. $\endgroup$ – varungupta Jul 21 at 18:55
  • $\begingroup$ @CedronDawg Do have any insight on how I can shift the vertical scale? $\endgroup$ – varungupta Jul 21 at 18:56
  • 1
    $\begingroup$ Well, you are using fvtool for visualizing spectrum of your data, not the actual filter. If you want to visualize things the way you want, use fft routine, scale the output with 0 dB being a particular value that you want and plot it. Values of temperature are much higher than 1, so it's normal you get levels higher than 0 dB. (Not sure what would be the meaning of 0 dB for temperature anyway...). Alternatively do this trick. In fvtool click Analysis, Analysis parameters and tick Normalize amplitude to 1 (0 dB). This will normalize the values so that maximum is always 0 d. $\endgroup$ – jojek Jul 21 at 19:23
1
$\begingroup$

A true moving average would have unity gain coefficients but also be divided by the total number of samples (as per the definition of average). This is trivial since it is just a scaling factor, but if the OP divides the output of the moving average by the total number of samples in the filter then the magnitude response will be normalized to 0 on a dB scale, with all other magnitude values given in negative dB.

| improve this answer | |
$\endgroup$

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.