コード例 #1
0
    def design_components(self,
                          zeros: dict,
                          poles: dict,
                          gain: float,
                          stop_at_first=False) -> dict:
        if "wp" not in poles.keys() or "wz" not in zeros.keys(
        ) or gain >= 0 or poles["wp"] <= 0 or zeros["wz"] != 0:
            raise CellError(CellErrorCodes.INVALID_PARAMETERS)
        else:
            # Declaring and cleaning
            self.results = []

            # First, compute possible R2 values based on C1 targetting the Wp value
            r1_c1_options = compute_commercial_by_iteration(
                ComponentType.Resistor, ComponentType.Capacitor, lambda c1: 1 /
                (poles["wp"] * c1), self.error)

            # With the given values of R2, targetting K gain, calculates R1
            r2_r1_options = compute_commercial_by_iteration(
                ComponentType.Resistor,
                ComponentType.Resistor,
                lambda r1: -gain * r1,
                self.error,
                fixed_two_values=[r2_option for r2_option, _ in r1_c1_options])

            # Collecting results!
            self.results = nexpand_component_list(self.results, r2_r1_options,
                                                  "R2", "R1")
            self.results = nexpand_component_list(self.results, r1_c1_options,
                                                  "R1", "C1")
            self.flush_results()
            self.choose_random_result()
コード例 #2
0
    def design_components(self,
                          zeros: dict,
                          poles: dict,
                          gain: float,
                          stop_at_first=False) -> dict:
        if "wp" not in poles.keys() or "qp" not in poles.keys() or gain >= 0:
            raise CellError(CellErrorCodes.INVALID_PARAMETERS)
        else:
            self.results = []

            # Using the gain, we calculate R6, R7 and R8, using that R7 = R8
            r8_r6 = compute_commercial_by_iteration(ComponentType.Resistor,
                                                    ComponentType.Resistor,
                                                    lambda r6: gain * (-r6),
                                                    self.error)
            r8_r7_r6 = [(r8, r8, r6) for r8, r6 in r8_r6]

            # Using R = R2 = R3 and C = C1 = C2 to calculate values
            r_c = compute_commercial_by_iteration(
                ComponentType.Resistor, ComponentType.Capacitor, lambda c: 1 /
                (poles["wp"] * c), self.error)
            r2_r3_c1_c2 = [(r, r, c, c) for r, c in r_c]

            # Calculate R1 and R4
            r1_r2 = compute_commercial_by_iteration(
                ComponentType.Resistor,
                ComponentType.Resistor,
                lambda r2: r2 * poles["qp"],
                self.error,
                fixed_two_values=[r2 for r2, r3, c1, c2 in r2_r3_c1_c2])

            r4_r1 = compute_commercial_by_iteration(
                ComponentType.Resistor,
                ComponentType.Resistor,
                lambda r1: -r1 / gain,
                self.error,
                fixed_two_values=[r1 for r1, r2 in r1_r2])

            self.results = nexpand_component_list(self.results, r4_r1, "R4",
                                                  "R1")
            self.results = nexpand_component_list(self.results, r1_r2, "R1",
                                                  "R2")
            self.results = nexpand_component_list(self.results, r2_r3_c1_c2,
                                                  "R2", "R3", "C1", "C2")
            self.results = nexpand_component_list(self.results, r8_r7_r6, "R8",
                                                  "R7", "R6")
            self.flush_results()
            self.choose_random_result()
コード例 #3
0
    def design_components(self,
                          zeros: dict,
                          poles: dict,
                          gain: float,
                          stop_at_first=False) -> dict:
        if "wp" not in poles.keys() or "qp" not in poles.keys() or gain != 1:
            raise CellError(CellErrorCodes.INVALID_PARAMETERS)
        else:
            # Declaring and cleaning
            self.results = []

            # Secondly, but using the relationship R1=R2, calculates C1, and C2
            c2_c1 = compute_commercial_by_iteration(
                ComponentType.Capacitor, ComponentType.Capacitor,
                lambda c1: c1 / (4 * poles["qp"]**2), self.error)

            # Finally, calculates with the previous C1, C2 values, options for R = R1 = R2
            r1_r2_c1_c2 = []
            for c2, c1 in c2_c1:
                r = 1 / (poles["wp"] * sqrt(c1 * c2))
                matches, commercial = matches_commercial_values(
                    ComponentType.Resistor, r, self.error)
                if matches:
                    r1_r2_c1_c2.append((commercial, commercial, c1, c2))

            # Cross selection of possible values of components
            self.results = nexpand_component_list(self.results, r1_r2_c1_c2,
                                                  "R1", "R2", "C1", "C2")
            self.flush_results()
            self.choose_random_result()
