FrequencyDomain FIR Filter
Filter input signal in the frequency domain
Libraries:
DSP System Toolbox /
Filtering /
Filter Implementations
Description
The FrequencyDomain FIR Filter block implements frequencydomain, fast
Fourier transform (FFT)based filtering to filter a streaming input signal. In the time
domain, the filtering operation involves a convolution between the input and the impulse
response of the finite impulse response (FIR) filter. In the frequency domain, the
filtering operation involves the multiplication of the Fourier transform of the input
and the Fourier transform of the impulse response. The frequencydomain filtering
becomes more efficient than timedomain filtering as the impulse response grows longer.
You can specify the filter coefficients directly in the frequency domain by setting
Numerator domain to
Frequency
.
This block uses the overlapsave and overlapadd methods to perform the frequencydomain filtering. For filters with a long impulse response length, the latency inherent to these two methods can be significant. To mitigate this latency, the FrequencyDomain FIR Filter block partitions the impulse response into shorter blocks and implements the overlapsave and overlapadd methods on these shorter blocks. To partition the impulse response, select the Partition numerator to reduce latency check box. For more details on these two methods and on reducing latency through impulse response partitioning, see Algorithms.
The FrequencyDomain FIR Filter block can model singleinput multipleoutput (SIMO) and multipleinput multipleoutput (MIMO) systems by supporting multiple filters in the time domain and the frequency domain. For examples that show how to model such systems, see Filter Input Signal Using 1by2 SIMO System and Filter Input Signal Using 3by2 MIMO System. You can also specify multiple paths between each transmitter (input channel) and receiver (output channel) pair using the Number of propagation paths parameter. For more information on modeling MIMO systems, see Modeling MIMO System with Multiple Propagation Paths. (since R2024a)
Examples
Frequency Domain Filtering Using OverlapAdd and OverlapSave
Filter input signal using the overlapsave and overlapadd methods and compare the filter output with the output of a timedomain FIR filter.
Open the model by clicking the Open Model button. The Lowpass FIR Filter Design block in the model designs the lowpass FIR filter with a filter order of 400 and a cutoff frequency of 0.5 in normalized frequency units. Use the Discrete FIR Filter block and the two FrequencyDomain FIR Filter blocks to filter the input signal using these coefficients.
The input signal in the model is a noisy sinusoidal signal with two tones, one at 100 Hz and the other at 3 kHz. The signal has a sample rate of 8000 Hz and a frame size of 256. The noise is a white Gaussian noise with a mean of 0 and a variance of 0.01.
Pass the input signal to the three filters. Account for the output latency of the frequencydomain FIR filters while passing the input to the timedomain FIR filter. View the filtered outputs in the time scope.
Run the model. The outputs of all the three filters match exactly.
Reduce Latency Through Partitioned Numerator
Partition the impulse response length of a frequencydomain FIR filter. Compare the outputs of the partitioned filter and the original filter.
Open the model by clicking the Open Model button. The Lowpass FIR Filter Design block in the model designs the lowpass FIR filter with a filter order of 4000 and a cutoff frequency of 0.5 in normalized frequency units. Use FrequencyDomain FIR Filter blocks to filter the input signal using these coefficients.
The input signal in the model is a noisy sinusoidal signal with two tones, one at 100 Hz and the other at 3 kHz. The signal has a sample rate of 8000 Hz and a frame size of 256. The noise is a white Gaussian noise with a mean of 0 and a variance of 0.01. Pass this data through the two frequencydomain filters.
Select the Partition numerator to reduce latency parameter in one of the FrequencyDomain FIR Filter blocks. Set the partition length to 256.
The latency of the frequencydomain FIR filter is given by . By default, the FFT length is equal to twice the numerator length. This makes the latency proportional to the impulse response length. For the frequencydomain FIR filter with no partition, the latency is 4002 samples, and for the frequencydomain FIR filter with partition, the latency is 256 samples.
Run the model. Compare the outputs of the two frequencydomain filters in the time scope. To compare the two outputs, delay the input to the partitioned frequencydomain FIR filter by 3746 samples (4002 256). As you can see in the time scope, the outputs match exactly.
Specify Frequency Response of FrequencyDomain FIR Filter
Specify the numerator coefficients of the frequencydomain FIR filter in the frequency domain. Filter the input signal using the overlapadd method. Compare the frequencydomain FIR filter output to the corresponding timedomain FIR filter output.
Open the model by clicking the Open Model button. The input is a noisy sinusoidal signal with two tones, one at 100 Hz and the other at 3 kHz. The noise is a white Gaussian noise with a mean of 0 and a variance of 0.01. Pass this signal to the FrequencyDomain FIR Filter block and the Discrete FIR Filter block.
Design the FIR lowpass filter coefficients using the designLowpassFIR
function. The sampling frequency is 8 kHz, and the cutoff frequency of the filter is 2 kHz. Specify the timedomain impulse response in the Discrete FIR Filter block. Compute the FFT of this impulse response and specify this response as the frequency response of the frequencydomain FIR filter. In the FrequencyDomain FIR Filter block, set the timedomain numerator length to the number of elements in the timedomain impulse response.
Here is the MATLAB® code to design the filter.
order = 400; Fs = 8000; Fcutoff = 2000; imp = designLowpassFIR(FilterOrder=order,CutoffFrequency=2*Fcutoff/Fs); H = fft(imp,2*numel(imp));
Run the model and visualize the frequencydomain FIR filter output and the timedomain FIR filter output in the time scope. To compare the outputs, delay the timedomain FIR filter input by the latency of the frequencydomain FIR filter.
The outputs of both the filters match exactly.
Filter Input Signal Using 1by2 SIMO System
Since R2024a
Filter an input signal using a 1by2 SIMO system with two distinct paths between the input and each output. Partition the filters to reduce latency.
Open the model by clicking the Open Model button. Design four lowpass FIR filters with different cutoff frequencies and concatenate the coefficients along the first dimension. The order for each filter is 4000 and the sampling rate is 8000 Hz. The SIMO system models one transmitter (input channel), two receivers (output channels), and two paths between each transmitterreceiver pair.
Pass the filter coefficients you design through the Num port of the FrequencyDomain FIR Filter block. Set the partition length of the filter to 256 and the number of propagation paths to 2. The block uses the Overlapsave method by default.
The input contains two sinusoidal signals each with a frame length of 256. The input noise is white Gaussian with a mean of 0 and a variance of 0.01. The first sinusoidal signal has a frequency of 500 Hz and the second sinusoidal signal has a frequency of 1000 Hz.
Run the model. Pass the signal through the designed filter. View the spectrum of the input and the filtered output in the spectrum analyzer.
Filter Input Signal Using 3by2 MIMO System
Since R2024a
Filter an input signal using a 3by2 MIMO system with three transmitters (input channels), two receivers (output channels), and one path between each transmitterreceiver pair.
Open the model by clicking the Open Model button. Design six lowpass FIR filters with different cutoff frequencies. The order for each filter is 400 and the sampling rate is 8000 Hz.
Pass the filter coefficients you design through the Num port of the FrequencyDomain FIR Filter block. The block uses the Overlapsave method by default. Select the Sum filtered output contributions from all input channels parameter.
The input contains two sinusoidal signals each with a frame length of 256. The first sinusoidal signal contains tones at 100 Hz, 200 Hz, and at 300 Hz. The second sinusoidal signal contains tones at 2 kHz, 2.5 kHz, and at 3 kHz. The input noise is white Gaussian with a mean of 0 and a variance of 0.01.
Run the model. Pass the signal through the designed filter. View the spectrum of the input and the filtered output in the spectrum analyzer.
Extended Examples
Ports
Input
x — Data Input
vector  matrix
Data input, specified as a vector or a matrix of size LbyT. This block supports variablesize input signals, that is, you can change the input frame size (number of rows) even after calling the algorithm. However, the number of channels (number of columns) must remain constant.
This port is unnamed until you select the Specify coefficients from input port parameter.
Data Types: single
 double
