shun_iwasawa a35b8f
function maxabsdiff=tailscrap()
shun_iwasawa a35b8f
% test code for circular convolution with the scrapped portion 
shun_iwasawa a35b8f
% at the tail of the buffer, rather than the front
shun_iwasawa a35b8f
%
shun_iwasawa a35b8f
% The idea is to rotate the zero-padded h (impulse response) buffer
shun_iwasawa a35b8f
% to the left nh-1 samples, rotating the junk samples as well.
shun_iwasawa a35b8f
% This could be very handy in avoiding buffer copies during fast filtering.
shun_iwasawa a35b8f
nh=10;
shun_iwasawa a35b8f
nfft=256;
shun_iwasawa a35b8f
shun_iwasawa a35b8f
h=rand(1,nh);
shun_iwasawa a35b8f
x=rand(1,nfft);
shun_iwasawa a35b8f
shun_iwasawa a35b8f
hpad=[ h(nh) zeros(1,nfft-nh) h(1:nh-1) ]; 
shun_iwasawa a35b8f
shun_iwasawa a35b8f
% baseline comparison
shun_iwasawa a35b8f
y1 = filter(h,1,x);
shun_iwasawa a35b8f
y1_notrans = y1(nh:nfft);
shun_iwasawa a35b8f
shun_iwasawa a35b8f
% fast convolution
shun_iwasawa a35b8f
y2 = ifft( fft(hpad) .* fft(x) );
shun_iwasawa a35b8f
y2_notrans=y2(1:nfft-nh+1);
shun_iwasawa a35b8f
shun_iwasawa a35b8f
maxabsdiff = max(abs(y2_notrans - y1_notrans))
shun_iwasawa a35b8f
shun_iwasawa a35b8f
end