plot magnitude and phase in lowpass active filter in matlab

To plot the magnitude and phase responses of a lowpass active filter in MATLAB, you can follow these steps:

  1. Design the lowpass active filter using the appropriate circuit topology (e.g., Sallen-Key, Multiple Feedback, etc.) and determine its transfer function.

  2. Use the freqs function in MATLAB to compute the frequency response of the filter. The freqs function takes the coefficients of the transfer function as inputs and returns the complex response for a range of frequencies.

  3. Separate the magnitude and phase components from the complex response obtained in the previous step using the abs and angle functions, respectively.

  4. Plot the magnitude and phase responses using the semilogx function for a logarithmic frequency scale or plot function for a linear frequency scale.

Here is an example code snippet that demonstrates these steps:

main.m
% Filter coefficients (example values)
R1 = 1e3;
R2 = 2e3;
C1 = 1e-6;
C2 = 2e-6;

% Compute transfer function
num = [1];
den = [R1*R2*C1*C2 (R1*C1 + R1*C2 + R2*C2) 1];
[H, w] = freqs(num, den);

% Separate magnitude and phase components
mag = abs(H);
phase = angle(H);

% Plot magnitude response
figure;
semilogx(w, 20*log10(mag));
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
title('Frequency Response - Magnitude');

% Plot phase response
figure;
semilogx(w, phase);
xlabel('Frequency (Hz)');
ylabel('Phase (rad)');
title('Frequency Response - Phase');
562 chars
29 lines

Please note that you may need to adjust the filter coefficients and transfer function based on your specific filter design.

gistlibby LogSnag