-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfreq_conv.m
47 lines (43 loc) · 1.67 KB
/
freq_conv.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function rr = freq_conv(xx,yy)
%freq_conv Performs convolution in frequency domain
%
% C = freq_conv(X,Y)
%
% This function computes the convolution of X and Y in the frequency domain
% and returns the result in C. Both X and Y must be one-dimensional (line
% or column) vectors. The format of the output C (i.e., line or column
% vector) matches that of the vector X.
%
% This function allows significant savings in execution time compared to
% the time-domain equivalent, i.e., Matlab's conv function.
% Release date: August 2008
% Author: Eric A. Lehmann, Perth, Australia (www.eric-lehmann.com)
%
% Copyright (C) 2008 Eric A. Lehmann
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
xxs = size(xx); yys = size(yy);
if min(xxs)~=1 || min(yys)~=1,
error('Both input vectors must be one-dimensional.');
end
xx = xx(:); yy = yy(:);
rlen = length(xx)+length(yy)-1;
rlen_p2 = 2^nextpow2(rlen);
XX = fft(xx,rlen_p2);
YY = fft(yy,rlen_p2);
rr = ifft(XX.*YY,'symmetric');
rr = rr(1:rlen); %column vector
if xxs(1)==1, % output rr in same format as xx
rr = rr.';
end