Complex Number Support: Yes
Num — Timedomain FIR filter coefficients
row vector  matrix (since R2024a)
Specify the timedomain FIR filter coefficients as a row vector (single filter) or a matrix (multiple filters) (since R2024a) of size FbyNumLen, where F is the number of filters and NumLen is the filter length. If F is greater than 1, then its value must be a multiple of the product of the number of input channels (columns) T and the number of paths P you specify through the Number of propagation paths parameter. The multiplication factor determines the number of receivers (output channels) R and equals F/(T × P).
The coefficient values can change during simulation but the size of the numerator must remain constant.
Dependencies
To enable this port, set Numerator domain to
Time
and select the Specify
coefficients from input port parameter.
Data Types: single
 double
 int8
 int16
 int32
 uint8
 uint16
 uint32
Complex Number Support: Yes
NumFFT — Frequencydomain FIR filter coefficients
row vector  matrix  3D array (since R2024a)
Specify the frequencydomain FIR filter coefficients as a row vector, matrix, or a 3D array (since R2024a).
When you clear the Partition numerator to reduce latency parameter, the coefficients input at this port can be a row vector or a matrix of size FbyFFTLength. The FFT length is equal to the length of the vector input. If F is greater than 1 (multiple filters) (since R2024a), then its value must be a multiple of the product of the number of input channels (columns) T and the number of paths P you specify through the Number of propagation paths parameter. The multiplication factor determines the number of receivers (output channels) R and equals F/(T × P).
When you select the Partition numerator to reduce latency parameter, Frequency response must be a matrix of size 2PLbyN to represent a single filter or a 3D array (since R2024a) of size 2PLbyNbyF to represent multiple filters, where PL is the partition size, N is the number of partitions, and F is the number of filters.
Dependencies
To enable this port, set Numerator domain to
Frequency
and select the Specify
frequency response from input port parameter.
Data Types: single
 double
 int8
 int16
 int32
 uint8
 uint16
 uint32
