MATLAB Answers

why freqz with b [1] is different from freqz with b [1,0]

1 view (last 30 days)
christian Alvarado
christian Alvarado on 12 Jun 2020
Commented: Paul on 17 Jun 2020
I have the following code:
Function FilterFIR(b)
title('Respuesta en frecuencia');
but I get different answers with b [1] and b [1,0]
According to me they should be equivalent because 0 does not affect
Please someone who can explain why


Sign in to comment.

Accepted Answer

Paul on 13 Jun 2020
They should be equivalent and it appears that they basically are:
>> which freqz -all
C:\Program Files\MATLAB\R2019a\toolbox\signal\signal\freqz.m
>> w=0:(pi/100):pi;
>> h1=freqz(1,1,w);
>> h2=freqz([1 0],1,w);
>> max(abs(h1-h2))
ans =
Are you seeing a difference more substantial than this? If so, are you sure you're using freqz from the signal processing toolbox and not some other version on your path?
Frankly, I'm not sure why there's any difference at all based on how freqz works according to its doc page.


christian Alvarado
christian Alvarado on 13 Jun 2020
I also don't know why the difference (it shouldn't), but thank you very much, as I only saw the graph I thought that the difference was bigger
Paul on 14 Jun 2020
I did a bit more investigating and found that freqz works as follows for the FIR case:
When b = 1, it literally evaluates:
h = 1/1;
But, when b = [1 0], it evaluates:
That result should, of course, be equal to 1, but for some values of w it doesn't quite equal 1 exactly. Don't know why. But I started a new thread here in case there is interest:
Paul on 17 Jun 2020
I also want point out that in the general case where length b>2, there is antoher complication. For example if
b = [1 0 0 0]
then freqz computes:
exp(1i*w)^3 / exp(1i*w)^3.
However, the way the numerator is computed (using polyval) is different than the way the denominator is computed (exp(1i*w*3)), which can also result in a small error relative to the expected result.

Sign in to comment.

More Answers (0)


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!