M-file:
%% EE 212 - FrequencyResponseExample.m % % Description: M-file showing how to plot frequency responses (magnitude % and phase angle) for three circuits. The RL circuit is a high-pass % filter, the RC circuit is a low-pass filter, and the op-amp circuit with % two capacitors is a band-pass filter. % %% Clear memory; clear command window; close all existing figures clear; clc; close all; %% RL circuit's (high-pass) frequency response on linear axes % vector of angular frequencies (omega) - 250 values between 0.01 and 100 w = linspace(0.01,10,250); R = 1; L = 1; % values of resistor and inductor H = (j*w*L)./(R + j*w*L); % (complex) transfer function figure(1); % open first figure % plot magnitude response in top half of first figure, and label subplot(2,1,1); plot(w, abs(H), 'linewidth', 2); grid; xlabel('\omega (rad/sec)'); ylabel('|H(j \omega)| (V/V)') title('Magnitude Response of RL Circuit''s Transfer Function'); % plot phase response (using degrees) in bottom half of first figure, and label subplot(2,1,2); plot(w, unwrap(angle(H))*180/pi, 'linewidth', 2); grid; xlabel('\omega (rad/sec)'); ylabel('\angle(H(j \omega)) (\circ)') title('Phase Response of RL Circuit''s Transfer Function'); %% RC circuit's (low-pass) frequency response on linear axes % vector of angular frequencies (omega) - 250 values between 0.01 and 100 w = linspace(0.01,10,250); R = 1; C = 1; % values of resistor and capacitor H = 1./(j*w*R*C + 1); % (complex) transfer function figure(2); % open second figure % plot magnitude response in top half of first figure, and label subplot(2,1,1); plot(w, abs(H), 'linewidth', 2); grid; xlabel('\omega (rad/sec)'); ylabel('|H(j \omega)| (V/V)') title('Magnitude Response of RC Circuit''s Transfer Function'); % plot phase response (using degrees) in bottom half of first figure, and label subplot(2,1,2); plot(w, unwrap(angle(H))*180/pi, 'linewidth', 2); grid; xlabel('\omega (rad/sec)'); ylabel('\angle(H(j \omega)) (\circ)') title('Phase Response of RC Circuit''s Transfer Function'); %% Op-amp circuit's (band-pass) frequency response on linear axes % vector of angular frequencies (omega) - 250 values between 0.01 and 100 w = linspace(0.01,10,250); H = (-j*w)./(1 + j*w).^2; % (complex) transfer function figure(3); % open third figure % plot magnitude response in top half of first figure, and label subplot(2,1,1); plot(w, abs(H), 'linewidth', 2); grid; xlabel('\omega (rad/sec)'); ylabel('|H(j \omega)| (V/V)') title('Magnitude Response of Op-amp Circuit''s Transfer Function'); % plot phase response (using degrees) in bottom half of first figure, and label subplot(2,1,2); plot(w, unwrap(angle(H))*180/pi, 'linewidth', 2); grid; xlabel('\omega (rad/sec)'); ylabel('\angle(H(j \omega)) (\circ)') title('Phase Response of Op-amp Circuit''s Transfer Function');
Figures/Plots Generated: