function fast_conv_demo

	% dimensioni delle sequenze da convolvere
	for N = [100 200 500 1000 2000 5000 10000]
		for	M = [3 5 11 31 51 101]
			
			fprintf('======= problem size: N=%d M=%d\n',N,M)
			
			% sequenze da convolvere
			x = randn(N,1);
			h = randn(M,1);
			
			% metodo 0: overhead
			tic;
			loop0 = 0;
			while toc < 1
				
				loop0 = loop0 + 1;
			end
			T0 = toc/loop0;
			fprintf('overhead: %g loops/s\n',1/T0);
			
			% metodo 1: convoluzione diretta con filter()
			tic;
			loop1 = 0;
			while toc < 1
				
				[y1,z1] = filter(h,1,x);
% 				y1 = [y1;z1];
				
				loop1 = loop1 + 1;
			end
			fprintf('filter(): %g loops/s\n',1/(toc/loop1-T0));
			
			% metodo 2: convoluzione tramite fft
			N_FFT = 2^ceil(log2(N+M-1));
			H = fft(h,N_FFT);
			tic;
			loop2 = 0;
			while toc < 1
				
				y2 = ifft(fft(x,N_FFT).*H,'symmetric');
% 				y2(N+M:end) = [];
				
				loop2 = loop2 + 1;
			end
			fprintf('ifft(fft().*fft()): %g loops/s\n',1/(toc/loop2-T0));
			
			% metodo 3: conv di matlab (come è?)
			tic;
			loop3 = 0;
			while toc < 1
				
				y3 = conv2(x,h,'full');
				
				loop3 = loop3 + 1;
			end
			fprintf('conv2(): %g loops/s\n',1/(toc/loop3-T0));
		end
	end
end