コード例 #4
0
    def design_components(self,
                          zeros: dict,
                          poles: dict,
                          gain: float,
                          stop_at_first=False) -> dict:
        if "wp" not in poles.keys() or "qp" not in poles.keys() or gain <= 1:
            raise CellError(CellErrorCodes.INVALID_PARAMETERS)
        else:
            # Declaring and cleaning
            self.results = []

            # First, calculate the easy gain resistors
            ra_rb = compute_commercial_by_iteration(ComponentType.Resistor,
                                                    ComponentType.Resistor,
                                                    lambda rb: rb / (gain - 1),
                                                    self.error)

            # Secondly, but using the relationship C1=C2, calculates R1, and R2
            r1_r2 = compute_commercial_by_iteration_list(
                ComponentType.Resistor, ComponentType.Resistor, [
                    lambda r2:
                    (-r2 *
                     (4 * (1 - gain) - 1) + r2 * sqrt(1 - 8 * poles["qp"]**2 *
                                                      (1 - gain))) /
                    (8 * poles["qp"]**2), lambda r2:
                    (-r2 *
                     (4 * (1 - gain) - 1) - r2 * sqrt(1 - 8 * poles["qp"]**2 *
                                                      (1 - gain))) /
                    (8 * poles["qp"]**2)
                ], self.error)

            # Finally, calculates with the previous R1, R2 values, options for C = C1 = C2
            r1_r2_c1_c2 = []
            for r1, r2 in r1_r2:
                c1 = 1 / (poles["wp"] * sqrt(r1 * r2))
                matches, commercial = matches_commercial_values(
                    ComponentType.Capacitor, c1, self.error)
                if matches:
                    r1_r2_c1_c2.append((r1, r2, commercial, commercial))

            # Cross selection of possible values of components
            self.results = nexpand_component_list(self.results, ra_rb, "Ra",
                                                  "Rb")
            self.results = nexpand_component_list(self.results, r1_r2_c1_c2,
                                                  "R1", "R2", "C1", "C2")
            self.flush_results()
            self.choose_random_result()
コード例 #5
0
    def design_components(self,
                          zeros: dict,
                          poles: dict,
                          gain: float,
                          stop_at_first=False) -> dict:
        if "wp" not in poles.keys() or "qp" not in poles.keys() or gain <= 0:
            raise CellError(CellErrorCodes.INVALID_PARAMETERS)
        else:
            self.results = []

            # Random values... why not?
            r7 = r8 = random_commercial(ComponentType.Resistor)

            # Calculate R1 and R4 to verify the gain of the filter
            r1_r4 = compute_commercial_by_iteration(ComponentType.Resistor,
                                                    ComponentType.Resistor,
                                                    lambda r4: gain * r4,
                                                    self.error)

            # Using the previous R1 values, get the R = R2 = R3 values
            r_r1 = compute_commercial_by_iteration(
                ComponentType.Resistor,
                ComponentType.Resistor,
                lambda r1: r1 / poles["qp"],
                self.error,
                fixed_two_values=[r1 for r1, r4 in r1_r4])
            r1_r2_r3 = [(r1, r, r) for r, r1 in r_r1]

            # Using that C=C1=C2 then calculate with the previous values of R
            c_r = compute_commercial_by_iteration(
                ComponentType.Capacitor,
                ComponentType.Resistor,
                lambda r: 1 / (poles["wp"] * r),
                self.error,
                fixed_two_values=[r for r, r1 in r_r1])
            c1_c2_r2 = [(c, c, r) for c, r in c_r]

            self.results = nexpand_component_list(self.results, c1_c2_r2, "C1",
                                                  "C2", "R2")
            self.results = nexpand_component_list(self.results, r1_r2_r3, "R1",
                                                  "R2", "R3")
            self.results = nexpand_component_list(self.results, r1_r4, "R1",
                                                  "R4")
            self.results = nexpand_component_list(self.results, [(r7, r8)],
                                                  "R7", "R8")
            self.flush_results()
            self.choose_random_result()
コード例 #6
0
    def design_components(self,
                          zeros: dict,
                          poles: dict,
                          gain: float,
                          stop_at_first=False) -> dict:
        if "wp" not in poles.keys() or "qp" not in poles.keys() or gain >= 0:
            raise CellError(CellErrorCodes.INVALID_PARAMETERS)
        else:
            self.results = []

            # Using the gain calculates posible values for R2 and R5
            r2_r5 = compute_commercial_by_iteration(ComponentType.Resistor,
                                                    ComponentType.Resistor,
                                                    lambda r5: gain * (-r5),
                                                    self.error)

            # Random values for R7 and R8
            r7 = r8 = random_commercial(ComponentType.Resistor)

            # Using R2 values, get possible values for R3 and C=C1=C2
            r3_c1_c2_r2_r1 = []
            for r2, r5 in r2_r5:
                r3_c = compute_commercial_by_iteration(
                    ComponentType.Resistor, ComponentType.Capacitor,
                    lambda c: 1 / ((poles["wp"]**2) * (c**2) * r2), self.error)
                for r3, c in r3_c:
                    r1 = poles["qp"] * sqrt(r2 * r3)
                    matches, commercial = matches_commercial_values(
                        ComponentType.Resistor, r1, self.error)
                    if matches:
                        r3_c1_c2_r2_r1.append((r3, c, c, r2, commercial))

            # Cross selection
            self.results = nexpand_component_list(self.results, r3_c1_c2_r2_r1,
                                                  "R3", "C1", "C2", "R2", "R1")
            self.results = nexpand_component_list(self.results, r2_r5, "R2",
                                                  "R5")
            self.results = nexpand_component_list(self.results, [(r7, r8)],
                                                  "R7", "R8")
            self.flush_results()
            self.choose_random_result()
コード例 #7
0
    def design_components(self,
                          zeros: dict,
                          poles: dict,
                          gain: float,
                          stop_at_first=False) -> dict:
        if "wp" not in poles.keys() or "wz" not in zeros.keys(
        ) or "qp" not in poles.keys() or gain >= 0:
            raise CellError(CellErrorCodes.INVALID_PARAMETERS)
        else:
            self.results = []

            # Starts calculating R2=R3 with R5 relationship of gain
            r2_r5 = compute_commercial_by_iteration(ComponentType.Resistor,
                                                    ComponentType.Resistor,
                                                    lambda r5: gain * (-r5),
                                                    self.error)
            r2_r3_r5 = [(r2, r2, r5) for r2, r5 in r2_r5]

            # To get the desired Q value, calculate R1 for that
            r1_r2 = compute_commercial_by_iteration(
                ComponentType.Resistor,
                ComponentType.Resistor,
                lambda r2: poles["qp"] * r2,
                self.error,
                fixed_two_values=[r2 for r2, r3, r5 in r2_r3_r5])

            # Calculating the capacitors for the pole frequency
            c_r2 = compute_commercial_by_iteration(
                ComponentType.Capacitor,
                ComponentType.Resistor,
                lambda r2: 1 / (r2 * poles["wp"]),
                self.error,
                fixed_two_values=[r2 for r2, r3, r5 in r2_r3_r5])
            c1_c2_r3 = [(c, c, r2) for c, r2 in c_r2]

            r1_r4_c1_r3 = []
            r7_r8_r6_c1_r3 = []
            for c1, c2, r3 in c1_c2_r3:
                r4_r1 = compute_commercial_by_iteration(
                    ComponentType.Resistor, ComponentType.Resistor,
                    lambda r1: r1 * (((zeros["wz"]**2) * (c1**2) * (r3**2)) /
                                     (-gain)), self.error)
                r1_r4_c1_r3 += [(r1, r4, c1, r3) for r4, r1 in r4_r1]

                r6_r7 = compute_commercial_by_iteration(
                    ComponentType.Resistor, ComponentType.Resistor,
                    lambda r7: r7 * ((zeros["wz"]**2) * (c1**2) * (r3**2) /
                                     (-gain)), self.error)
                r7_r8_r6_c1_r3 += [(r7, r7, r6, c1, r3) for r6, r7 in r6_r7]

            self.results = nexpand_component_list(self.results, r2_r3_r5, "R2",
                                                  "R3", "R5")
            self.results = nexpand_component_list(self.results, r1_r2, "R1",
                                                  "R2")
            self.results = nexpand_component_list(self.results, c1_c2_r3, "C1",
                                                  "C2", "R3")
            self.results = nexpand_component_list(self.results, r1_r4_c1_r3,
                                                  "R1", "R4", "C1", "R3")
            self.results = nexpand_component_list(self.results, r7_r8_r6_c1_r3,
                                                  "R7", "R8", "R6", "C1", "R3")
            self.flush_results()
            self.choose_random_result()