function [y,delay]=d_up(x,ratio,type)
%	y=d_up(x,ratio,type);
% upsample x, at an integer (ratio)=f_out/f_in
% using PAM.  Time delay is returned in second output.
% pulse types:
%  0      zero fill preserved
%  1      square or zero-order hold (ordinary DAC)
%  2      triangular   (linear interpolation)
%  3      FIR linear phase hamming of order 8(ratio)+1
	
	p=ones(1,ratio);delay=0;% type 1 is default
	if type == 0
		p=[1,zeros(1,ratio-1)];delay=0;
	end
	if type == 2
		p=(1/ratio)*conv(p,p);
		delay=ratio-1;
	end
	if type == 3
		N=8;
		v=(pi/ratio)*[1:N*ratio-1];v=sin(v)./v; 
		p=[fliplr(v),1,v]; % FIR linear phase
		p=p.*hamming(length(p))'; % lowpass
		delay=N*ratio-1;
	end
	if type == 4
		N=3;
		v=(pi/ratio)*[1:N*ratio-1];v=sin(v)./v; 
		p=[fliplr(v),1,v]; % FIR linear phase
		p=p.*hamming(length(p))'; % lowpass
		delay=N*ratio-1;
	end
	
	L=length(x);M=1+ratio*(L-1);
	xx=zeros(1,M);
	xx(1:ratio:M)=x;
	y=conv(xx,p);