Complex Number Support: Yes
Output Arguments
output — Filtered output
vector  matrix  3D array (since R2024a)
Filtered output, returned as a vector, matrix or a 3D array (since R2024a).
When the number of filters F is greater than 1 and you select the Sum filtered output contributions from all input channels parameter, the block adds the filtered output from each input channel for a receiver to generate an LbyR output matrix, where L is the input frame size (number of input rows) and R is the number of receivers (output channels). R equals F/(T x P), where F is the number of filters, T is the number of transmitters (input channels), and P is the value that you specify in the Number of propagation paths parameter. (since R2024a)
When you clear the Sum
filtered output contributions from all input channels
parameter, the block does not sum filtered output contributions from all
input channels. The output is an
LbyRbyT
array. output(:,j,k)
refers to the output from the
k^{th} input channel for
the j^{th} receiver. For
example, output(:,3,2)
indicates output from the
second transmitter for the third receiver. (since R2024a)
For more information on how the object computes the output, see Algorithms.
The output has the same data type and complexity as the input signal.
This port is unnamed until you select the Output filter latency parameter and click Apply.
Data Types: single
 double
Complex Number Support: Yes
latency — Filter latency
positive integer
Filter latency, returned as a scalar. This latency is inherent to overlapadd and overlapsave methods and does not include the group delay of the filter. This port appears only when you select the Output filter latency check box.
This port is unnamed until you select the Output filter latency check box and click Apply.
Data Types: uint32
Parameters
Frequencydomain filter method — Filtering method in frequency domain
Overlapsave
(default)  Overlapadd
Specify the filtering method in the frequency domain as
Overlapsave
or
Overlapadd
. For more details on these two
methods, see Algorithms.
Numerator domain — Numerator domain
Time
(default)  Frequency
Specify the domain of the filter coefficients as one of the following:
Time
–– Specify the timedomain filter coefficients in the Filter coefficients parameter or through the Num input port.Frequency
–– Specify the filter's frequency response in the Frequency response parameter or through the NumFFT input port.
Specify coefficients from input port — Flag to specify timedomain FIR filter coefficients
off
(default)  on
When you select this check box, the timedomain FIR filter coefficients are input through the port, Num. When you clear this check box, the coefficients are specified in the block dialog box through the Filter coefficients parameter.
To view the filter response, clear this check box, specify the coefficients in the block dialog box, and click on the View Filter Response button.
Dependencies
To enable this parameter, set Numerator domain to
Time
.
Filter coefficients — Timedomain FIR filter coefficients
fir1(100,0.3)
(default)  row vector  matrix (since R2024a)
Specify the timedomain FIR filter coefficients as a row vector (single filter) or a matrix (multiple filters) (since R2024a) of size FbyNumLen, where F is the number of filters and NumLen is the filter length. If F is greater than 1, then its value must be a multiple of the product of the number of input channels (columns) T and the number of paths P you specify through the Number of propagation paths parameter. The multiplication factor determines the number of receivers (output channels) R and equals F/(T × P).
The coefficient values can change during simulation but the size of the numerator must remain constant.
Tunable: Yes
Dependencies
To enable this parameter, set Numerator domain to
Time
and clear the Specify
coefficients from input port parameter.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
Complex Number Support: Yes
Specify frequency response from input port — Flag to specify frequencydomain filter coefficients
off (default)  on
When you select this check box, the FIR filter coefficients in the frequency domain are input through the port, NumFFT. When you clear this check box, the coefficients are specified in the block dialog box through the Frequency response parameter.
To view the filter response, clear this check box, specify the frequency response in the block dialog box, and click on the View Filter Response button.
Dependencies
To enable this parameter, set Numerator domain to
Frequency
.
Frequency response — Frequency response of filter
fft(fir1(100,0.3),202)
(default)  row vector  matrix  3D array (since R2024a)
Specify the frequency response of the filter as a row vector, matrix, or a 3D array (since R2024a).
When you clear the Partition numerator to reduce latency parameter, Frequency response can be a row vector or a matrix of size FbyFFTLength. The FFT length is equal to the length of the Frequency response vector. If F is greater than 1 (multiple filters) (since R2024a), then its value must be a multiple of the product of the number of input channels (columns) T and the number of paths P you specify through the Number of propagation paths parameter. The multiplication factor determines the number of receivers (output channels) R and equals F/(T × P).
When you select the Partition numerator to reduce latency parameter, Frequency response must be a matrix of size 2PLbyN to represent a single filter or a 3D array (since R2024a) of size 2PLbyNbyF to represent multiple filters, where PL is the partition size, N is the number of partitions, and F is the number of filters.
Tunable: Yes
Dependencies
To enable this parameter, set Numerator domain to
Frequency
and clear the Specify
frequency response from input port parameter.
Data Types: single
 double
 int8
 int16
 int32
 uint8
 uint16
 uint32
