Digital signal processing-overlap and add to calculate linear convolution

Mood at the moment

University time is sometimes fragmented, large and small intervals of trivial matters, a small period of time, I don’t know what to do, so I do some sorting of ideas

Introduction to overlap and add

#Origin

When using FFT to calculate linear convolution, when encountering long sequence and short sequence convolution, FFT may not have the advantage of simplifying calculation

#Thinking The idea of
divide and conquer may be used in many situations to turn big problems into known problems that can be solved. Since a long segment is not enough, why not divide the long segment by
letting the short sequence in the two sequences be s(n), and the length is M; the long sequence is l(n), and the length is L; it can be tested. The number of segment points does not affect the convolution result, so we set the length of each segment as N. Then, the subscript of the first segment should be 0~N-1, and the second segment should be N ->2N-1; because we use each segment to calculate the convolution separately, and then combine each segment of the convolution into a suitable method The target result, then the second segment should be shifted to the left by N points for DFT, which can also be understood as period extension. In order for fft or dft to replace the linear convolution result, there is a requirement for the number of dft points, namely points=2^r>=N+M-1. Therefore, we need to add zeros on the basis of N points, and then add points-N zeros. Don't forget to do the same zero padding for s(n).
Since time domain convolution can be obtained by multiplying in frequency domain and then inversely transforming, we will convolve s(n) and each segment separately. After getting the convolution sum of each segment, we want to organize our results accordingly. The results are already given in mathematics, so I won’t repeat them. The understanding of mathematical expressions is that the first N points of the first paragraph still represent the result, and the subsequent M-1 points will be added to the first M- points of the second paragraph, and the others are similar. To put it loosely, each segment produces N+M-1 points. The second segment is equivalent to N points shifted to the right, which will inevitably cause aliasing, and the third segment shifts 2N points to the right. . . Look at the two pictures and combine understanding.
Insert picture description here

Insert picture description here
#matlabcode implementation
Since variables or memory will not be dynamically allocated for the time being, my program can only divide the sequence into 3 segments. In fact, you can modify the number of segments. From a program point of view, this code cannot meet the expected function, but the programming ability needs to be improved.

function y=chongDieBaoLiuOf3seg(x1,x2,L)
%L为分段点数
%设x1长度小于x2
len1=length(x1);
len2=length(x2);
%实现分段
if 2*L+1<len2
x21=x2(1:L);
x22=x2(L+1:2*L);
x23=x2(2*L+1:end);
%补零
m=ceil(log2(len1+len2-1));
end
N=2^m;
if L<N
    x21=[x21,zeros(1,N-L)];
    x22=[x22,zeros(1,N-L)];
    x23=[x23,zeros(1,N-length(x23))];
end
if len1<N
    x1=[x1,zeros(1,N-len1)];
end
%卷积化为乘积
X1=fft(x1);
X22=fft(x22);
X21=fft(x21);
X23=fft(x23);
Y22=X22.*X1;
Y23=X23.*X1;
Y21=X21.*X1;
y21=ifft(Y21);
y22=ifft(Y22);
y23=ifft(Y23);
%使维度一致
y21=[y21,zeros(1,2*L)];
y22=[zeros(1,L),y22,zeros(1,L)];
y23=[zeros(1,2*L),y23];
y=y21+y22+y23;
%截取需要部分
y=y(1:len1+len2-1)

# 不知道怎么跳出代码模块
小结一下,数学运算上,matlab优势很明显,

Guess you like

Origin blog.csdn.net/qq_44801767/article/details/102895639