Skip to content

Instantly share code, notes, and snippets.

@wolframalexa
Last active October 17, 2021 21:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolframalexa/f72a3a9e3000a3636da56dda52d3e506 to your computer and use it in GitHub Desktop.
Save wolframalexa/f72a3a9e3000a3636da56dda52d3e506 to your computer and use it in GitHub Desktop.
clear; close all; clc
% Alexa Jakob and Nathaniel Kingsbury
% ECE394: Color organ project
capacitors = [33e-12 100e-12 560e-12 0.001e-6 0.01e-6 0.033e-6 0.33e-6 1e-6 ...
4.7e-6 15e-6 68e-6];
% very large values excluded
R1 = 1e3;
R2 = 560e3;
R3 = 680;
low_C = find_C(225, 400, R1, R2, R3, capacitors)
med_C = find_C(1000, 1500, 2e3, R2, R3, capacitors)
high_C = find_C(4800, 5500, R1, R2, R3, capacitors)
function cap = find_C(low, high, R1, R2, R3, capacitors)
% returns standard value closest to the calculated capacitor
center = (low + high)/2;
cap = 1./ (2 * pi * center * sqrt(1./(1./R1 + 1./R3) * R2));
[~, i] = min(abs(capacitors - cap));
cap = capacitors(i);
end
function gain = gain(R1, R2, R3, C1, C2, w)
% gain of the bandpass filter
gain = C1 * R3 ./ ((1 + R1./R2) * (1 + C1 * R3) + 1j * w * C1 * C2 * R3 + C1 + C2);
gain = abs(gain);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment