forked from sfstoolbox/sfs-matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This function uses the same method as the convolve function from LTFAT
- Loading branch information
Showing
9 changed files
with
224 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
function z = convolution(x,y) | ||
%CONVOLUTION convolve the signals x and y | ||
% | ||
% Usage: z = convolution(x,y) | ||
% | ||
% Input parameters: | ||
% x - matrix/vector with signals as columns | ||
% y - matrix/vector with signals as columns, note that only one of | ||
% the signals can be a matrix | ||
% | ||
% Output parameters: | ||
% z - convolved signal | ||
% | ||
% CONVOLUTION(x,y) convolves the signals given with x and y. One of the input | ||
% signals can be a matrix containing the signals as column vectors, the other | ||
% one has to be a column vector. The convolution is done in the frequency | ||
% domain and it is checked if we have only real signals to speed up the | ||
% calculation. The length of z is length(x)+length(y)-1. | ||
% | ||
% see also: fft_real, ifft_real, fft, ifft | ||
|
||
%***************************************************************************** | ||
% Copyright (c) 2010-2013 Quality & Usability Lab, together with * | ||
% Assessment of IP-based Applications * | ||
% Deutsche Telekom Laboratories, TU Berlin * | ||
% Ernst-Reuter-Platz 7, 10587 Berlin, Germany * | ||
% * | ||
% Copyright (c) 2013 Institut fuer Nachrichtentechnik * | ||
% Universitaet Rostock * | ||
% Richard-Wagner-Strasse 31, 18119 Rostock * | ||
% * | ||
% This file is part of the Sound Field Synthesis-Toolbox (SFS). * | ||
% * | ||
% The SFS 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. * | ||
% * | ||
% The SFS 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:https://www.gnu.org/licenses/>. * | ||
% * | ||
% The SFS is a toolbox for Matlab/Octave to simulate and investigate sound * | ||
% field synthesis methods like wave field synthesis or higher order * | ||
% ambisonics. * | ||
% * | ||
% http:https://dev.qu.tu-berlin.de/projects/sfs-toolbox [email protected] * | ||
%***************************************************************************** | ||
|
||
|
||
%% ===== Checking input parameters ======================================= | ||
nargmin = 2; | ||
nargmax = 2; | ||
narginchk(nargmin,nargmax); | ||
isargmatrix(x,y); | ||
% check if only one of the inputs is a matrix | ||
if all(size(x)>1) && all(size(y)>1) | ||
error('%s: Only one of the inputs can be multi-dimensional.', ... | ||
upper(mfilename)); | ||
end | ||
|
||
|
||
%% ===== Computation ===================================================== | ||
% if one of the input signals is a matrix repmat the vector of the other signal | ||
if all(size(x)>1) | ||
y = repmat(y,1,size(x,2)); | ||
elseif all(size(y)>1) | ||
x = repmat(x,1,size(y,2)); | ||
end | ||
% length of output signal | ||
N = size(x,1)+size(y,1)-1; | ||
% convolve the signals in frequency domain | ||
if isreal(x) && isreal(y) | ||
z = ifft_real(fft_real(postpad(x,N)).*fft_real(postpad(y,N)),N); | ||
else | ||
z = ifft(fft(postpad(x,N)).*fft(postpad(y,N))); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
function y = fft_real(x) | ||
%FFT_REAL computes an fft for real value signals | ||
% | ||
% Usage: y = fft_real(x) | ||
% | ||
% Input parameters: | ||
% x - matrix with signals as columns | ||
% | ||
% Output parameters: | ||
% y - matrix with signals as columns | ||
% | ||
% FFT_REAL(x) computes the fft of the real signals in x. The signals have | ||
% to be the columns of x. | ||
% | ||
% see also: ifft_real, convolution | ||
|
||
%***************************************************************************** | ||
% Copyright (c) 2010-2013 Quality & Usability Lab, together with * | ||
% Assessment of IP-based Applications * | ||
% Deutsche Telekom Laboratories, TU Berlin * | ||
% Ernst-Reuter-Platz 7, 10587 Berlin, Germany * | ||
% * | ||
% Copyright (c) 2013 Institut fuer Nachrichtentechnik * | ||
% Universitaet Rostock * | ||
% Richard-Wagner-Strasse 31, 18119 Rostock * | ||
% * | ||
% This file is part of the Sound Field Synthesis-Toolbox (SFS). * | ||
% * | ||
% The SFS 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. * | ||
% * | ||
% The SFS 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:https://www.gnu.org/licenses/>. * | ||
% * | ||
% The SFS is a toolbox for Matlab/Octave to simulate and investigate sound * | ||
% field synthesis methods like wave field synthesis or higher order * | ||
% ambisonics. * | ||
% * | ||
% http:https://dev.qu.tu-berlin.de/projects/sfs-toolbox [email protected] * | ||
%***************************************************************************** | ||
|
||
|
||
%% ===== Checking of input parameters ==================================== | ||
nargmin = 1; | ||
nargmax = 1; | ||
narginchk(nargmin,nargmax); | ||
isargmatrix(x); | ||
|
||
|
||
%% ===== Computation ===================================================== | ||
N = size(x,1); | ||
N2=floor(N/2)+1; | ||
|
||
% Force IFFT along dimension 1 | ||
y = fft(x,N,1); | ||
y = y(1:N2,:); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
function y = ifft_real(x,N) | ||
%IFFT_REAL computes an ifft for real value signals | ||
% | ||
% Usage: y = ifft_real(x,samples) | ||
% | ||
% Input parameters: | ||
% x - matrix x with signals as columns | ||
% samples - desired length of the output signals | ||
% | ||
% Output parameters: | ||
% y - matrix y with signals as columns | ||
% | ||
% IFFT_REAL(x,samples) computes the ifft of the real signals in x. The signals | ||
% have to be the columns of x. | ||
% | ||
% see also: fft_real, convolution | ||
|
||
%***************************************************************************** | ||
% Copyright (c) 2010-2013 Quality & Usability Lab, together with * | ||
% Assessment of IP-based Applications * | ||
% Deutsche Telekom Laboratories, TU Berlin * | ||
% Ernst-Reuter-Platz 7, 10587 Berlin, Germany * | ||
% * | ||
% Copyright (c) 2013 Institut fuer Nachrichtentechnik * | ||
% Universitaet Rostock * | ||
% Richard-Wagner-Strasse 31, 18119 Rostock * | ||
% * | ||
% This file is part of the Sound Field Synthesis-Toolbox (SFS). * | ||
% * | ||
% The SFS 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. * | ||
% * | ||
% The SFS 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:https://www.gnu.org/licenses/>. * | ||
% * | ||
% The SFS is a toolbox for Matlab/Octave to simulate and investigate sound * | ||
% field synthesis methods like wave field synthesis or higher order * | ||
% ambisonics. * | ||
% * | ||
% http:https://dev.qu.tu-berlin.de/projects/sfs-toolbox [email protected] * | ||
%***************************************************************************** | ||
|
||
|
||
%% ===== Checking of input parameters ==================================== | ||
nargmin = 2; | ||
nargmax = 2; | ||
narginchk(nargmin,nargmax); | ||
isargmatrix(x); | ||
isargpositivescalar(N); | ||
|
||
|
||
%% ===== Computation ===================================================== | ||
N2=floor(N/2)+1; | ||
|
||
% Force IFFT along dimension 1 | ||
if rem(N,2)==0 | ||
y= [x; flipud(conj(x(2:end-1,:)))]; | ||
else | ||
y = [x; flipud(conj(x(2:end,:)))]; | ||
end; | ||
|
||
y = real(ifft(y,N,1)); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters