.Modelica_LinearSystems2.Controllers.Internal.FIR_coefficients

Information

The FIR-filter synthesis based on the window method. The coefficients are calculated through a fourier series approximation of the desired amplitude characteristic. Due to the fact that the Fourier series is truncated, there will be discontinuities in the magnitude of the filter. Especial at the edge of the filter the ripple is concentrated (Gibbs-effect). To counteract this, the filter coefficients are convolved in the frequency domain with the spectrum of a window function, thus smoothing the edge transitions at any discontinuity. This convolution in the frequency domain is equivalent to multiplying the filter coefficients with the window coefficients in the time domain.

The filter equation

     y(k) = a0*u(k) + a1*u(k-1) + a2*u(k-2) + ... + an*u(k-n)

implies that the function outputs n+1 coefficients for a n-th order filter. The coefficients can be weightened with different kind of windows: Rectangle, Bartlett, Hann, Hamming, Blackman, Kaiser. The beta parameter is only needed by the Kaiser window.

Interface

function FIR_coefficients
  extends Modelica.Icons.Function;
  import Modelica_LinearSystems2.Utilities.Types.FilterType;
  import Modelica_LinearSystems2.Controllers.Types.FIRspec;
  input FIRspec specType = FIRspec.MeanValue "Specification type of FIR filter";
  input Integer L(min = 2) = 2 "Length of mean value filter" annotation(
    Dialog(enable = specType == FIRspec.MeanValue));
  input FilterType filterType = FilterType.LowPass "Type of filter" annotation(
    Dialog(enable = specType == FIRspec.Window));
  input Integer order(min = 1) = 2 "Order of filter" annotation(
    Dialog(enable = specType == FIRspec.Window));
  input Modelica.Units.SI.Frequency f_cut = 1 "Cut-off frequency" annotation(
    Dialog(enable = specType == FIRspec.Window));
  input Modelica.Units.SI.Time Ts(min = 0) "Sampling time";
  input Types.Window window = Modelica_LinearSystems2.Controllers.Types.Window.Rectangle "Type of window" annotation(
    Dialog(enable = specType == FIRspec.Window));
  input Real beta = 2.12 "Beta-Parameter for Kaiser-window" annotation(
    Dialog(enable = specType == FIRspec.Window and window == Modelica_LinearSystems2.Controllers.Types.Window.Kaiser));
  input Real a_desired[:] = {1, 1} "FIR filter coefficients" annotation(
    Dialog(enable = specType == FIRspec.Coefficients));
  output Real a[if specType == FIRspec.MeanValue then L else (if specType == FIRspec.Window then if mod(order, 2) > 0 and filterType == FilterType.HighPass then order + 2 else order + 1 else size(a_desired, 1))] "Filter coefficients";
end FIR_coefficients;

Generated at 2024-12-17T19:26:02Z by OpenModelicaOpenModelica 1.24.3 using GenerateDoc.mos