[MATLAB] Analyze the frequency response and phase response of its continuous time system according to a given system transfer function

a = [1 0.4 1]; % 滤波器的分母多项式系数
b = [0.2 0.3 1]; % 滤波器的分子多项式系数
w = logspace(-1,1); % 生成从10^-1到10^1的对数均匀分布的100个数字
h = freqs(b,a,w); % 求取滤波器在频域的复频率响应
mag = abs(h); % 复频率响应的幅度
phase = angle(h); % 复频率响应的相位
phasedeg = phase*180/pi; % 相位转换为角度

subplot(2,1,1); % 将画图区域分成两个子图,第一个子图
loglog(w,mag); % 使用对数坐标画幅频曲线
grid on; % 添加网格线
xlabel('Frequency (rad/s)'); % 设置x轴标签
ylabel('Magnitude'); % 设置y轴标签

subplot(2,1,2); % 第二个子图
semilogx(w,phasedeg); % 使用对数坐标画相频曲线
grid on; % 添加网格线
xlabel('Frequency (rad/s)'); % 设置x轴标签
ylabel('phase (degrees)'); % 设置y轴标签

This code implements the analysis and visualization of the complex frequency response of the filter in the frequency domain, where the logspace function generates 100 numbers that are logarithmically uniformly distributed from 10^-1 to 10^1, and the freqs function calculates the filter For the complex frequency response at these frequencies, the abs and angle functions extract the magnitude and phase of the response, respectively, and finally draw the magnitude-frequency curve and phase-frequency curve through two subgraphs.

Guess you like

Origin blog.csdn.net/m0_52537869/article/details/130659953