%Illustration of Overlap-Save Method
clear all
clf
set(0,'defaultaxesfontsize',20);
%
nblocks=4;
Nfft=64;  %FFT size
DataSize=(nblocks-1)*49+64;
M=16;
x=randn(DataSize,1);
h=randn(M,1);
Hft=fft(h,64);
%
for n=0:nblocks-1,
start=1+n*49;
xt=x(start:start+63);
%
G=fft(xt,Nfft);
%
% N=Nfft/2;
% X=fft(xt(1:2:end)+j*xt(2:2:end),N);
% for k=0:N-1,
% X1(k+1)=0.5*(X(k+1)+conj(X(rem(N-k,N)+1)));
% X2(k+1)=-j*0.5*(X(k+1)-conj(X(rem(N-k,N)+1)));
% Z2(k+1)=exp(-j*2*pi*k/(2*N))*X2(k+1);
% G(k+1)=X1(k+1)+Z2(k+1);
% G(k+1+N)=X1(k+1)-Z2(k+1);
% end
%
Yft=Hft.*G;
yt=ifft(Hft.*G,64);
%
%next two lines show how the ifft is actually
%computed in terms of an fft
ytest=(1/Nfft)*conj(fft(conj(Yft),64));
norm(yt-ytest)
%yt=conv(xt,h);
ytmp(start:start+48)=yt(M:end);
end
yf=conv(x,h);
y=yf(M:end-M+1);
plot(y,'Linewidth',3);
hold on
plot(real(ytmp),'rx','Linewidth',3)
hold off
