Problem to implement a sinusoid oscillator in matlab I'm pretty new in dsp and I'm having tough times trying to get the output for a simple digital oscillator. I'm starting from the recursive formula $y[n]=x[n]+a \times y[n-1]-b \times y[n-2]$, and need to figure out the values of $a$ and $b$ for the output to be completely sinusoidal at a determined frequency $\omega _0$ when an unit impulse is applied as input. I can't get the theory too much and the code I wrote just doesn't work at all. I would appreciate a lot with your help with this, cheers.

The code I've tried so far:

n=0:2*pi/200:2*pi;

w0=pi/16;

f=w0/(2*pi);

beta=1;

alpha=2*cos(w0);

num=1;

den=[1 -alpha beta];

x=[0 0 1 zeros(size(n))];

y=zeros(size(n));

y(1)=0;

y(2)=0;

y(3)=sin(w0);

for i=3:size(n)

    y(i)=x(i)+alpha*y(i-1)-beta*y(i-2);

end

y;

stem(n,y)


Thanks very much
OK, since the original code was changed a bit, here is the complete solution (with some useful modifications):

n=1000;
w0=pi/16;
beta=1;
alpha=2*cos(w0);
y=zeros(1,n);
y(1)=0;
y(2)=sin(w0);

for i=3:n
    y(i)=alpha*y(i-1)-beta*y(i-2);
end

stem(y)
% End of code