0
$\begingroup$

I just filtered a only positive signal with the following filter which is a bandpass filter with the following characteristics:

Frequency Characteristic of bandpass filter

%the filter
numer = [0.2 0.1 0 -0.1 -0.2];
denom = [1 -0.94];

I filter a only positive signal with this filter by applying:

y = filter(numer, denom, signal);

The question is: Why does a filter with only positive inputs yield negative values? What can I do about it? (Can't possibly plot the result of the filtering on a dB scale because there is no dB of negative values)

Sorry for the beginner question I searched the web extensively before posting here (but couldn't find an answer).

$\endgroup$
1
  • $\begingroup$ @MarcusMüller: nope. The impulse response is all positive. $\endgroup$
    – Hilmar
    Jun 8, 2018 at 12:24

2 Answers 2

3
$\begingroup$

Looking at your plots, your filter has attenuation at f=0. In effect, you are subtracting a constant from your data, shifting it so that some of it negative.

Subtracting the mean from a set of numbers will centralize it on zero.

$\endgroup$
6
  • $\begingroup$ how can I reverse the effect in the end result? Where can I learn more about this? $\endgroup$
    – Alon
    Jun 8, 2018 at 13:44
  • 1
    $\begingroup$ Use low pass instead of band pass is one solution. Another is to find the minimum values of the filtered data, which will be negative and subtract ( subtract a negative ) that constant from the data. Which is better depends on your application $\endgroup$
    – user28715
    Jun 8, 2018 at 14:07
  • $\begingroup$ In terms of where you can learn more, books are never narrowly tailed to a specific understanding, they have a lot of other things in them and the path is never direct. This place is a good place to ask questions but not a perfect place. An in the flesh teacher or consultant is the best but that isn’t free. Experiment Experiment Experiment... $\endgroup$
    – user28715
    Jun 8, 2018 at 14:19
  • $\begingroup$ Thanks for your input Mr. Pawlukiewicz ! Do you mind explaining why it is valid to just add a offset to the filtered data? I cannot imagine how the "most negative" value of the filtered data is the correct offset to add... $\endgroup$
    – Alon
    Jun 8, 2018 at 14:29
  • 1
    $\begingroup$ Subtracting the minimum value (which is negative) is the smallest shift that makes all the numbers positive $\endgroup$
    – user28715
    Jun 8, 2018 at 16:38
2
$\begingroup$
  1. Your impulse response is all positive. You only have one negative coefficients and that's in the denominator, so it flips to positive in the difference equation
  2. If you filter a positive signal with a positive impulse response, you will get a positive result. You can verify this bey evaluating $min(y)$, that should be equal or greater than zero
  3. If you do simply type $plot(y)$, you should see an all positive signal
  4. If you plot anything in dB you will also see negative values. That simply means the original value is smaller than 1.
  5. It rarely makes sense to plot a time domain signal in dB. Typically you would do a spectral analysis first

EDIT:

The filter you show in the graph and the filter you show in the code are not the same. The code is a lowpass filter, the graph is a bandpass. The bandpass will indeed have negative values in the impulse response.

$\endgroup$
5
  • $\begingroup$ 1. I know / 2. I know / 3. I know / 4. I know / 5. I know.. Please answer the question $\endgroup$
    – Alon
    Jun 8, 2018 at 13:15
  • $\begingroup$ Thanks for pointing this out! I forgot the "-" sign in front of the last two coefficients! $\endgroup$
    – Alon
    Jun 8, 2018 at 13:55
  • $\begingroup$ You say the bandpass will indeed have negative values in the impulse response, how is this possible? Tell me everything you know please! $\endgroup$
    – Alon
    Jun 8, 2018 at 13:55
  • $\begingroup$ Why would it NOT be negative: If you have negative coefficients, you'll subtract numbers. If you subtract numbers you will occasionally get negative numbers. It's hard to help you unless you explain, why you would think this should be positive only. Nothing in the math says, it would be that way $\endgroup$
    – Hilmar
    Jun 8, 2018 at 16:12
  • $\begingroup$ When you look at at transfer function you only see attenuation, not subtractions, am I right? The signal gets weaker or stronger but only in terms of percentages, e.g. -3dB is 50%. Or at -200dB the signal is attenuated by 99.99...%. But it never changes algebraic sign, does it? $\endgroup$
    – Alon
    Jun 12, 2018 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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