Complex Number Support: Yes
Number of propagation paths — Number of propagation paths between each transmitter and receiver pair
1
(default)  positive integer
Since R2024a
Specify the number of propagation paths P between each
transmitter (input channel) and receiver (output channel) pair as a positive
integer. Each path is represented by a unique filter. When you specify the
number of paths to be greater than 1
, the filter models
multipath propagation. The algorithm sums up the filtered output
contributions from all paths between each transmitter and receiver
pair.
For an example, see Filter Input Signal Using 1by2 SIMO System.
Dependencies
To enable this parameter, the number of filters F must be greater than 1.
Data Types: single
 double
Sum filtered output contributions from all input channels — Option to sum filtered output contributions from all input channels
true
(default)  false
Since R2024a
Select this check box to sum filtered output contributions from all input channels. When you select this check box, the block adds the filtered output from each input channel for a receiver to generate an LbyR output matrix, where L is the input frame size (number of input rows) and R is the number of receivers (output channels). R equals F/(T x P), where F is the number of filters, T is the number of transmitters (input channels), and P is the value that you specify through the Number of propagation paths parameter.
When you clear this parameter, the block does not sum filtered output contributions from all input channels. The output is an LbyRbyT array.
For more information on how the block computes the output based on the value of this parameter, see Modeling MIMO System with Multiple Propagation Paths.
Dependencies
To enable this property, the number of filters F must be greater than 1.
Partition numerator to reduce latency — Option to partition the numerator to reduce latency
off
(default)  on
Select this parameter to partition the numerator to reduce latency. When you select this parameter, the block partitions the numerator into segments of length specified by the Numerator partition length parameter. The filter performs overlapsave or overlapadd on each partition, and combines the partial results to form the overall output. This option reduces latency to the partition length.
When you clear this parameter, the filter uses the traditional overlapsave or overlapadd method. The latency in this case is FFT length – NumLen + 1, where NumLen is the filter length. See the Filter coefficients parameter for more information on the filter length.
Numerator partition length — Partition length of numerator
32
(default)  positive integer
Specify the partition length of the numerator PL as a positive integer less than or equal to the length of the numerator.
Dependencies
To enable this parameter, set Numerator domain to
Time
and select the Partition
numerator to reduce latency parameter.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
Timedomain numerator length — Timedomain numerator length
101
(default)  positive integer
Specify the timedomain numerator length as a positive integer.
Dependencies
To enable this parameter, set Numerator domain to
Frequency
and clear the
Partition numerator to reduce latency check
box.
Data Types: single
 double
 int8
 int16
 int32
 uint8
 uint16
 uint32
