Overlap–add method: Difference between revisions

Content deleted Content added
Cewbot (talk | contribs)
Aw6STM (talk | contribs)
Link suggestions feature: 1 link added.
 
(15 intermediate revisions by 10 users not shown)
Line 1:
{{Short description|Method in signal processing}}
{{hatnoteabout|Thisthe article is about aconvolution method|the of performing convolution, not to be confused with WOLA ("Weight, OverLap, Add)," which is achannelization method of performing channelization. See [[|Discrete-time Fourier transform#Sampling the DTFT|{{!}}Sampling the DTFT]]}}
{{hatnote|This article uses common abstract notations, such as <math display="inline">y(t) = x(t) * h(t),</math> or <math display="inline">y(t) = \mathcal{H}\{x(t)\},</math> in which it is understood that the functions should be thought of in their totality, rather than at specific instants <math display="inline">t.</math> (see [[Convolution#Notation]])}}
 
In [[signal processing]], the '''overlap–add method''' is an efficient way to evaluate the discrete [[convolution]] of a very long signal <math>x[n]</math> with a [[finite impulse response]] (FIR) filter <math>h[n]</math>''':'''
[[Image:Overlap-add algorithm.svg|thumb|500px|Fig 1: A sequence of 5 plots depicts one cycle of the Overlap-add convolution algorithm. The first plot is a long sequence of data to be processed with a lowpass FIR filter. The 2nd plot is one segment of the data to be processed in piecewise fashion. The 3rd plot is the filtered segment, including the filter rise and fall transients. The 4th plot indicates where the new data will be added with the result of previous segments. The 5th plot is the updated output stream. The FIR filter is a boxcar lowpass with M=16 samples, the length of the segments is L=100 samples and the overlap is 15 samples.]]
 
{{Equation box 1
{{NumBlk|:|<math>
|indent= |cellpadding= 0 |border= 0 |background colour=white
y[n] = x[n] * h[n]
|equation={{NumBlk|:|<math>
<math>y[n] = x[n] * h[n]
\ \triangleq\ \sum_{m=-\infty}^{\infty} h[m] \cdot x[n - m]
= \sum_{m=1}^{M} h[m] \cdot x[n - m],</math> &nbsp; &nbsp;
</math>|{{EquationRef|Eq.1}}}}}}
 
{{hatnote|where <math>h[m] = 0</math> for <math>m</math> outside the region <math>[1,M].</math>&nbsp; This article uses common abstract notations, such as <math display="inline">y(t) = x(t) * h(t),</math> or <math display="inline">y(t) = \mathcal{H}\{x(t)\},</math> in which it is understood that the functions should be thought of in their totality, rather than at specific instants <math display="inline">t.</math> (see [[Convolution#Notation]])}}.
where {{nowrap|''h''[''m''] {{=}} 0}} for ''m'' outside the region {{nowrap|[1, ''M'']}}.
 
[[Image:Overlap-add algorithm.svg|thumb|right|500px|Fig 1: A sequence of 5five plots depicts one cycle of the Overlapoverlap-add convolution algorithm. The first plot is a long sequence of data to be processed with a lowpass FIR filter. The 2nd plot is one segment of the data to be processed in piecewise fashion. The 3rd plot is the filtered segment, including the filter rise and fall transients. The 4th plot indicates where the new data will be added with the result of previous segments. The 5th plot is the updated output stream. The FIR filter is a boxcar lowpass with <math>M=16</math> samples, the length of the segments is <math>L=100</math> samples and the overlap is 15 samples.]]
The concept is to divide the problem into multiple convolutions of ''h''[''n''] with short segments of <math>x[n]</math>:
 
The concept is to divide the problem into multiple convolutions of ''<math>h''[''n'']</math> with short segments of <math>x[n]</math>''':'''
 
:<math>x_k[n]\ \triangleq\ \begin{cases}
Line 21 ⟶ 24:
</math>
 
where ''<math>L''</math> is an arbitrary segment length. Then''':'''
 
:<math>x[n] = \sum_{k} x_k[n - kL],\,</math>
 
and ''<math>y''[''n'']</math> can be written as a sum of short convolutions''':'''<ref name=Rabiner/>
 
:<math>\begin{align}
Line 33 ⟶ 36:
\end{align}</math>
 
where the linear convolution <math>y_k[n]\ \triangleq\ x_k[n] * h[n]\,</math> is zero outside the region {{nowrap|<math>[1, ''L'' + ''M'' − -1]}}.</math> And for any parameter <math>N \ge L + M - 1,\,</math>{{efn-ua
|This condition implies that the <math>x_k</math> segment has at least ''<math>M''-1</math> appended zeros, which prevents circular overlap of the output rise and fall transients.
}} it is equivalent to the ''<math>N''</math>-point [[circular convolution]] of <math>x_k[n]\,</math> with <math>h[n]\,</math> in the {{nowrap|region <math>[1, ''N'']}}.</math>&nbsp; The advantage is that the circular convolution can be computed more efficiently than linear convolution, according to the [[Discrete Fourier transform#Circular convolution theorem and cross-correlation theorem|circular convolution theorem]]''':'''
 
{{Equation box 1
{{NumBlk|:|<math>y_k[n]\ =\ \scriptstyle \text{IDFT}_N \displaystyle (\ \scriptstyle \text{DFT}_N \displaystyle (x_k[n])\cdot\ \scriptstyle \text{DFT}_N \displaystyle (h[n])\ ),</math>|{{EquationRef|Eq.2}}}}
|indent= |cellpadding= 0 |border= 0 |background colour=white
|equation={{NumBlk|:|
{{NumBlk|:|<math>y_k[n]\ =\ \scriptstyle \text{IDFT}_N \displaystyle (\ \scriptstyle \text{DFT}_N \displaystyle (x_k[n])\cdot\ \scriptstyle \text{DFT}_N \displaystyle (h[n])\ ),</math>|{{EquationRef|Eq.2}}}} &nbsp; &nbsp;
|{{EquationRef|Eq.2}}}}}}
 
where''':'''
* DFT<sub>N</sub> and IDFT<sub>N</sub> refer to the [[Discrete Fourier transform]] and its inverse, evaluated over ''<math>N''</math> discrete points, and
*{{ <math|>L}}</math> is customarily chosen such that {{<math|>N {{=}} L+M-1}}</math> is an integer power-of-2, and the transforms are implemented with the [[Fast Fourier transform|FFT]] algorithm, for efficiency.
 
==Pseudocode==
The following is a [[pseudocode]] of the algorithm''':'''
 
The following is a [[pseudocode]] of the algorithm:
 
<span style="color:green;">(''Overlap-add algorithm for linear convolution'')</span>
h = FIR_filter
h = FIR_impulse_response
M = length(h)
Nx = length(x)
N = 8 × 2^ceiling( log2(M) ) <span style="color:green;">(see8 times the smallest power of two bigger than filter length M. See next section for a slightly better choice.)</span>
step_size = N - (M-1) <span style="color:green;">(L in the text above)</span>
H = DFT(h, N)
position = 0
Line 62 ⟶ 68:
'''end'''
 
== Efficiency considerations ==
[[Image:FFT_size_vs_filter_length_for_Overlap-add_convolution.svg|thumb|400px|Fig 2: A graph of the values of N (an integer power of 2) that minimize the cost function <math>\tfrac{N\left(\log_2 N + 1\right)}{N - M + 1}</math>]]
 
Line 69 ⟶ 75:
}} Each iteration produces {{nowrap|'''N-M+1'''}} output samples, so the number of complex multiplications per output sample is about''':'''
 
{{Equation box 1
{{NumBlk|:|<math>\frac{N (\log_2(N) + 1)}{N-M+1}.\,</math>|{{EquationRef|Eq.3}}}}
|indent= |cellpadding= 0 |border= 0 |background colour=white
|equation={{NumBlk|:|
{{NumBlk|:|<math>\frac{N (\log_2(N) + 1)}{N-M+1}.\,</math>|{{EquationRef|Eq.3}}}} &nbsp; &nbsp;
|{{EquationRef|Eq.3}}}}}}
 
For example, when '''<math>M'''=201</math> and '''<math>N'''=1024,</math> {{EquationNote|Eq.3}} equals <math>13.67,</math> whereas direct evaluation of {{EquationNote|Eq.1}} would require up to <math>201</math> complex multiplications per output sample, the worst case being when both '''<math>x'''</math> and '''<math>h'''</math> are complex-valued. Also note that for any given '''<math>M''',</math> {{EquationNote|Eq.3}} has a minimum with respect to '''<math>N'''.</math> Figure 2 is a graph of the values of <math>N</math> that minimize {{EquationNote|Eq.3}} for a range of filter lengths (<math>M</math>).
 
Instead of {{EquationNote|Eq.1}}, we can also consider applying {{EquationNote|Eq.2}} to a long sequence of length <math>N_x</math> samples. The total number of complex multiplications would be:
Line 81 ⟶ 91:
:<math>N_x\cdot (\log_2(N) + 1)\cdot \frac{N}{N-M+1}.</math>
 
Hence the ''cost'' of the overlap–add method scales almost as <math>O\left(N_x\log_2 N\right)</math> while the cost of a single, large circular convolution is almost <math>O\left(N_x\log_2 N_x \right)</math>. The two methods are also compared in Figure 3, created by [[MATLAB|Matlab]] simulation. The contours are lines of constant ratio of the times it takes to perform both methods. When the overlap-add method is faster, the ratio exceeds 1, and ratios as high as 3 are seen.
 
[[Image:gain oa method.png|frame|none|Fig 3: Gain of the overlap-add method compared to a single, large circular convolution. The axes show values of signal length N<sub>x</sub> and filter length N<sub>h</sub>.]]
 
== See also ==
* [[Overlap–save method]]
* [[Circular_convolution#Example]]
 
==Notes==
Line 104 ⟶ 115:
| chapter=2.25
| pages=[https://archive.org/details/theoryapplicatio00rabi/page/63 63–65]
| chapter-url-access=registration
| chapter-url=https://archive.org/details/theoryapplicatio00rabi/page/63
}}</ref>
}}
 
== Further reading==
*{{Cite book
|author1=Oppenheim, Alan V. |author2=Schafer, Ronald W. | title=Digital signal processing
Line 128 ⟶ 139:
| pages=
}}
* {{cite journal | last1=Senobari | first1=Nader Shakibay | last2=Funning | first2=Gareth J. | last3=Keogh | first3=Eamonn | last4=Zhu | first4=Yan | last5=Yeh | first5=Chin-Chia Michael | last6=Zimmerman | first6=Zachary | last7=Mueen | first7=Abdullah | title=Super-Efficient Cross-Correlation (SEC-C): A Fast Matched Filtering Code Suitable for Desktop Computers | journal=Seismological Research Letters | volume=90 | issue=1 | date=2019 | issn=0895-0695 | doi=10.1785/0220180122 | pages=322–334 | url=https://www.cs.ucr.edu/~eamonn/SuperEfficientCrossCorrelation.pdf }}
 
== External links ==
 
{{DEFAULTSORT:Overlap-Add Method}}