You are on page 1of 3

7.

GENERATION OF SINUSOIDAL WAVE USING RECURSIVE/FILTER


METHOD

Aim: To generate sinusoidal signal using recursive/filter method

Apparatus: PC having MATLAB software

Theory:
There exists different techniques to generate a sine wave on a DSP processor.
Using a lookup table, interpolation, polynomials, or pulse width modulation are some of these
techniques utilized to generate a sine wave. When a slightly sufficient processing power is
considered, it is possible to utilize another technique which makes use of an IIR filter.
In this technique, a second order IIR filter as shown in Figure 1 is designed to be marginally
stable which is an undesirable situation for a normal filtering operation. For this second order
filter to be marginally stable, its poles are located in the unit circle. After choosing the suitable
filter oefficients for the filter to be marginally stable, a unit impulse is applied to the filter as an
input at time t = 0, and then the input is disconnected. Then the filter starts to oscillate with a
fixed frequency.

The difference equation of the second order filter shown in Figure 1 will be:
Where F0 is the frequency, Fs is the sampling frequency and A is the amplitude of the
sine wave.
Y[n]=-a1y[n-1]-a2y[n-2]+b0[n]
Where, y[n-1]=y[-2]=0
a1=-2 ( ), a2=1,
b0=A Sin(w0),

w0 = 2/s

Procedure: 1.Open MATLAB

2.Open new M-file

3.Type the program

4.Save in current directory

5.Run the program

6.For output see command window/figure window

Program:

% Generation of sine wave using recursive difference equation or IIR filter


%fs = sampling rate
% t = time in sec
%f0 = frequency
% A = amplitude
A = 2;
t=0.1;
fs = 5000;
f0=50;
length = fs*t;
y = zeros(1,length);
impulse = zeros(1,length);
impulse(1) = 1;
% frequency coefficients
% difference equation of form y[n]= -a1 y[n-1] -a2 y[n-2] + b0 impulse[n]
% a1 = -2cos(2*pi*f0/fs), a2= 1, b0 = Asin(2*pi*f0/fs)
a1 = -2*cos(2*pi*f0/fs)
a2 = 1;
b0 = A*sin(2*pi*f0/fs)
y(1)= 0;
y(2)= b0;
for i=3:length
y(i)= b0* impulse(i)- a1*y(i-1) - a2* y(i-2);
end
plot (y);
title('Sinusoidal waveform')
xlabel('samples n');
ylabel('y(n)');

Result:
Sinusoidal waveform is generated using IIR filter method

You might also like