get specific magnitude response value given a specific frequency from a freqz graph

2 views (last 30 days)
Hi Team,
I have plotted a Magnitude response vs Normalized frequency graph through freqz. I would like to calculate the corresponding magnitude response values for specific normalized frequencies without having to observe on the graph.
e.g for a normalized frequency value of 0.3pi rad/sample i expect this much DB from the graph. Kindly assist.
See my code snippet so far: Given a H(z):
[b,a] = tfdata(Hz,'v');
figure(2);
freqz(b,a)

Accepted Answer

Issa
Issa on 14 Jul 2022
Edited: Issa on 14 Jul 2022
Hi!
Try this:
% Since you did not share Hz, I am loading tfData.mat
load('tfData.mat','sys1');
Hz = sys1 ;
[b, a] = tfdata(Hz) ;
% Convert a and b from cell to mat
a = cell2mat(a) ;
b = cell2mat(b) ;
[h,w] = freqz(b,a) ;
% Convert to db and rad/sample
h = 20*log10(abs(h)) ;
w = w/pi ;
% e.g for a normalized frequency w(200) (normalized freq at index 200),
% the magnitude is:
w_eg = w(200) ;
h_eg = h(w == w_eg) ;
disp("The magnitude at " + w_eg + " rad/sample is " + h_eg + " dB")
The magnitude at 0.38867 rad/sample is -1.8019 dB
% Let's plot the magnitude and compare with freqz() plot
figure
plot(w,h)
xlabel("Normalized Freq (rad/sample)")
ylabel("Magnitude (dB)")

More Answers (1)

Paul
Paul on 14 Jul 2022
Edited: Paul on 14 Jul 2022
freqz accepts a third argument that allows the user to specify the desired angular frequencies to evaluate (it must have at least two elements)
h = freqz(b,a,w);
absh = abs(h) % magnitude respose
% or
absh = abs(freqz(b,a,w));

Community Treasure Hunt

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

Start Hunting!