V_IRFFT Inverse fft of a conjugate symmetric spectrum X=(Y,N,D) Inputs: Y(M) The first half of a complex spectrum N The number of output points to generate (default: 2M-2) D The dimension along which to perorm the transform (default: first non-singleton dimension of Y) Outputs: X(N) Real inverse dft of Y This routine calculates the inverse DFT of a conjugate-symmetric to give a real-valued output of dimension N. Only the first half of the spectrum need be supplied: if N is even, this includes the Nyquist term and is of dimension M=N/2 + 1 whereas if N is odd then there is no Nyquist term and the input is of dimension M=(N+1)/2. Note that the default value of N is always even so that N must be given explicitly if it is odd. See also the forward transform: RFFT
0001 function x=v_irfft(y,n,d) 0002 %V_IRFFT Inverse fft of a conjugate symmetric spectrum X=(Y,N,D) 0003 % 0004 % Inputs: Y(M) The first half of a complex spectrum 0005 % N The number of output points to generate (default: 2M-2) 0006 % D The dimension along which to perorm the transform 0007 % (default: first non-singleton dimension of Y) 0008 % 0009 % Outputs: X(N) Real inverse dft of Y 0010 % 0011 % This routine calculates the inverse DFT of a conjugate-symmetric to give a real-valued 0012 % output of dimension N. Only the first half of the spectrum need be supplied: if N is even, 0013 % this includes the Nyquist term and is of dimension M=N/2 + 1 whereas if N is odd then there is 0014 % no Nyquist term and the input is of dimension M=(N+1)/2. 0015 % Note that the default value of N is always even so that N must be given explicitly 0016 % if it is odd. 0017 % 0018 % See also the forward transform: RFFT 0019 0020 % Copyright (C) Mike Brookes 2009 0021 % Version: $Id: v_irfft.m 10865 2018-09-21 17:22:45Z dmb $ 0022 % 0023 % VOICEBOX is a MATLAB toolbox for speech processing. 0024 % Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html 0025 % 0026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0027 % This program is free software; you can redistribute it and/or modify 0028 % it under the terms of the GNU General Public License as published by 0029 % the Free Software Foundation; either version 2 of the License, or 0030 % (at your option) any later version. 0031 % 0032 % This program is distributed in the hope that it will be useful, 0033 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0034 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0035 % GNU General Public License for more details. 0036 % 0037 % You can obtain a copy of the GNU General Public License from 0038 % http://www.gnu.org/copyleft/gpl.html or by writing to 0039 % Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA. 0040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0041 0042 s=size(y); 0043 ps=prod(s); 0044 ns=length(s); 0045 if ps==1 0046 x=y; 0047 else 0048 if nargin <3 || isempty(d) 0049 d=find(s>1,1); 0050 end 0051 m=s(d); 0052 k=ps/m; % number of fft's to do 0053 if d==1 0054 v=reshape(y,m,k); 0055 else 0056 v=reshape(permute(y,[d:ns 1:d-1]),m,k); 0057 end 0058 if nargin<2 || isempty(n) 0059 n=2*m-2; % default output length 0060 else 0061 mm=1+fix(n/2); % expected input length 0062 if mm>m v=[v; zeros(mm-m,k)]; % zero pad 0063 elseif mm<m v(mm+1:m,:)=[]; % or truncate 0064 end 0065 m=mm; 0066 end 0067 if rem(n,2) % odd output length 0068 x=real(ifft([v;conj(v(m:-1:2,:))],[],1)); % do it the long way 0069 else % even output length 0070 v(m,:)=real(v(m,:)); % force nyquist element real 0071 w=ones(1,k); 0072 % t=[cumprod([-0.5i; exp(2i*pi/n)*ones(m-2,1)]); 0.5i]; 0073 t=-0.5i* exp((2i*pi/n)*(0:m-1)).'; 0074 z=(t(:,w)+0.5).*(conj(flipud(v))-v)+v; 0075 z(m,:)=[]; 0076 zz=ifft(z,[],1); 0077 x=zeros(n,k); 0078 x(1:2:n,:)=real(zz); 0079 x(2:2:n,:)=imag(zz); 0080 end 0081 s(d)=n; % change output dimension 0082 if d==1 0083 x=reshape(x,s); 0084 else 0085 x=permute(reshape(x,s([d:ns 1:d-1])),[ns+2-d:ns 1:ns+1-d]); 0086 end 0087 end