Magnitude (Gain in dB) NO -20 -30 Magnitude (Normalized Gain) Magnitude (Normalized Gain) 101 0 5 101 5 102 102 0 Lower Cutoff: 145.80 Hz -10 Low-pass Filter Magnitude Response (Normalized) 103 Frequency (Hz) High-pass Filter Magnitude Response (Normalized) 103 Frequency (Hz) Band-pass Filter Magnitude Response (dB) ↑ 104 104 Low-pass Filter -Cutoff 159.15 Hz High-pass Filter -Cutoff 159.15 Hz Upper Cutoff: 1737.35 Hz Band-pass Filter -Lower Cutoff = 145.80 Hz Upper Cutoff 1737.35 Hz -40 101 102 103 104 Frequency (Hz) 105 105 105

Introductory Circuit Analysis (13th Edition)
13th Edition
ISBN:9780133923605
Author:Robert L. Boylestad
Publisher:Robert L. Boylestad
Chapter1: Introduction
Section: Chapter Questions
Problem 1P: Visit your local library (at school or home) and describe the extent to which it provides literature...
icon
Related questions
Question

The MATLAB code is going well but the last part in bandpass, the legend that is supposed to tell the color of both lower and upper-frequency cutoff does not align with each other. As such I need help

My Matlab code:

% Define frequency range for the plot
f = logspace(1, 5, 500); % Frequency range from 10 Hz to 100 kHz
w = 2 * pi * f; % Angular frequency
 
% Parameters for the filters
R = 1e3; % Resistance in ohms (1 kΩ)
C = 1e-6; % Capacitance in farads (1 μF)
L = 0.1; % Inductance in henries (chosen for proper bandpass response)
 
% Compute cutoff frequencies
f_cutoff_RC = 1 / (2 * pi * R * C); % RC low-pass/high-pass cutoff
f_resonance = 1 / (2 * pi * sqrt(L * C)); % Resonant frequency of RLC
Q_factor = (1/R) * sqrt(L/C); % Quality factor of the circuit
 
% Band-pass filter cutoff frequencies
f_lower_cutoff = f_resonance / (sqrt(1 + 1/(4*Q_factor^2)) + 1/(2*Q_factor));
f_upper_cutoff = f_resonance / (sqrt(1 + 1/(4*Q_factor^2)) - 1/(2*Q_factor));
 
% Define Transfer Functions
H_low = 1 ./ (1 + 1i * w * R * C); % Low-pass filter (RC)
H_high = (1i * w * R * C) ./ (1 + 1i * w * R * C); % High-pass filter (RC)
H_band = (R ./ (R + 1i*w*L + 1./(1i*w*C))); % Band-pass filter (RLC series)
 
% Normalize the gain for Low-pass and High-pass filters
H_low_normalized = abs(H_low) / max(abs(H_low));
H_high_normalized = abs(H_high) / max(abs(H_high));
H_band_dB = 20 * log10(abs(H_band) / max(abs(H_band)));
 
% Create Figure
figure('Position', [100, 100, 800, 600]);
 
% ---- Low-pass Filter ----
subplot(3,1,1);
semilogx(f, H_low_normalized, 'b', 'LineWidth', 1.5);
hold on;
line([f_cutoff_RC f_cutoff_RC], [0, 0.707], 'Color', 'r', 'LineStyle', '--'); % Mark cutoff
title('Low-pass Filter Magnitude Response (Normalized)');
xlabel('Frequency (Hz)');
ylabel('Magnitude (Normalized Gain)');
grid on;
legend('Low-pass Filter', sprintf('Cutoff = %.2f Hz', f_cutoff_RC));
ylim([0 1.1]); % Ensure visibility
hold off;
 
% ---- High-pass Filter ----
subplot(3,1,2);
semilogx(f, H_high_normalized, 'r', 'LineWidth', 1.5);
hold on;
line([f_cutoff_RC f_cutoff_RC], [0, 0.707], 'Color', 'r', 'LineStyle', '--'); % Mark cutoff
title('High-pass Filter Magnitude Response (Normalized)');
xlabel('Frequency (Hz)');
ylabel('Magnitude (Normalized Gain)');
grid on;
legend('High-pass Filter', sprintf('Cutoff = %.2f Hz', f_cutoff_RC));
ylim([0 1.1]);
hold off;
 
% ---- Band-pass Filter ----
subplot(3,1,3);
semilogx(f, H_band_dB, 'g', 'LineWidth', 1.5);
hold on;
% Mark -3dB reference line
yline(-3, 'k--');
 
% Mark lower cutoff frequency
line([f_lower_cutoff f_lower_cutoff], [-40, -3], 'Color', 'r', 'LineStyle', '--');
text(f_lower_cutoff, -3, sprintf('Lower Cutoff: %.2f Hz', f_lower_cutoff), ...
'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'right', 'FontSize', 10);
 
% Mark upper cutoff frequency
line([f_upper_cutoff f_upper_cutoff], [-40, -3], 'Color', 'b', 'LineStyle', '--');
text(f_upper_cutoff, -3, sprintf('Upper Cutoff: %.2f Hz', f_upper_cutoff), ...
'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'left', 'FontSize', 10);
 
% Plot the band-pass filter magnitude response with labels, legend, and cutoff frequencies.
title('Band-pass Filter Magnitude Response (dB)');
xlabel('Frequency (Hz)');
ylabel('Magnitude (Gain in dB)');
grid on;
legend('Band-pass Filter', sprintf('Lower Cutoff = %.2f Hz', f_lower_cutoff), ...
sprintf('Upper Cutoff = %.2f Hz', f_upper_cutoff));
ylim([-40 5]);
hold off;
 
Magnitude (Gain in dB)
NO
-20
-30
Magnitude (Normalized Gain) Magnitude (Normalized Gain)
101
0
5
101
5
102
102
0
Lower Cutoff: 145.80 Hz
-10
Low-pass Filter Magnitude Response (Normalized)
103
Frequency (Hz)
High-pass Filter Magnitude Response (Normalized)
103
Frequency (Hz)
Band-pass Filter Magnitude Response (dB)
↑
104
104
Low-pass Filter
-Cutoff 159.15 Hz
High-pass Filter
-Cutoff 159.15 Hz
Upper Cutoff: 1737.35 Hz
Band-pass Filter
-Lower Cutoff = 145.80 Hz
Upper Cutoff 1737.35 Hz
-40
101
102
103
104
Frequency (Hz)
105
105
105
Transcribed Image Text:Magnitude (Gain in dB) NO -20 -30 Magnitude (Normalized Gain) Magnitude (Normalized Gain) 101 0 5 101 5 102 102 0 Lower Cutoff: 145.80 Hz -10 Low-pass Filter Magnitude Response (Normalized) 103 Frequency (Hz) High-pass Filter Magnitude Response (Normalized) 103 Frequency (Hz) Band-pass Filter Magnitude Response (dB) ↑ 104 104 Low-pass Filter -Cutoff 159.15 Hz High-pass Filter -Cutoff 159.15 Hz Upper Cutoff: 1737.35 Hz Band-pass Filter -Lower Cutoff = 145.80 Hz Upper Cutoff 1737.35 Hz -40 101 102 103 104 Frequency (Hz) 105 105 105
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Introductory Circuit Analysis (13th Edition)
Introductory Circuit Analysis (13th Edition)
Electrical Engineering
ISBN:
9780133923605
Author:
Robert L. Boylestad
Publisher:
PEARSON
Delmar's Standard Textbook Of Electricity
Delmar's Standard Textbook Of Electricity
Electrical Engineering
ISBN:
9781337900348
Author:
Stephen L. Herman
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Electrical Engineering
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education
Fundamentals of Electric Circuits
Fundamentals of Electric Circuits
Electrical Engineering
ISBN:
9780078028229
Author:
Charles K Alexander, Matthew Sadiku
Publisher:
McGraw-Hill Education
Electric Circuits. (11th Edition)
Electric Circuits. (11th Edition)
Electrical Engineering
ISBN:
9780134746968
Author:
James W. Nilsson, Susan Riedel
Publisher:
PEARSON
Engineering Electromagnetics
Engineering Electromagnetics
Electrical Engineering
ISBN:
9780078028151
Author:
Hayt, William H. (william Hart), Jr, BUCK, John A.
Publisher:
Mcgraw-hill Education,