Search code examples
matlabsignal-processing

why then FIR filter generated by Matlab design does not apply properly?


The code is simple:

N = 40;
fs = 20 * 10 ^ 9;
freq = [0, 1 * 10 ^ 9, 2 * 10 ^ 9, 3 * 10 ^ 9, 5 * 10 ^ 9, 7.5 * 10 ^ 9, 10 * 10 ^ 9]
mag  = [1, 1,          1,          0.3,        0.1,        0.005,        0.001]

d = fdesign.arbmag('N,F,A', N, freq, mag, fs);
W = [1, 1, 1, 1, 1, 1, 1];
fir = design(d, 'equiripple', 'weights', W, 'SystemObject', true);

sents = ones(1, 300) * 1.0;
rcvds = fir(sents);

% plot
figure(1)
stem(sents)
hold on
stem(rcvds)
legend('sents', 'received')

It should be low-pass. I input a DC signal. But the output signal is extremely small: enter image description here

By viewing freqz, the filter seems to be designed properly: enter image description here


Solution

  • Your filter is correct, checking with freqz, you can even give it a step response, which is what your DC signal is doing (going directly to a value from 0). Here is the result of this:

    results of step

    The problem is that you are giving it the data as a row, so the filter is applied on every column. Which means you end up with a row, where every column in that row is considered a signal to be filtered. To fix, use this: sents = ones(1, 300)' * amplitude;

    After that, your plot will look like this:

    corrected plot