Inherit FFT length from numerator length — Flag to inherit FFT length from the numerator length
on (default)  off
When you select this check box, the FFT length equals twice the numerator length. When you clear this check box, you specify the FFT length through the FFT length parameter.
Dependencies
To enable this parameter, set Numerator domain to
Time
and clear the Partition
numerator to reduce latency parameter.
FFT length — FFT length
1024
(default)  positive integer
The FFT length you specify must be greater than or equal to the length of the numerator you specify in the Filter coefficients parameter.
Dependencies
To enable this parameter, set Numerator domain to
Time
, clear the Partition
numerator to reduce latency and the Inherit FFT
length from numerator length parameters.
Data Types: single
 double
 int8
 int16
 int32
 int64
 uint8
 uint16
 uint32
 uint64
Filter is real — Flag to specify if filter is real
true
(default)  false
Select this parameter to specify that the filter coefficients are all real.
Dependencies
To enable this parameter, set Numerator domain to
Frequency
.
Output filter latency — Flag to output filter latency
'off'
(default)  'on'
When you select this check box and click Apply, the block outputs the filter latency through the latency port.
View Filter Response — Visualize frequency response
button
Clicking this button opens the filter visualizer and displays the magnitude response of the frequency domain FIR filter. The response is based on the parameters you select in the block dialog box. To update the response while the visualizer is running, modify the parameters in the dialog box and click Apply.
You can configure the plot settings and the frequency response measurements from the interface of the visualizer.
On the Scope tab, you can enable the legend, specify to plot both magnitude and phase responses of the filter, modify the plot settings, generate a script to recreate the plot, and even save or share the settings. On the Measurements tab, you can enable data cursors, and display the peak values of the filter response.
For more details on the filter visualizer interface and its tools, see Configure Filter Visualizer.
Dependencies
To enable this button, clear the Specify coefficients from input port and the Specify frequency response from input port parameters.
Simulate using — Type of simulation to run
Interpreted execution
(default)  Code generation
Specify the type of simulation to run. You can set this parameter to:
Interpreted execution
–– Simulate model using the MATLAB^{®} interpreter. This option shortens startup time.Code generation
–– Simulate model using generated C code. The first time you run a simulation, Simulink^{®} generates C code for the block. The C code is reused for subsequent simulations as long as the model does not change. This option requires additional startup time but provides faster subsequent simulations.
Block Characteristics
Data Types 

Direct Feedthrough 

Multidimensional Signals 

VariableSize Signals 

ZeroCrossing Detection 

