Main Content

designHighpassFIR

Design and implement highpass FIR filter

Since R2023b

Description

B = designHighpassFIR designs a highpass FIR filter with the filter order of 100, cutoff frequency of 0.25, and a Hamming window. B is a vector of filter coefficients of length 101.

The System object™ argument is false by default. To implement the filter, assign the filter coefficients in B to a dsp.FIRFilter object.

example

B = designHighpassFIR(Name=Value) specifies options using one or more name-value arguments.

For example, B = designHighpassFIR(FilterOrder=30,CutoffFrequency=0.5,Window="hann",SystemObject=true) designs a highpass FIR filter with the filter order of 30, cutoff frequency of 0.5, and a Hann window. As the SystemObject argument is true, the function designs and implements the highpass FIR filter. B is a dsp.FIRFilter System object in this case.

When you specify only a partial list of filter parameters, the function designs the filter by setting the other design parameters to their default values.

When you specify any of the numeric input arguments in single precision, the function designs the filter coefficients in single precision. Alternatively, you can use the Datatype and like arguments to control the coefficients data type. (since R2024b)

example

Examples

collapse all

Create a dsp.FIRFilter object, and set the NumeratorSource property to 'Input port' so that you can vary the coefficients of the FIR filter through the input port during simulation.

firFilt = dsp.FIRFilter(NumeratorSource="Input port")
firFilt = 
  dsp.FIRFilter with properties:

            Structure: 'Direct form'
      NumeratorSource: 'Input port'
    InitialConditions: 0

  Use get to show all properties

Create a spectrumAnalyzer object to visualize the spectra of the input and output signals.

spectrumScope = spectrumAnalyzer(SampleRate=44100,PlotAsTwoSidedSpectrum=false,...
    ChannelNames=["Input Signal","Filtered Signal"]);

Create a dsp.DynamicFilterVisualizer object to visualize the magnitude response of the varying filter.

filterViz = dsp.DynamicFilterVisualizer(NormalizedFrequency=true);

Stream in random data and filter the signal using the dsp.FIRFilter object. Use the designHighpassFIR function to design the filter coefficients. By default, this function returns a vector of FIR filter coefficients. Assign these coefficients to the dsp.FIRFilter object.

Vary the cutoff frequency of the filter during simulation. The designHighpassFIR function redesigns the coefficients based on the updated filter specifications. Pass these updated coefficients to the FIR filter. Visualize the spectra of the input and filtered signals using the spectrum analyzer.

Fcut = 0.5;
for idx = 1:500
    num = designHighpassFIR(FilterOrder=30,CutoffFrequency=Fcut,Window="hann");
    x = randn(1024,1);
    y = firFilt(x,num);
    spectrumScope(x,y);
    filterViz(num);
    Fcut = Fcut + 0.0001;
end

Design and implement a highpass FIR filter object using the designHighpassFIR function. The function returns a dsp.FIRFilter object when you set the SystemObject argument to true. To design the filter in single-precision, use the Datatype or like argument. Alternatively, you can specify any of the numerical arguments in single-precision.

firFilt = designHighpassFIR(FilterOrder=30,CutoffFrequency=0.5,...
    Window="hann",Datatype="single",SystemObject=true)
firFilt = 
  dsp.FIRFilter with properties:

            Structure: 'Direct form'
      NumeratorSource: 'Property'
            Numerator: [0 -2.1297e-19 -0.0011 1.8613e-18 0.0048 -4.8729e-18 -0.0122 8.7270e-18 0.0251 -1.2757e-17 -0.0477 1.6267e-17 0.0960 -1.8649e-17 -0.3148 0.5000 -0.3148 -1.8649e-17 0.0960 1.6267e-17 -0.0477 -1.2757e-17 0.0251 ... ] (1x31 single)
    InitialConditions: 0

  Use get to show all properties

Create a dsp.DynamicFilterVisualizer object to visualize the magnitude response of the filter.

filterViz = dsp.DynamicFilterVisualizer(NormalizedFrequency=true);
filterViz(firFilt)

Create a spectrumAnalyzer object to visualize the spectra of the input and output signals.

spectrumScope = spectrumAnalyzer(SampleRate=44100,PlotAsTwoSidedSpectrum=false,...
    ChannelNames=["Input Signal","Filtered Signal"]);

Stream in random data and filter the signal using the dsp.FIRFilter object. Visualize the spectra of the input and filtered signals using the spectrum analyzer.

for idx = 1:500
    x = randn(1024,1);
    y = firFilt(x);
    spectrumScope(x,y);
end

Input Arguments

collapse all

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: designHighpassFIR(FilterOrder=30,CutoffFrequency=0.3)

Order of the highpass FIR filter, N, specified as an even nonnegative integer.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Cutoff frequency of the highpass FIR filter, Fcut, specified as a normalized scalar in the range (0,1].

Data Types: single | double

Window design method, specified as one of these options:

  • "hamming"

  • "hann"

  • "blackman"

  • "blackman-harris"

  • "chebyshev" –– The default sidelobe attenuation is 60 dB.

  • "kaiser"

  • "custom" –– Specify the custom window vector in the CustomWindow argument.

Data Types: char | string

Custom window vector, specified as a vector of length FilterOrder + 1.

Data Types: single | double

Since R2024b

Data type of the filter coefficients, specified by type name as "double" or "single".

You can use the Dataype or the like argument to specify the data type of the filter coefficients, but you cannot use both arguments at the same time.

If you specify the data type of the filter coefficients using this argument, the function ignores the data types of the other numeric arguments.

Data Types: char | string

Since R2024b

Data type of the filter coefficients, specified as a prototype of a real floating-point value.

You can use the Dataype or the like argument to specify the data type of filter coefficients, but you cannot use both arguments at the same time.

If you specify the data type of the filter coefficients using this argument, the function ignores the data types of the other numeric arguments.

Example: B = designHighpassFIR(FilterOrder=N,CutoffFrequency=Fcut,like=single(N))

Example: N = single(110); B = designHighpassFIR(FilterOrder=N,CutoffFrequency=Fcut,like=N)

Data Types: single | double

Option to create System object, specified as one of these:

  • false –– The function returns a vector of FIR filter coefficients.

  • true –– The function returns a dsp.FIRFilter object.

Data Types: logical

Option to print the entire function call in MATLAB, specified as one of these:

  • false –– The function does not print the function call.

  • true –– The function prints the entire function call including the default values of the Name=Value arguments that you did not specify when calling the function.

    Use this argument to view all the values used by the function to design and implement the filter.

Data Types: logical

Output Arguments

collapse all

Highpass FIR filter coefficients or filter object, returned as one of these:

  • Row vector –– The function returns a row vector of length FilterOrder + 1 when you set the SystemObject argument to false.

    If you specify single-precision values in any of the input arguments, the function designs single-precision filter coefficients. (since R2024a)

    If you specify the data type using the Datatype or the like argument, the function ignores the data types of the other numeric arguments. (since R2024b)

  • dsp.FIRFilter System object –– The function returns a filter object when you set the SystemObject argument to true.

Data Types: single | double

Extended Capabilities

Version History

Introduced in R2023b

expand all