function [t, y, w, amp, phase] = cosfunc(freq_on, a, b, t0, c, w1);

t = -2*pi:0.03:2*pi;
ImpResp = 0.03*sin(w1*t)./(pi*t);

if (freq_on==0),
   T = pi/2;
   w0 = 7;
   t = -2*pi:0.03:2*pi;
   y = a*cos(w0*(b/c*t-t0)).*(ustep(b/c*t+T-t0) - ustep(b/c*t-T-t0));

   w = -7*pi:0.05:7*pi;
   Y = a/b*T*((sin(c/b*w-w0))./(c/b*w-w0) + (sin(c/b*w+w0))./(c/b*w+w0)).*exp(-(j*w*(t0+0.001)));
 
   phase = angle(Y);
   amp = abs(Y);

else
   T = pi/2;
   w0 = 7;
   t = -2*pi:0.03:2*pi;
   y = a*cos(w0*(b/c*t-t0)).*(ustep(b/c*t+T-t0) - ustep(b/c*t-T-t0));

   yc = conv(y, ImpResp);
   y=yc(209:209+ length(t)-1);  % 2*pi/0.03 = 209.xxx

   w = -7*pi:0.05:7*pi;
   Y = a/b*T*((sin(c/b*w-w0))./(c/b*w-w0) + (sin(c/b*w+w0))./(c/b*w+w0)).*exp(-(j*w*t0)).*(ustep(w+w1) - ustep(w-w1));
 
   phase = angle(Y);
   amp = abs(Y);
end