Algorithms
Overlapsave and overlapadd are the two frequencydomain FFTbased filtering methods this algorithm uses.
OverlapSave
The overlapsave method is implemented using the following approach:
The input stream is partitioned into overlapping blocks of size FFTLen, with an overlap factor of NumLen – 1 samples. FFTLen is the FFT length and NumLen is the length of the FIR filter numerator. The FFT of each block of input samples is computed and multiplied with the lengthFFTLen FFT of the FIR numerator. The inverse fast Fourier transform (IFFT) of the result is performed, and the last FFTLen – NumLen + 1 samples are saved. The remaining samples are dropped.
The latency of overlapsave is FFTLen – NumLen + 1. The first FFTLen – NumLen + 1 samples are equal to zero. The filtered value of the first input sample appears as the FFTLen – NumLen + 2 output sample.
Note that the FFT length must be larger than the numerator length, and is typically set to a value much greater than NumLen.
OverlapAdd
The overlapadd method is implemented using the following approach:
The input stream is partitioned into blocks of length FFLen – NumLen + 1, with no overlap between consecutive blocks. Similar to overlapsave, the FFT of the block is computed, and multiplied by the FFT of the FIR numerator. The IFFT of the result is then computed. The first NumLen + 1 samples are modified by adding the values of the last NumLen + 1 samples from the previous computed IFFT.
The latency of overlapadd is FFTLen – NumLen + 1. The first FFTLen – NumLen + 1 samples are equal to zero. The filtered value of the first input sample appears as the FFTLen – NumLen + 2 output sample.
Reduce Latency Through Impulse Response Partitioning
With an FFT length that is twice the length of the FIR numerator, the latency roughly equals the length of the FIR numerator. If the impulse response is very long, the latency becomes significantly large. However, frequency domain FIR filtering is still faster than the timedomain filtering. To mitigate the latency and make the frequency domain filtering even more efficient, the algorithm partitions the impulse response into multiple short blocks and performs overlapsave or overlapadd on each block. The results of the different blocks are then combined to obtain the final output. The latency of this approach is of the order of the block length, rather than the entire impulse response length. This reduced latency comes at the cost of additional computation. For more details, see [1].
Modeling MIMO System with Multiple Propagation Paths
These diagrams present a generalized representation of a frequencydomain FIR filter using multiple filters to process signals between multiple transmitters and receivers. This diagram models multiple paths between each transmitterreceiver pair.
SumFilteredOutputs
is
true
The algorithm passes the first input channel through the first set of R × P filters within which ((i − 1) × P + 1) to (i × P) filters compute the output for the ith receiver. The algorithm passes the second input channel through the next set of R × P filters, and the sequence continues until the last input channel passes through the filter F.
The algorithm adds the filtered output contributions from all input channels before sending them to the respective receiver.
The input signal is of size LbyT. Each input channel corresponds to a signal sent by the specific transmitter.
L is the input frame size (number of input rows)
T is the number of transmitters (input channels)
F is the number of filters. This value is the number of rows in the filter coefficients matrix.
Filter coefficients is a matrix of size FbynumLen. Each row corresponds to a filter of length numLen.
P is the number of propagation paths between each transmitter and receiver
R is the number of receivers (output channels) and equals F/(T x P)
Output signal is of size LbyR. Each receiver receives a specific output channel of size Lby1.
SumFilteredOutputs
is
false
The algorithm concatenates the filtered outputs and does not sum across input
channels. The output is an
LbyRbyT array that you
can further process before sending it to the receiver. For example, if you add elements
in the LbyRbyT array across
the third dimension, the resultant LbyR array is
same as the output signal you get when you set SumFilteredOutputs
to true
.
References
[1] Stockham, T. G., Jr. "High Speed Convolution and Correlation." Proceedings of the 1966 Spring Joint Computer Conference, AFIPS, 28 (1966): 229–233.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Version History
Introduced in R2017bR2024a: Change in the default value of Simulate using parameter
The default value of the Simulate using parameter is now
Interpreted execution
. With this change, the block uses the
MATLAB interpreter for simulation by default.
R2024a: Support for multiple filters
You can model MIMO systems by specifying multiple filters in the time and frequency domains. You can also specify multiple paths between each input and output pair.
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
 América Latina (Español)
 Canada (English)
 United States (English)
Europe
 Belgium (English)
 Denmark (English)
 Deutschland (Deutsch)
 España (Español)
 Finland (English)
 France (Français)
 Ireland (English)
 Italia (Italiano)
 Luxembourg (English)
 Netherlands (English)
 Norway (English)
 Österreich (Deutsch)
 Portugal (English)
 Sweden (English)
 Switzerland
 United Kingdom (English)