Objective

Inheritance diagram of fird.objective
class fird.objective.FunctionLinearObjective(bounds: Sequence[float], function: Callable[[float], tuple[float, float]] | Callable[[float], float], points: Sequence[int] | int | None = None)

Bases: LinearObjective

plot(ax: Axes, frequency_scale: float = 3.141592653589793, zero_phase: bool = False, desired_line: str | None = 'g', plot_db: bool = False, plot_range: bool = False, **kwargs) None

Plot desired values and objective frequency ranges in Matplotlib Axes.

Parameters:
axAxes

The Axes to plot in.

frequency_scalefloat, default: pi

Multiply the frequency values (normalized 0 to 1) when plotting.

zero_phasebool, default: False

If plotting the zero-phase magnitude response, i.e., the magnitude can take on negative values, set this to True.

desired_linestr or None, default: ‘g’

Matplotlib line definition string for the desired values. Set to None to not plot desired line.

plot_dbbool, default: False

If True, plot \(20\log_{10}\) of the desired values.

plot_rangebool, default: False

Mark where the objective is active.

**kwargsdict

Additional keyword arguments passed to Matplotlib plot().

class fird.objective.LinearObjective(frequencies: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], desired_values: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], weights: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes])

Bases: Objective

Base class for any linear objective.

A linear objective is based on constraints of the form

\[\begin{split}\begin{array}{ll} \mathrm{minimize} & \delta \\ \mathrm{subject\ to} & W(\omega)\left|H_R(\omega) - D(\omega)\right| \leq \delta \end{array}\end{split}\]

where \(H_R(\omega)\) is the zero-phase magnitude response.

The values are represented as arrays with frequencies \(= \omega\), desired_values \(= D(\omega)\), and weights \(= W(\omega)\).

Parameters:
frequencies1D array-like

Array of frequencies to form constraints for.

desired_values1D array-like

Array of desired values at frequencies.

weights1D array-like

Array of weights at frequencies.

add_to_problem(problem: LpProblem, coefficients: list[LpVariable], *, odd_order: bool = True, fractional_bits: int | None = None, even_symmetry: bool = True, cascade_filter: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None = None, period: int = 1) None

Add constraint to an FIR filter optimization problem.

Parameters:
problemLpProblem

Problem instance to add constraint to.

coefficientsdict[int, pulp.LpVariable]

Coefficient variables.

odd_orderbool, default: True

If the filter order is odd or even.

fractional_bitsint, optional

Number of fractional bits for fixed-point coefficients. If not provided, continuous (floating-point) coefficients are used.

even_symmetrybool, default: True

If the filter to be designed is of odd or even symmetry.

cascade_filter1D array, optional

The optional filter in cascade with the designed.

periodint, default: 1

The period of the designed filter in relation to the specification.

plot(ax: Axes, frequency_scale: float = 3.141592653589793, zero_phase: bool = False, desired_line: str | None = 'g', plot_db: bool = False, plot_range: bool = False, **kwargs) None

Plot desired values and objective frequency ranges in Matplotlib Axes.

Parameters:
axAxes

The Axes to plot in.

frequency_scalefloat, default: pi

Multiply the frequency values (normalized 0 to 1) when plotting.

zero_phasebool, default: False

If plotting the zero-phase magnitude response, i.e., the magnitude can take on negative values, set this to True.

desired_linestr or None, default: ‘g’

Matplotlib line definition string for the desired values. Set to None to not plot desired line.

plot_dbbool, default: False

If True, plot \(20\log_{10}\) of the desired values.

plot_rangebool, default: False

Mark where the objective is active.

**kwargsdict

Additional keyword arguments passed to Matplotlib plot().

to_constraint(min_error: float) LinearConstraint

Convert objective to the corresponding constraint.

A weight of 1 corresponds to min_error.

Parameters:
min_errorfloat

The approximation error that the constraint should have for a weight of 1.

Returns:
Constraint
Raises:
TypeError

Not all objectives can be converted to constraints.

class fird.objective.Objective

Bases: ABC

abstractmethod add_to_problem(problem: LpProblem, coefficients: dict[int, LpVariable], *, odd_order: bool = True, fractional_bits: int | None = None, even_symmetry: bool = True, cascade_filter: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None = None, period: int = 1) None

Add constraint to an FIR filter optimization problem.

Parameters:
problemLpProblem

Problem instance to add constraint to.

coefficientsdict[int, pulp.LpVariable]

Coefficient variables.

odd_orderbool, default: True

If the filter order is odd or even.

fractional_bitsint, optional

Number of fractional bits for fixed-point coefficients. If not provided, continuous (floating-point) coefficients are used.

even_symmetrybool, default: True

If the filter to be designed is of odd or even symmetry.

cascade_filter1D array, optional

The optional filter in cascade with the designed.

periodint, default: 1

The period of the designed filter in relation to the specification.

to_constraint(min_error: float) Constraint

Convert objective to the corresponding constraint.

A weight of 1 corresponds to min_error.

Parameters:
min_errorfloat

The approximation error that the constraint should have for a weight of 1.

Returns:
Constraint
Raises:
TypeError

Not all objectives can be converted to constraints.

class fird.objective.PiecewiseLinearObjective(bounds: Sequence[float], desired_values: Sequence[float], weights: Sequence[float] | None = None, points: Sequence[int] | int | None = None)

Bases: LinearObjective

plot(ax: Axes, frequency_scale: float = 3.141592653589793, zero_phase: bool = False, desired_line: str | None = 'g', plot_db: bool = False, plot_range: bool = False, **kwargs) None

Plot desired values and objective frequency ranges in Matplotlib Axes.

Parameters:
axAxes

The Axes to plot in.

frequency_scalefloat, default: pi

Multiply the frequency values (normalized 0 to 1) when plotting.

zero_phasebool, default: False

If plotting the zero-phase magnitude response, i.e., the magnitude can take on negative values, set this to True.

desired_linestr or None, default: ‘g’

Matplotlib line definition string for the desired values. Set to None to not plot desired line.

plot_dbbool, default: False

If True, plot \(20\log_{10}\) of the desired values.

plot_rangebool, default: False

Mark where the objective is active.

**kwargsdict

Additional keyword arguments passed to Matplotlib plot().

class fird.objective.RaisedCosineLinearObjective(rolloff: float, sps: int = 2, points: int = 1000)

Bases: FunctionLinearObjective

class fird.objective.RootRaisedCosineLinearObjective(rolloff: float, sps: int = 2, points: int = 1000)

Bases: FunctionLinearObjective