Matlab function freqz gives wrong amplitude in dB

8 visualizzazioni (ultimi 30 giorni)
Hello guys,
i want to compute und plot the filter amplitude response and want to compare it with the filterDesigner function from Matlab.
For that i use this Code:
fs = 1200; Ts = 1/fs;
filterCoff = Filter1, %% FIR lOWPASS Filter
%% Plot of the amplitude response in db
figure(1);
plot(w/(2*pi*Ts),mag2db(abs(h)));
xlabel('Normalized Frequency (Hz)')
ylabel('Magnitude');
I tried everythink, but i dont get the same solution as the filterDesigner.

Risposte (2)

Star Strider
Star Strider il 2 Mag 2022
I do not see any call to freqz, or the designed filter, so I cannot test this.
What you are seeing may be a frequency-axis resolution problem. The freqz function has the option of choosing the length of the Fourier transform used to plot the Bode plot as the second (or third argument, depending on how the filter is defined), and I usually choose 2^16 for this. A higher value results in a more accurate plot with increased frequency resoution.
If the highest frequency in the passband is not the first frequency, the freqz function does not always scale the amplitude axis so that the highest amplitude is always 0 dB, so it may seem as though the filter is amplifying even though it is not. The relative amplitudes are nevertheless correct.
For freqz, also using:
set(subplot(2,1,1), 'YLim',[-130 0])
(in this instance) may make the plots more comparable by improving the amplitude resolution.
.
  9 Commenti
hans petersen
hans petersen il 10 Mag 2022
First of all thank you for your help. I think i understood. I plot the same filter with 2^12 and 2^16 and the plots are the same. The only Difference is in the length of the vertikal lines.
Is this explanation correct?
The reason Why the vertical lines dont have the same length is just a mathematical issue. Somethink like rounding and decimal point operations. For The performance of the digital filter we have to look on the high points of the individual parabolas.
Star Strider
Star Strider il 10 Mag 2022
My pleasure.
Is this explanation correct?
Essentially, yes. The difference is in the fft frequency resolution and therefore the plot resolution. The underlying data is the same.
For The performance of the digital filter we have to look on the high points of the individual parabolas.’
The entire filter is important with respect to the actual filtered signal. The filter is not linear in the stopband, however the variations do not matter because the stopband frequencies are significantly attenuated.
.

Accedi per commentare.


hans petersen
hans petersen il 3 Mag 2022
Hi,
sorry. This is the whole Code:
fs = 1200; Ts = 1/fs;
filterCoeff = Filter1
[h,w] = freqz(filterCoeff,1);
figure(1);
plot(w/(2*pi*Ts),mag2db(abs(h)));
xlabel('Normalized Frequency (Hz)');
ylabel('Magnitude (dB)');
% The FIR Filter Coefficient:
Filter1 = [
0.000178232054708589,
0.000709878618964491,
0.001585843072655027,
0.002791137421116118,
0.004305138743876396,
0.006101942058544247,
0.008150803562238728,
0.010416666666580653,
0.012860761825639317,
0.015441269893612304,
0.018114037662004680,
0.020833333333267912,
0.023552629004535204,
0.026225396772939561,
0.028805904840931838,
0.031250000000016098,
0.033515863104388588,
0.035564724608116896,
0.037361527922819888,
0.038875529245614424,
0.040080823594106516,
0.040956788047822303,
0.041488434612095185,
0.041666666666809973,
0.041488434612095185,
0.040956788047822303,
0.040080823594106516,
0.038875529245614424,
0.037361527922819888,
0.035564724608116896,
0.033515863104388588,
0.031250000000016098,
0.028805904840931838,
0.026225396772939561,
0.023552629004535204,
0.020833333333267912,
0.018114037662004680,
0.015441269893612304,
0.012860761825639317,
0.010416666666580653,
0.008150803562238728,
0.006101942058544247,
0.004305138743876396,
0.002791137421116118,
0.001585843072655027,
0.000709878618964491,
0.000178232054708589
];
With this Code my frequencies are near to the frequencies of the filterDesigner Tool, but my Amplitude is absolutely different.
Thank you for your help.

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by