Changing magnitude to decibel in freqs plot

조회 수: 43 (최근 30일)
Joshua Brown
Joshua Brown 2019년 10월 30일
답변: Roshni Garnayak 2019년 11월 5일
I have the following transfer funtion for a analogue low pass filter:
39.476/(s^2+8.886 s+39.476)
I am using "freqs" to plot the frequency:
a=[1,8.886,39.476]
b=39.476
w=logspace(-1,3)
freqs(b,a,w)
However I want my plot to show magnitude in decibels, i have tried the mag2db command but that is messig with the results, any suggestions?

답변 (1개)

Roshni Garnayak
Roshni Garnayak 2019년 11월 5일
You can store the output of ‘freqs’ in a variable, say h. The following line of code would give you the magnitude in decibels:
mag = mag2db(abs(h));
For plotting the magnitude and phase response, you can use the ‘semilogx’ function which plots the x-axis in log scale and the y-axis in linear scale. You can find the code for that below:
h = freqs(b,a,w);
mag = mag2db(abs(h));
phase = angle(h);
phasedeg = phase*180/pi;
subplot(2,1,1), semilogx(w,mag), grid on
xlabel 'Frequency (rad/s)', ylabel Magnitude
subplot(2,1,2), semilogx(w,phasedeg), grid on
xlabel 'Frequency (rad/s)', ylabel 'Phase (degrees)'
For further capabilities of the ‘freqs’ function, refer to the examples in the following documentation:https://www.mathworks.com/help/signal/ref/freqs.html

카테고리

Help CenterFile Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by