Reputation: 129
I have the coefficients of an FIR filter,b0-b31, and I am trying to plot the magnitude and phase response of the filter.
coeff = [-8 -2 9 16 20 15 3 -19 -36 -41 -26 11 69 126 187 208 208 187 126 65 11 -26 -41 -36 -19 0 15 20 16 10 -2 -8];
when I plot it using freqz, it gives me magnitude that's not normalized as shown below:
I am using:
freqz(coeff, 1,[],5000000)
Is there a way to get the normalized plot of the magnitude and phase in the y-axis? Meaning, the maximum of the magnitude is 0 and the graph starts from it? Like the graph shown below:
Upvotes: 1
Views: 2598
Reputation: 899
There are many possibilities:
A) One way is to tell fvtool to normailize the output
fvt = fvtool(....)
fvt.NormalizeMagnitudeto1 = 'on';
B) The other option is to normalize your coefficients in the following way:
normalize_coeff=coeff/sum(coeff);
calling now
freqz(normalize_coeff, 1,[],5000000)
will result in your desired frequency magnitude response.
As mentioned before to get both in one plot you can use fvtool.
Or you first calcultate the frequency response using the command freqz
fs=5000000;
[H,F]=freqz(normalize_coeff, 1,[],fs);
and the phase response by using:
[phi,w] = phasez(normalize_coeff,1,fs);
and you plot both results into one graph
figure(1001)
plot(w,phi,'r')
hold on
plot(pi*(F/(fs/2)),20*log10(abs(H)))
hold off
legend('phase','magnitude')
For different y-axis you can also use the command plotyy.
Upvotes: 2
Reputation: 22214
One approach is to compute the DC gain using the output of freqz
then plot the normalized filter using fvtool
.
Example:
coeff = [-8 -2 7 16 20 15 0 -19 -36 -41 -26 11 65 126 178 208 208 178 126 65 11 -26 -41 -36 -19 0 15 20 16 7 -2 -8];
[h,w] = freqz(coeff);
fvtool(coeff/h(1),'freq');
Upvotes: 1