You are on page 1of 104

Digital Signal processing Lab

Ex.No:
Date :
GENERATION OF SIGNALS

AIM:

To write a MATLAB for the following

(i) Plot the unit impulse function.

(ii) Plot the unit step function.

(iii)Plot the unit ramp and exponential function.

(iv)Plot the sine, cosine, saw tooth and square wave function.

ESSENTIAL REQUIRED:

Hardware: PC

Software: MATLAB 7.4

ALGORITHM:

IMPLUSE FUNCTION:

Step1: Get the time interval.

Step2: Give the respect impulse function using zeros and ones function.

Step3: Subplot and stem the sequence.

Step4: Give x label, y label and title.

Step5: Stop the program and execute it.

Department of ECE Page 1


Digital Signal processing Lab

STEP FUNCTION:

Step1: Give the number of sequences.

Step2: Get the time interval.

Step3: Give the matrix using one’s function.

Step4: Subplot and stem the sequence.

Step5: Give the x label, y label and title.

Step6: Stop the program.

RAMP FUNCTION:

Step1: Give the length of the sequence.

Step2: Give the time interval.

Step3: Subplot and stem the sequence

Step4: Give x label, y label and title.

Step5: Stop the program.

SINUSOIDAL FUNCTION:

Step1: Enter the length of the sinusoidal sequence.

Step2: Enter the number of cycle.

Step3: Get the interval and obtain sinusoidal waveform using sine function.

Step4: Subplot and stem the waveform.

Step5: Give the x label, y label and title.

Step6: Stop the program.

Department of ECE Page 2


Digital Signal processing Lab

COSINE FUNCTION

Step1: Enter the length of cosine sequence.

Step2: Enter the number of cycles.

Step3: Get the interval and obtain cosine function.

Step4: Subplot and stem the waveform.

Step5: Give x label, y label and title.

Step6: Stop the program.

EXPONENTIAL FUNCTION:

Step1: Start the exponential function.

Step2: Plot the exponential sequence in discrete domain.

Step3: Give the x label, y label and title.

Step4: Stop the program.

SAWTOOTH FUNCTION:

Step1: Set the time domain from 0 to 5.

Step2: Generate the saw tooth wave and store it.

Step3: Subplot and stem the waveform for the given time domain.

Step4: Give x label, y label and title.

Step5: Stop the program.

Department of ECE Page 3


Digital Signal processing Lab

SQUARE FUNCTION:

Step1: Set the time domain from 0 to 5.

Step2: Generate the square wave and store it.

Step3: subplot and stem the waveform for the given time domain.

Step4: Given x label, y label and title.

Step5: Stop the program.

FLOWCHART:

IMPLUSE FUNCTION:

START

Get the time interval

Compute the impulse function using zero


and ones

Plot output sequence and give


title, x label and y label

STOP

Department of ECE Page 4


Digital Signal processing Lab

STEP FUNCTION:

START

Get the number of sequences and


the time interval

Compute the step function using ones function

Plot the output sequence and give


title, x label and y label

STOP

RAMP FUNCTION:

START

Get the length of the sequence


and time interval

Compute the ramp function using zero and ones

Plot the output sequence and give


title, x label and y label

STOP

Department of ECE Page 5


Digital Signal processing Lab

SINUSOIDAL FUNCTION:

START

Enter the length of the sinusoidal


sequence and number of cycle

Get the interval and obtain sine waveform using


sine function

Plot the output sequence and give


x label, y label and title

STOP

COSINE FUNCTION

START

Enter the length of sinusoidal


sequences and number of cycle

Get the time interval and obtain cosine using cosine


function

Plot the output sequence and


give x label, y label and title

STOP

Department of ECE Page 6


Digital Signal processing Lab

EXPONENTIAL FUNCTION:

START

Set the exponential

Plot the output sequence x label,y label and tittle

STOP

SAWTOOTH FUNCTION:

START

Set the time domain from 0 to


5

Generate the saw tooth wave and store it

Plot the output sequence x


label,y label and tittle

STOP

Department of ECE Page 7


Digital Signal processing Lab

‘SQUARE FUNCTION:

START

Set the time domain form


0 to 5

Generate the sequence wave form and store it

Plot the output sequence x label,


y label and title

STOP

PROGRAM:

% TO PLOT THE UNIT IMPULSE FUNCTION

s1= [zeros(1,5),1,zeros(1,5)];

n1=-5:5;

subplot (2,2,1);

stem (n1,s1);

title ('unit impulse function');

x label ('time');

y label('amplitude');

Department of ECE Page 8


Digital Signal processing Lab

% TO PLOT THE UNIT STEP FUNCTION

s2=[zeros(1,5),ones(1,6)];

n2=-5:5;

subplot(2,2,2);

stem(n2,s2);

title('unit step function');

xlabel('time');

ylabel('amplitude');

%TO PLOT THE UNIT RAMP FUNCTION

n3=input('enter the limit= ');

n4=0:n3;

subplot(2,2,3);

stem(n4,n4);

title('unit ramp function');

xlabel('time');

ylabel('amplitude');

%TO PLOT THE EXPONENTIAL FUNCTION

n5=0:0.1:1;

subplot(2,2,4);

stem(n5,exp(n5));

title(' exponential function ');

xlabel('time');

Department of ECE Page 9


Digital Signal processing Lab

ylabel('amplitude');

%TO PLOT THE SAWTOOTH WAVEFORM

t1=0:0.1:1;

y1=sawtooth(2*pi*t1);

subplot(1,2,1);

stem(t1,y1);

title('sawtooth function ');

xlabel('time ');

ylabel('amplitude');

% TO PLOT THE SQUARE WAVEFORM

t2=0:0.1:1;

y2=square(2*pi*t2);

subplot(1,2,2);

stem(t2,y2);

title('square function ');

xlabel('time');

ylabel('amplitude');

%TO PLOT THE COSINE WAVEFORM

clear all;

close all;

vm=input('enter the amplitude');

f=input('enter frequency');

Department of ECE Page 10


Digital Signal processing Lab

t1=0:0.1:2;

y=vm*cos(2*pi*f*t1);

stem(t1,y);

title('cos wave');

xlabel('time');

ylabel('amplitude');

%TO PLOT THE SINE WAVEFORM

clc;

clear all;

close all;

vm=input('enter the amplitude');

f=input('enter frequency');

t1=0:0.1:2;

y=vm*sin(2*pi*f*t1);

stem(t1,y);

title('sine wave');

xlabel('time');

ylabel('amplitude');

Department of ECE Page 11


Digital Signal processing Lab

OUTPUT:

enter the limit= 3

unit impulse function unit step function


1 1
amplitude

amplitude
0.5 0.5

0 0
-5 0 5 -5 0 5
time time
unit ramp function exponential function
3 3

2 2
amplitude

amplitude

1 1

0 0
0 1 2 3 0 0.5 1
time time

sawtooth function square function


0.8 1

0.6 0.8

0.6
0.4

0.4
0.2

0.2
0
amplitude

amplitude

0
-0.2
-0.2

-0.4
-0.4

-0.6
-0.6

-0.8 -0.8

-1 -1
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
time time

Department of ECE Page 12


Digital Signal processing Lab

Enter the amplitude: 3

Enter frequency: 1

cos wave
3

1
amplitude

-1

-2

-3
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
time

Enter the amplitude: 3

Enter frequency: 1

sine wave
3

1
amplitude

-1

-2

-3
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
time

RESULT:
Thus the MATLAB program to generate the various sequences and waves were executed
and the results are obtained.

Department of ECE Page 13


Digital Signal processing Lab

Ex.No:
Date :

LINEAR CONVOLUTION AND CIRCULAR CONVOLUTION

AIM:

To write a MATLAB program for

1. Computing linear convolution using FFT.

2. Computing circular convolution using FFT.

ESSENTIALS REQUIRED:

HARDWARE: Zenith PC or compatible

SOFTWARE: MATLAB version 7.4.

ALGORITHM:

LINEAR CONVOLUTION USING FFT:

Step1: start the program

Step2: first enter the sequence x (n).

Step3: place the input sequence x (n).

Step4: compute the FFT for the input sequence x (n).

Step5: enter the impulse response h (n).

Step6: plot the impulse response h (n).

Step7: compute the impulse response h (n).

Department of ECE Page 14


Digital Signal processing Lab

Step8: multiply x (n) and h (n).

Step9: compute IFFT for y (n).

Step10: display the convolued sequence.

CIRCULAR CONVOLUTION USING FFT:

Step1: First enter the input sequence x(n).

Step2: Plot the input sequence x(n).

Step3: Compute the FFT for the input sequence x(n).

Step4: Enter the impulse response h(n).

Step5: Plot the impulse response h(n).

Step6: Compute FFT for the impulse response h(n).

Step7: Multiply x(n) and h(n).

Step8: Compute IFFT for y(n).

Step9: Display the convolued sequence.

Step10: Stop the program.

Department of ECE Page 15


Digital Signal processing Lab

FLOWCHART:

LINEAR CONVOLUTION USING FFT:

START

Enter the sequence x(n)

Plot the input sequence x(n)

Compute the FFT for x(n)

Enter the impulse response h(n)

Plot the impulse response h(n)

Compute FFT for h(n)

Y1=x1*h1

Compute IFFT for y1

Plot the convolued sequence y(n)

STOP

Department of ECE Page 16


Digital Signal processing Lab

CIRCULAR CONVOLUTION USING FFT:

START

Enter the sequence x(n)

Plot the input sequence x(n)

Compute FFT for x(n)

Enter the impulse response h(n)

Plot the impulse response h(n)

Compute FFT for h(n)

Y1=x1*h1

Compute IFFT for y1

Plot the convolued sequence y(n)

STOP

Department of ECE Page 17


Digital Signal processing Lab

% LINEAR CONVOLUTION USING FFT

clc;

x=input('enter the sequence x(n)');

len1=length(x);

n1=0:1:len1-1;

subplot(3,1,1);

stem(n1,x);

xlabel('time period');

ylabel('amplitude');

title('input sequence x(n)');

h=input('enter the sequence h(n)');

len2=length(h);

n2=0:1:len2-1;

subplot(3,1,2);

stem(n2,h);

n3=0:1:len-1;

x1=fft(x,len);

h1=fft(h,len);

y=x1.*h1;

xlabel('time period');

ylabel('amplitude');

title('impulse response h(n)');

len=len1+len2-1;

y=ifft(y,len);

Department of ECE Page 18


Digital Signal processing Lab

subplot(3,1,3);

disp('convoluted sequence');

disp(y);

stem(n3,y);

xlabel('time period');

ylabel('amplitude');

OUTPUT:

enter the sequence x(n):[1,-1,-1,-1,1,1,1,-1]

enter the sequence h(n):[4,3,2,1,0,0,0,0]

convolued sequence

Columns 1 through 9

4.0000 -1.0000 -5.0000 -8.0000 -2.0000 4.0000 8.0000 2.0000 0

Columns 10 through 15

-1.0000 -1.0000 0 0.0000 -0.0000 -0.0000

Department of ECE Page 19


Digital Signal processing Lab

input sequence x(n)


1
amplitude
0

-1
1 2 3 4 5 6 7 8
time index
impulse response h(n)
4
amplitude

0
1 2 3 4 5 6 7 8
time index
convolued sequence y(n)
10
amplitude

-10
0 2 4 6 8 10 12 14
time index

%CIRCULAR CONVOLUTION:

clc;

xn=input('enter the input sequence');

len1=length(xn);

n1=0:1:len1-1;

subplot(3,1,1);

stem(xn);

hn=input('enter the impulse response');

len2=length(hn);

subplot(3,1,2);

stem(hn);

len=len1+len2-1;

Department of ECE Page 20


Digital Signal processing Lab

N=len;

x=[xn zeros(1,N-len1)];

n1=length(x);

h=[hn zeros(1,N-len2)];

n2=length(h);

x1=fft(x,len);

h1=fft(h1,len);

y1=x.*h1;

y=ifft(y,len);

subplot(3,1,1);

disp('convoluted sequence');

disp(y);

n=0:1:len-1;

subplot(3,2,1);

stem(n,y);

xlabel('time period');

ylabel('amplitude');

title('convoluted sequence');

Department of ECE Page 21


Digital Signal processing Lab

Output:

enter the input sequence[1 1 1 -1]

enter the impulse response[-1 -1 1 0]

convoluted sequence

Columns 1 through 5

-0.2857 -0.6435 - 0.2854i 0.4453 - 0.1669i -0.1589 - 0.2632i -0.1589 + 0.2632i

Columns 6 through 7

0.4453 + 0.1669i -0.6435 + 0.2854i

convoluted sequence
0.5
amplitude

-0.5

-1
0 2 4 6
time period
1

-1
1 1.5 2 2.5 3 3.5 4
convolued sequence y(n)
2
amplitude

-2
0 1 2 3 4 5 6
time index

RESULT:
Thus the MATLAB program to perform (i) linear convolution using FFT
(ii) circular convolution using FFT has been written and the output sequence is obtained.

Department of ECE Page 22


Digital Signal processing Lab

Ex.No:
Date :
SAMPLING AND EFFECT OF ALIASING

AIM:

To write a MATLAB code to explain sampling a continuous time signal also obtains a graph
to obtain aliasing in time domain and frequency domain.

ESSENTIAL REQUIRED:

Hardware: Zenith Pc or Compatible.

Software: MATLAB version 5.1

ALGORITHM:

Step 1: Initialize the continuous time variable to the range between 0 and 1.

Step 2: Obtain the frequency of ct signal as input.

Step 3: Compute the ct signals.

Step 4: Display and obtain the sampling frequency > the nyquist rate of ct signal.

Step 5: Compute the sampling period and allow the time variable of the sampled signal to range
between 0 and 1 in the range of sampling period.

Step 6: Compute the sampled signal and display it if fc < nyquist rate then go to step 8.

Step 7: Obtain the sampling and frequency less than nyquist rate as input and repeat 5&6.

Step 8: Compute the dft of sampled signal for both cases and display it.

Department of ECE Page 23


Digital Signal processing Lab

FLOW CHART:

START

INITIALISE CT VARIABLE
0:0.001:1

Display

x=cos(2*pi*f*t)

Input fs>=2fm

ts=1/(fs)

x(n)=cos(2*pi*f*t)

Input fs<2fm

tsln=1/(fsln)

x(n)=cos(2*pi*f*tln)

display

DFT signal and xln area display

STOP

Department of ECE Page 24


Digital Signal processing Lab

%PROGRAM FOR SAMPLING IN TIME DOMAIN AND ALIASING IN FREQUENCY


DOMAIN

t=0:0.001:1;

f=input('Enter the frequency in cycles per sec');

x=cos(2*pi*f*t);

subplot(3,1,1);

plot(t,x);

title('continuous time signal');

xlabel('time index t');

ylabel('signal x(t)');

%SAMPLING IN TIME DOMAIN AT NYQUIST RATE

fs=input('Enter the nyquist rate fs');

ts=1/fs;

t=0:ts:1;

xn=cos(2*pi*f*t);

subplot(3,1,2);

stem(t,xn);

title('Analog signal at nyquist rate');

xlabel('time index t');

ylabel('discrete time signal x(n)');

Department of ECE Page 25


Digital Signal processing Lab

%SAMPLING IN TIME DOMAIN LESS THAN NYQUIST RATE

fsln=input('Enter the sampling frequency less than nyquist');

tsln=1/fsln;

tln=0:tsln:1;

xln=cos(2*pi*f*tln);

subplot(3,1,3);

stem(tln,xln);

title('Analog signal samples less than nyquist rate');

xlabel('time index t');

ylabel('amplitude');

figure;

%ALIASING IN FREQUENCY DOMAIN AT NYQUIST RATE

xnf=fft(xn);

subplot(2,2,1);

plot(abs(xnf));

title('frequency domain representation of signal aliased at nyquist');

xlabel('index n');

ylabel('amplitude');

Department of ECE Page 26


Digital Signal processing Lab

%ALIASING IS FREQUENCY DOMAIN LESS THAN NYQUIST RATE

xlnf=fft(xln);

subplot(2,1,2);

plot(abs(xlnf));

title('frequency domain of signal aliased at a frequency less than nyquist rate');

xlabel('index n');

ylabel('amplitude');

OUTPUT:

Enter the frequency in cycles per sec 5

continuous time signal


1
signal x(t)

0
continuous time signal
1
signal x(t)

-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0 time index t
time index t
discrete time signal x(n)

Analog signal at nyquist rate


1
Enter the nyquist rate fs 50
-1
0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
time index t
discrete time signal x(n)

-1
0 0.1 0.2 0.3 0.4 0.5
Analog signal0.6at nyquist
time index t
0.7 0.8
rate 0.9 1

1 Analog signal samples less than nyquist rate


1
amplitude

00

-1
-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0 0.1 0.2 0.3 time0.4
index t 0.5 0.6 0.7 0.8 0.9 1
time index t
Analog signal samples less than nyquist rate
1
amplitude

Department of ECE Page 27


0

-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
time index t

discrete time signal x(n)


Analog signal at nyquist rate
1
Digital Signal processing Lab
0

Enter the sampling


-1 frequency less than nyquist 20
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
time index t
Analog signal samples less than nyquist rate
1
amplitude

-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
time index t

frequency domain representation of signal aliased at nyquist


30

20
amplitude

10

0
0 20 40 60
index n
frequency domain of signal aliased at a frequency less than nyquist rate
10

8
amplitude

0
0 5 10 15 20 25
index n

RESULT:
Thus the MATLAB program to explain the concept of sampling a continuous time signal
was written and graph to explain aliasing in time domain and in frequency domain was written.

Department of ECE Page 28


Digital Signal processing Lab

Ex.No :

Date :

DESIGN OF FIR FILTERS

AIM:

To design and plot the FIR filter using hamming, hanning and Blackman window
techniques.

ESSENTIAL REQUIRED:

Hardware:PC or compatible

Software:MATLAB version 7.4

ALGORITHM:

HAMMING WINDOW:

Step 1: For the given length N, calculate alpha= (N-1)/2 and assign eps=0.001 and
wc=0.5*pi.

Step2: Calculate delayed sample response (hd) using sine function.

Step3: Calculate the rectangular window coefficients as resonant frequency (wr).

Step4: Calculate unit sample response (hn) as delayed sample tresponse(hd) multiplied by resonant
frequency wr.

Step5: Calculate the frequency of unit sample response and plot it.

Step6: Calculate the hamming window coefficients (wn) using hamming function.

Step7: Calculate hn=hd*wn.

Step8: Calculate the frequency and plot it.

HANNING WINDOW

Department of ECE Page 29


Digital Signal processing Lab

Step1: For the given length N. calculate alpha= (N-1)/2 and assign eps=0.001 and cut off

frequency wc=0.3*pi.

Step2: Calculate delayed sample response (hd) using sine function.

Step3: Claculate the rectangular window coefficient (wr).

Step4: Calculate the sample response h (n) as hd.*wr’.

Step5: Calculate the frequency of h (n) and plot.

Step6: Calculate the hanning window coefficient (wh) using hanning functions.

Step7: Calculate hn=hd.*wh’.

Step8: Calculate the frequency and plot it.

BLACKMANN WINDOW:

Step1:For the given length N,calculatealpha=(N-1)/2 and assign eps=0.001 and

wc=0.7*pi.

Step2:Calculate delayed sample response using sine function.

Step3:Calculate the rectangular window coefficient as wr.

Step4:Calculate unit sample response h(n) as hd.*wr’.

Step5:Calculate the frequency of h(n) and plot.

Step6:Calculate the blackmann window coefficient (wn) using blackmann function.

Step7:Calculate hn=hd.*wp’.

Step8:Calcul;ate the frequency the frequency and plot it.

Department of ECE Page 30


Digital Signal processing Lab

FLOWCHART:

HAMMING WINDOW:

START

Get the sequence length

Calcutate α=N-1/2 and wc=0.5*pi

Calculate the filter coefficient as hd


rect. window coefficient as wr

Calculate the FIR filter coefficient hn =hd*wr’

Find the frequency domain response of h(n)

Plot the frequency domain response

Compute hamming window coefficient wh and corresponding filter


coefficient

Calculate frequency domain representation of

h(n)

H=freq(h,1,w) and plot it


Plot the frequency domain with label

STOP

Department of ECE Page 31


Digital Signal processing Lab

HANNING WINDOW:

START

Get the sequence length

Calcutate α=N-1/2 and wc=0.3*pi

Calculate the filter coefficient as hd


rect. window coefficient as wr

Calculate the FIR filter coefficient hn =hd*wr’

Find the frequency domain response of h(n)

Plot the frequency domain response

Compute hanning window coefficient wh and corresponding filter


coefficient

Calculate frequency domain representation of

h(n)

H=freq(h,1,w) and plot it


Plot the frequency domain with label

STOP

Department of ECE Page 32


Digital Signal processing Lab

BLACKMANN WINDOW:

START

Get the sequence length

Calcutate α=N-1/2 and wc=0.7*pi

Calculate the filter coefficient as hd


rect. window coefficient as wn

Calculate the FIR filter coefficient hn =hd*wr’

Find the frequency domain response of h(n)

Plot the frequency domain response

Compute blackmann window coefficient wh and corresponding filter


coefficient

Calculate frequency domain representation of

h(n)

H=freq(h,1,w) and plot it


Plot the frequency domain with label

STOP

Department of ECE Page 33


Digital Signal processing Lab

PROGRAM:

%TO DESIGN BLACKMAN WINDOW

clear all;
wc=0.7*pi;
N=9;
alpha=(N-1)/2;
eps=0.001;
n=0:1:N-1;
hd=sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps));
wr=boxcar(N);
hn=hd.*wr';
w=0:0.1:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h));
hold on;
wh= blackman(N);
hn=hd.*wh';
w=0:0.1:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'-*');
grid;
xlabel('normalised frequency');
ylabel('amplitude');
title('blackman window');
hold off;

Department of ECE Page 34


Digital Signal processing Lab

OUTPUT:

%TO DESIGN HAMMING WINDOW

clear all;
wc=0.5*pi;
N=9;
alpha=(N-1)/2;
eps=0.0001;
n=0:1:N-1;
hd=sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps));
wr=boxcar(N);
hn=hd.*wr';
w=0:0.1:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h));
hold on;
wh= hamming(N);

Department of ECE Page 35


Digital Signal processing Lab

hn=hd.*wh';
w=0:0.1:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'-*');
grid;
xlabel('normalised frequency');
ylabel('magnitude');
title('hamming window');
hold off;

OUTPUT:

Department of ECE Page 36


Digital Signal processing Lab

%TO DESIGN HANNING WINDOW

clear all;
wc=0.3*pi;
N=9;
alpha=(N-1)/2;
eps=0.001;
n=0:1:N-1;
hd=sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps));
wr=boxcar(N);
hn=hd.*wr';
w=0:0.1:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h));
hold on;
wh= hanning(N);
hn=hd.*wh';
w=0:0.1:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'-*');
grid;
xlabel('normalised frequency');
ylabel('magnitude');
title('hanning window');
hold off;

Department of ECE Page 37


Digital Signal processing Lab

OUTPUT:

RESULT:
Thus the FIR filter is designed and plotted using hamming, hanning and blackmann window
techniques.

Department of ECE Page 38


Digital Signal processing Lab

Ex.No :

Date :

DESIGN OF IIR FILTERS USING BUTTERWORTH TECHNIQUE

AIM:

To write a MATlab program to design a Butterworth low pass, high pass, band pass and band
reject filter.

ESSENTIALS REQUIRED:

Hardware: pc or compatible

Software: MATlab version 7.4

ALGORITHM:

Butterworth low pass filter:

Step1: Start the program.

Step2: Assign alphap=4, alphas=30, fp=400, fs=800, f=2000.

Step3: Perform omp=2*fp/f & oms=2*fs/f.

Step4: Calculate cutoff frequency and order of the filter using buttord function.

Step5: Butter function is used to calculate system function.

Step6: Assign w=0:0.01: pi.

Step7: Calculate z transform using freqz function.

Step8: Perform m=abs (h) & an=angle (h).

Step9: Stop the program.

Department of ECE Page 39


Digital Signal processing Lab

Butterworth high pass filter:

Step1: Start the program.

Step2: Assign alphap=0.4, alphas=30, fp=400, fs=800, f=2000.

Step3: Perform omp=2*fp/f & oms=2*fs/f.

Step4: Calculate cutoff frequency and order of the filter using buttord function.

Step5: Butter function is used to calculate system function.

Step6: Assign w=0:0.01: pi.

Step7: Calculate z transform using freqz function.

Step8: Perform m=20*log(abs (h)) & an=angle (h).

Step9: Stop the program.

Butterworth band pass filter:

Step1: Start the program.

Step2: Assign alphap=2, alphas=20,wp=[0.2*pi,0.4*pi],ws=[0.1*pi,0.5*pi].


Step3: Calculate cutoff frequency and order of the filter using buttord function.

Step4: Butter function is used to calculate system function.

Step5: Assign w=0:0.01: pi.

Step6: Calculate z transform using freqz function.

Step7: Perform m=20*log(abs (h)) & an=angle (h).

Step8: Plot phase in radians in y axis and normalized frequency in x axis.

Step9:Stop the program.

Department of ECE Page 40


Digital Signal processing Lab

Butterworth bandstop filter:

Step1: Start the program.

Step2: Assign alphap=2, alphas=20,wp=[0.2*pi,0.4*pi],ws=[0.1*pi,0.5*pi].


Step3: Calculate cutoff frequency and order of the filter using buttord function.

Step4: Butter function is used to calculate system function.

Step5: Assign w=0:0.01: pi.

Step6: Calculate z transform using freqz function.

Step7: Perform m=20*log(abs (h)) & an=angle (h).

Step8: Plot phase in radians in y axis and normalized frequency in x axis.

Step9:Stop the program.

Department of ECE Page 41


Digital Signal processing Lab

FLOWCHART:

Butterworth low pass filter:

Start

Assign alphap=4, alphas=30,


fp=400, fs=800, f=2000.

Calculate omp=2*fp/f & oms=2*fs/f.

Calculate cutoff frequency and order of the filter using


buttord function

Assign w=0:0.01:pi

Calculate z transform using freqz function.

And Perform m=abs (h) & an=angle (h).

Display butterworth lowpass


filter response

Stop

Department of ECE Page 42


Digital Signal processing Lab

%TO DESIGN A BUTTERWORTH LOWPASS FILTER

clear all;
alphap=4;
alphas=30;
fp=400;
fs=800;
f=2000;
omp=2*fp/f;
oms=2*fs/f;
%to find the cutoff frequency and order of the filter
[n,wn]=buttord(omp,oms,alphap,alphas)
%system function of the filter
[b,a]=butter(n,wn);
w=0:0.01:pi;
[h,om]=freqz(b,a,w,'whole');
m=abs(h);
an=angle(h);
subplot(2,1,1);
plot(om/pi,20*log(m));
grid;
xlabel('normalised frequency');
ylabel('gain in dB');
subplot(2,1,2);
plot(om/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in radians');

Department of ECE Page 43


Digital Signal processing Lab

OUTPUT:

Department of ECE Page 44


Digital Signal processing Lab

Butterworth high pass filter:

Start

Assign alphap=0.4, alphas=20,


fp=400, fs=800, f=2000.

Calculate omp=2*fp/f & oms=2*fs/f.

Calculate cutoff frequency and order of the filter using


buttord function

Assign w=0:0.01: pi

Calculate z transform using freqz function.

And Perform m=20*log(abs (h)) & an=angle (h).

Display butterworth highpass


filter response

Stop

Department of ECE Page 45


Digital Signal processing Lab

%TO DESIGN A BUTTERWORTH HIGHPASS FILTER

clear all;
alphap=0.4;
alphas=30;
fp=400;
fs=800;
f=2000;
omp=2*fp/f;
oms=2*fs/f;
%to find the cutoff frequency and order of the filter
[n,wn]=buttord(omp,oms,alphap,alphas)
%system function of the filter
[b,a]=butter(n,wn,'high');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
grid;
xlabel('normalised frequency');
ylabel('gain in dB');
subplot(2,1,2);
plot(om/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in radians');

Department of ECE Page 46


Digital Signal processing Lab

OUTPUT:

Department of ECE Page 47


Digital Signal processing Lab

Butterworth band pass filter:

Start

Assign alphap=2, alphas=20.

Calculate wp=[0.2*pi,0.4*pi],ws=[0.1*pi,0.5*pi].

Calculate cutoff frequency and order of the filter using


buttord function

Assign w=0:0.01:pi

Calculate z transform using freqz function.

And Perform m=20*log(abs (h)) & an=angle (h).

Display butterworth
bandpass filter response

Stop

Department of ECE Page 48


Digital Signal processing Lab

%TO DESIGN A BUTTERWORTH BANDPASS FILTER

clear all;
alphap=2;
alphas=20;
wp=[0.2*pi,0.4*pi];
ws=[0.1*pi,0.5*pi];
%to find the cutoff frequency and order of the filter
[n,wn]=buttord(wp/pi,ws/pi,alphap,alphas)
%system function of the filter
[b,a]=butter(n,wn);
w=0:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log(abs(h));
an=angle(h);
subplot(2,1,1);
plot(ph/pi,m);
grid;
xlabel('normalised frequency');
ylabel('gain in dB');
subplot(2,1,2);
plot(ph/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in radians');

Department of ECE Page 49


Digital Signal processing Lab

OUTPUT:

Department of ECE Page 50


Digital Signal processing Lab

Butterworth band stop filter:

Start

Assign alphap=2, alphas=20.

Calculate wp=[0.2*pi,0.4*pi],ws=[0.1*pi,0.5*pi].

Calculate cutoff frequency and order of the filter using


buttord function

Assign w=0:0.01:pi

Calculate z transform using freqz function.

And Perform m=20*log(abs (h)) & an=angle (h).

Display butterworth bandstop


filter response

Stop

Department of ECE Page 51


Digital Signal processing Lab

%TO DESIGN A BUTTERWORTH BANDREJECT FILTER

clear all;
alphap=2;
alphas=20;
wp=[0.2*pi,0.4*pi];
ws=[0.1*pi,0.5*pi];
%to find the cutoff frequency and order of the filter
[n,wn]=buttord(wp/pi,ws/pi,alphap,alphas)
%system function of the filter
[b,a]=butter(n,wn,'stop');
w=0:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log(abs(h));
an=angle(h);
subplot(2,1,1);
plot(ph/pi,m);
grid;
xlabel('normalised frequency');
ylabel('gain in dB');
subplot(2,1,2);
plot(ph/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in radians');

Department of ECE Page 52


Digital Signal processing Lab

OUTPUT:

RESULT:
Thus the MATLAB program to design a Butterworth low pass, high pass, band pass and
band reject filter is performed and graph is drawn.

Department of ECE Page 53


Digital Signal processing Lab

Ex.No :

Date :
DESIGN OF IIR FILTER USING CHEBYCHEV TECHNIQUE

AIM:

To write a MATLAB program to design a chebychev IIR filter low pass, band pass and band
reject filter.

ESSENTIAL REQUIRED:

Hardware: PC or Compatible

Software: MATLAB version 7.4.

ALGORITHM:

CHEBYSHEV-LOW PASS FILTER:

Step1: Start the program

Step2: Assign alphap=1, alphas=15

Step3: Perform the function wp=0.2*pi,ws=0.3*pi

Step4: Calculate the cutoff frequency and the order of the filter.

Step5: Assign the value w=0:0.01:pi

Step6: Calculate the z-transform using the frequency function.

Step7: Perform m=20*log(abs(h)) and an=angle(h)

Step8: Display the chebyshev low pass filter function

Step9: Stop the program.

Department of ECE Page 54


Digital Signal processing Lab

CHEBYSHEV-BAND PASS FILTER:

Step1: Start the program

Step2: Assign alphap=2, alphas=20

Step3: Perform the function wp=0.2*pi, 0.4*pi ws=0.1*pi, 0.5*pi

Step4: Calculate the cutoff frequency and the order of the function

Step5: Assign the value w=0:0.01:pi

Step6: Calculate the z-transform using the frequency function.

Step7: Perform m=20*log(abs(h)) and an=angle(h)

Step8: Display the chebyshev band pass filter function

Step9: Stop the program.

CHEBYSHEV-BAND REJECT FILTER:

Step1: Start the program.

Step2: Assign alphap=2, alphas=20

Step3: Perform the function wp=0.2*pi, 0.4*pi ws=0.1*pi, 0.5*pi

Step4: Calculate the cutoff frequency and the order of the function.

Step5: Assign the value w=0:0.01:pi

Step6: Calculate the z-transform using the frequency function.

Step7: Perform m=20*log (abs (h)) and an=angle (h)

Step8: Display the chebyshev band pass filter function

Step9: Stop the program.

Department of ECE Page 55


Digital Signal processing Lab

CHEBYSHEV-HIGH PASS FILTER:

Step1: Start the program

Step2: Assign alphap=1, alphas=15

Step3: Perform the function wp=0.2*pi,ws=0.3*pi

Step4: Calculate the cutoff frequency and the order of the filter.

Step5: Assign the value w=0:0.01:pi

Step6: Calculate the z-transform using the frequency function.

Step7: Perform m=20*log(abs(h)) and an=angle(h)

Step8: Display the chebyshev low pass filter function

Step9: Stop the program.

Department of ECE Page 56


Digital Signal processing Lab

FLOW CHART:

LOW PASS AND HIGH PASS FILTER

Start

Assign alphap=1, alphas=15

Calculate wp=0.2*pi& ws=0.3*pi.

Calculate cutoff frequency and order of the filter.

Assign w=0:0.01:pi

Calculate z transform using freqz function.

Perform m=20*log(abs(h)) and an=angle(h)

Display chebychev low pass


&high pass filter response

Stop

Department of ECE Page 57


Digital Signal processing Lab

BAND PASS AND BAND REJECT FILTERS:

Start

Assign alphap=2, alphas=20

Calculate wp=[0.2*pi,0.4*pi]&
ws=[0.1*pi,0.5*pi]

Calculate cutoff frequency and order of the filter.

Assign w=0:0.01:pi

Calculate z transform using freqz function.

Perform m=20*log10(abs(h)) for band pass and


m=20*log(abs(h)) for band reject &an=angle(h)

Display chebychev band pass and


band reject filter response

Stop

Department of ECE Page 58


Digital Signal processing Lab

PROGRAM:

%TO DESIGN A CHEBYCHEV LOW PASS FILTER

clear all;

alphap=1;

alphas=15;

wp=0.2*pi;

ws=0.3*pi;

%to find cuttoff frequency and order of filter

[n,wn]=cheb1ord(wp/pi,ws/pi,alphap,alphas);

%system function of the filter

[b,a]=cheby1(n,alphap,wn);

w=0:0.01:pi;

[h,ph]=freqz(b,a,w);

m=20*log(abs(h));

an=angle(h);

subplot(2,1,1);

plot(ph/pi,m);

grid;

ylabel('Gain in dB');

xlabel('Normalised frequency');

subplot(2,1,2);

plot(ph/pi,an);

grid;

title('low pass filter');

Department of ECE Page 59


Digital Signal processing Lab

ylabel('Phase in radians');

xlabel('Normalised frequency');

%TO DESIGN A CHEBYCHEV HIGH PASS FILTER

clear all;

alphap=1;

alphas=15;

wp=0.2*pi;

ws=0.1*pi;

%to find cuttoff frequency and order of filter

[n,wn]=cheb1ord(wp/pi,ws/pi,alphap,alphas);

%system function of the filter

[b,a]=cheby1(n,alphas,wn,'high');

w=0:0.01:pi;

[h,ph]=freqz(b,a,w);

m=abs(h);

an=angle(h);

subplot(2,1,1);

plot(ph/pi,m);

grid;

title('high pass filter');

ylabel('Gain in dB');

xlabel('Normalised frequency');

subplot(2,1,2);

plot(ph/pi,an);

Department of ECE Page 60


Digital Signal processing Lab

grid;

title('high pass filter');

ylabel('Phase in radians');

xlabel('Normalised frequency');

%TO DESIGN A CHEBYCHEV BAND PASS FILTER

clear all;

alphap=2;

alphas=20;

wp=[0.2*pi,.4*pi];

ws=[0.1*pi,.5*pi];

%to find cuttoff frequency and order of filter

[n,wn]=buttord(wp/pi,ws/pi,alphap,alphas);

%system function of the filter

[b,a]=cheby1(n,alphap,wn);

w=0:0.01:pi;

[h,ph]=freqz(b,a,w);

m=20*log10(abs(h));

an=angle(h);

subplot(2,1,1);

plot(ph/pi,m);

grid;

title('BAND PASS FILTER');

ylabel('Gain in dB');

Department of ECE Page 61


Digital Signal processing Lab

xlabel('Normalised frequency');

subplot(2,1,2);

plot(ph/pi,an);

grid;

title('band pass filter');

ylabel('Phase in radians');

xlabel('Normalised frequency');

%TO DESIGN A CHEBYCHEV BAND REJECT FILTER

clear all;

alphap=2;

alphas=20;

wp=[0.2*pi,.4*pi];

ws=[0.1*pi,.5*pi];

%to find cuttoff frequency and order of filter

[n,wn]=cheb2ord(wp/pi,ws/pi,alphap,alphas);

%system function of the filter

[b,a]=cheby2(n,alphas,wn,'stop');

w=0:0.01:pi;

[h,ph]=freqz(b,a,w);

m=20*log(abs(h));

an=angle(h);

subplot(2,1,1);

plot(ph/pi,m);

grid;

Department of ECE Page 62


Digital Signal processing Lab

title('Band reject filter');

ylabel('Gain in dB');

xlabel('Normalised frequency');

subplot(2,1,2);

plot(ph/pi,an);

grid;

title('band reject filter');

ylabel('Phase in radians');

xlabel('Normalised frequency'

OUTPUT:

LOW PASS FILTER

low pass filter


0

-200
Gain in dB

-400

-600

-800
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
low pass filter
4
Phase in radians

-2

-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency

Department of ECE Page 63


Digital Signal processing Lab

BAND PASS FILTER

BAND PASS FILTER


0

-100
Gain in dB

-200

-300

-400
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
band pass filter
4
Phase in radians

-2

-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency

BAND REJECT FILTER

Band reject filter


0

-50
Gain in dB

-100

-150

-200
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
band reject filter
4
Phase in radians

-2

-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency

Department of ECE Page 64


Digital Signal processing Lab

HIGH PASS FILTER

high pass filter


1
Gain in dB

0.5

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
high pass filter
4
Phase in radians

-2

-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency

RESULT:
Thus the MATLAB program to design and plot the low pass, high pass, band pass, band
reject using chebyshev filter technique and the output is verified.

Department of ECE Page 65


Digital Signal processing Lab

Ex.No :
Date :
CALCULATION OF FFT OF A SIGNAL

AIM:

To write the MATLAB program for the following given sequence


x(n)=[0,1,2,3,4,5,6,7] .compute and plot the 8 point DFT and IDFT of the sequence .

ESSENTIALS REQUIRED:

Hardware: pc or compatible

Software: MATLAB version7.4

ALGORITHM:

DISCRETE FOURIER TRANSFORM

Step1: Start the program.

Step2: First enter the sequence x (n).

Step3: Plot the input sequence x (n).

Step4: Compute DFT of the sequence using FFT algorithm.

Step5: Display the DFT sequences.

Step6: Plot the real part.

Step7: Plot the imaginary part.

Step8: Use abs command to obtain magnitude plot.

Step9: Use angle command to obtain the phase plot and plot it.

Step10: Stop the program.

Department of ECE Page 66


Digital Signal processing Lab

INVERSE DISCRETE FOURIER TRANSFORM

Step1: Start the program.

Step2: First enter the sequence X (k).

Step3: Plot the input sequence X (k).

Step4: Compute IDFT of the sequence using IFFT command.

Step5: Display the IDFT sequence.

Step6: Plot the real part.

Step7: Plot the imaginary part.

Step8: Use abs command to obtain magnitude plot.

Step9: Use angle command to obtain the phase plot and plot it.

Step10: Stop the program.

Department of ECE Page 67


Digital Signal processing Lab

FLOW CHART:

DISCRETE FOURIER TRANSFORM

Start

Enter the sequence x(n)

Plot the sequence x(n)

Compute DFT using FFT algorithm

Display the DFT sequence

Plot the real part

Plot the imaginary part

Plot the magnitude using

abs command

Plot the phase using angle


command

Stop

Department of ECE Page 68


Digital Signal processing Lab

INVERSE DISCRETE FOURIER TRANSFORM

Start

Enter the sequence x(n)

Plot the sequence x(n)

Compute IDFT using IFFT command

Display the IDFT sequence

Plot the real part

Plot the imaginary part

Plot the magnitude using

abs command

Plot the phase using angle


command

Stop

Department of ECE Page 69


Digital Signal processing Lab

PROGRAM:

%COMPUTATION OF DFT

x=input ('Enter the sequence');

n=length(x);

y=fft(x,n);

subplot (2,2,1);

stem (1:n,real(y));

title ('Real part of x(k):');

xlabel('Index k');

ylabel('real of x(k)');

subplot (2,2,2);

stem (1:n,imag(y));

title ('Imaginary part of x(k):');

xlabel('index of k');

ylabel('imag of x(k)');

m=abs(y);

subplot (2,2,3);

stem (m);

title ('magnitude of x(k):');

xlabel('index of f');

ylabel('magnitude of x(k)');

disp(real(y));

disp('imag of x(k)');

disp(imag(y));

Department of ECE Page 70


Digital Signal processing Lab

disp('Magnitude of x(k):');

disp(m);

p=angle(y);

subplot (2,2,4);

stem (p);

title ('phase of x(k)');

xlabel('index of k');

ylabel('phase of x(k)');

disp('phase of x(k):');

disp(p);

INPUT:

Enter the sequence[1 2 3 4 5]

15.0000 -2.5000 -2.5000 -2.5000 -2.5000

imag of x(k)

0 3.4410 0.8123 -0.8123 -3.4410

Magnitude of x(k):

15.0000 4.2533 2.6287 2.6287 4.2533

phase of x(k):

0 2.1991 2.8274 -2.8274 -2.1991

Department of ECE Page 71


Digital Signal processing Lab

OUTPUT:

Real part of x(k): Imaginary part of x(k):


15 4

10 2

imag of x(k)
real of x(k)

5 0

0 -2

-5 -4
1 2 3 4 5 1 2 3 4 5
Index k index of k
magnitude of x(k): phase of x(k)
15 4
magnitude of x(k)

2
phase of x(k)
10
0
5
-2

0 -4
1 2 3 4 5 1 2 3 4 5
index of f index of k

%COMPUTATION OF IDFT

clc;

clear all;

close all;

x=input('enter the sequence:');

n=length(x);

y=ifft(x,n);

subplot(2,2,1);

stem(1:n,real(y));

title('real part of x(k)');

xlabel('index of k');

ylabel('real of x(k)');

subplot(2,2,2);

Department of ECE Page 72


Digital Signal processing Lab

stem(1:n,imag(y));

title('imaginary part of x(k)');

xlabel('index of k');

ylabel('imaginary of x(k)');

m=abs(y);

subplot(2,2,3);

stem(m);

title('magnitude of x(k)');

xlabel('index of f');

ylabel('real of x(k)');

disp('real of x(k)');

disp(real(y));

disp('imaginary of x(k)');

disp(imag(y));

disp('magnitude of x(k)');

disp(m);

p=angle(y);

subplot(2,2,4);

stem(p);

title('phase of x(k)');

xlabel('index of k');

ylabel('real of x(k)');

disp('phase of x(k)');

disp(p);

Department of ECE Page 73


Digital Signal processing Lab

INPUT:

enter the sequence:[2 4 6 8]

real of x(k)

5 -1 -1 -1

imaginary of x(k)

0 -1 0 1

magnitude of x(k)

5.0000 1.4142 1.0000 1.4142

phase of x(k)

0 -2.3562 3.1416 2.3562

OUTPUT:

real part of x(k) imaginary part of x(k)


6 1
imaginary of x(k)

4 0.5
real of x(k)

2 0

0 -0.5

-2 -1
1 2 3 4 1 2 3 4
index of k index of k
magnitude of x(k) phase of x(k)
6 4

2
real of x(k)

real of x(k)

4
0
2
-2

0 -4
1 2 3 4 1 2 3 4
index of f index of k

RESULT:
Thus the computation of N-point DFT and IDFT was done and the output was obtained.

Department of ECE Page 74


Digital Signal processing Lab

Ex.No:
Date :

WAVEFORM GENERATION

AIM:

 To generate triangular waveform of DAC channel.


 To generate the sine waveform at DAC port.
 To generate the square waveform at DAC port.

ESSENTIALS REQUIRED:

DSP trainer kit: TMS 320C50

Universal debugger for C50

PROGRAM:

;square waveform generation.

.mmregs

.text

start:

ldp #100h

lacc #0fffh ;change this value for amplitude.

loop: sacl 0

rpt #0ffh ;change this value for frequency.

out 0,04 ;address for dac.

cmpl

b loop

.end

Department of ECE Page 75


Digital Signal processing Lab

;triangle waveform generation

AMPLITUDE .SET 4

FREQ .SET 350

TEMP .SET 0

.mmregs

.text

START:

LDP #100H

splk #0,TEMP

CONT1:

lar AR2,#FREQ

CONT:

out TEMP,4

LACC TEMP

ADD #AMPLITUDE

SACL TEMP

MAR *,AR2

BANZ CONT,*-

LAR AR2,#FREQ

CONTx:

OUT TEMP,4

LACC TEMP

Department of ECE Page 76


Digital Signal processing Lab

SUB #AMPLITUDE

SACL TEMP

MAR *,AR2

BANZ CONTx

B CONT1

.end

Sine Wave Generation. With these default values sine generated is 100 Hz.

INCFREQ .set 10 ;minimum value 1 - change for increasing frequency

;every count will increase frequency in steps of 100hz

DECFREQ .set 0 ;minimu value 0 - change for decreasing frequency

;every count will decrease frequency by half

LENGTH .set 360

AMPLITUDE .set 5

delay .set 7 ;change to increase/decrease frequency in

;different steps;

TEMP .set 0

TEMP1 .set 1

.mmregs

.text

START:

LDP #100H

Department of ECE Page 77


Digital Signal processing Lab

SPLK #TABLE,TEMP ;load start address of table

lar AR2,#( (LENGTH/INCFREQ)+(LENGTH*DECFREQ) )-1

lar ar3,#DECFREQ ;repeat counter for reducing frequency

CONT:

CALL DELAY

LACC TEMP ;load address of sine value

TBLR TEMP1 ;read sine data to TEMP1

LT TEMP1

MPY #AMPLITUDE

PAC

SACL TEMP1

mar *,ar3

banz repeat,*-

lar ar3,#DECFREQ ;repeat counter for reducing frequency

LACC TEMP

ADD #INCFREQ ;increase table value

repeat:

SACL TEMP ;store it

OUT TEMP1,4 ;send sine data to DAC

MAR *,AR2

BANZ CONT,*-

b START

Department of ECE Page 78


Digital Signal processing Lab

DELAY:

lar ar7,#delay

mar *,ar7

back: banz back,*-

ret

TABLE

.word 100

.word 101

.word 103

.word 105

.word 106

.word 108

.word 110

.word 112

.word 113

.word 115

.word 117

.word 119

.word 120

.word 122

.word 124

.word 125

.word 127

.word 129

Department of ECE Page 79


Digital Signal processing Lab

.word 130

.word 132

.word 134

.word 135

.word 137

.word 139

.word 140

.word 142

.word 143

.word 145

.word 146

.word 148

.word 150

.word 151

.word 152

.word 154

.word 155

.word 157

.word 158

.word 160

.word 161

.word 162

.word 164

.word 165

.word 166

.word 168

.word 169

.word 170

Department of ECE Page 80


Digital Signal processing Lab

.word 171

.word 173

.word 174

.word 175

.word 176

.word 177

.word 178

.word 179

.word 180

.word 181

.word 182

.word 183

.word 184

.word 185

.word 186

.word 187

.word 188

.word 189

.word 189

.word 190

.word 191

.word 192

.word 192

.word 193

.word 193

.word 194

.word 195

.word 195

Department of ECE Page 81


Digital Signal processing Lab

.word 196

.word 196

.word 197

.word 197

.word 197

.word 198

.word 198

.word 198

.word 199

.word 199

.word 199

.word 199

.word 199

.word 199

.word 199

.word 199

.word 200

.word 199

.word 199

.word 199

.word 199

.word 199

.word 199

.word 199

.word 199

.word 198

.word 198

.word 198

Department of ECE Page 82


Digital Signal processing Lab

.word 197

.word 197

.word 197

.word 196

.word 196

.word 195

.word 195

.word 194

.word 193

.word 193

.word 192

.word 192

.word 191

.word 190

.word 189

.word 189

.word 188

.word 187

.word 186

.word 185

.word 184

.word 183

.word 182

.word 181

.word 180

.word 179

.word 178

.word 177

Department of ECE Page 83


Digital Signal processing Lab

.word 176

.word 175

.word 174

.word 173

.word 171

.word 170

.word 169

.word 168

.word 166

.word 165

.word 164

.word 162

.word 161

.word 160

.word 158

.word 157

.word 155

.word 154

.word 152

.word 151

.word 149

.word 148

.word 146

.word 145

.word 143

.word 142

.word 140

.word 139

Department of ECE Page 84


Digital Signal processing Lab

.word 137

.word 135

.word 134

.word 132

.word 130

.word 129

.word 127

.word 125

.word 124

.word 122

.word 120

.word 119

.word 117

.word 115

.word 113

.word 112

.word 110

.word 108

.word 106

.word 105

.word 103

.word 101

.word 99

.word 98

.word 96

.word 94

.word 93

.word 91

Department of ECE Page 85


Digital Signal processing Lab

.word 89

.word 87

.word 86

.word 84

.word 82

.word 80

.word 79

.word 77

.word 75

.word 74

.word 72

.word 70

.word 69

.word 67

.word 65

.word 64

.word 62

.word 60

.word 59

.word 57

.word 56

.word 54

.word 53

.word 51

.word 49

.word 48

.word 47

.word 45

Department of ECE Page 86


Digital Signal processing Lab

.word 44

.word 42

.word 41

.word 39

.word 38

.word 37

.word 35

.word 34

.word 33

.word 31

.word 30

.word 29

.word 28

.word 26

.word 25

.word 24

.word 23

.word 22

.word 21

.word 20

.word 19

.word 18

.word 17

.word 16

.word 15

.word 14

.word 13

.word 12

Department of ECE Page 87


Digital Signal processing Lab

.word 11

.word 10

.word 10

.word 9

.word 8

.word 7

.word 7

.word 6

.word 6

.word 5

.word 4

.word 4

.word 3

.word 3

.word 2

.word 2

.word 2

.word 1

.word 1

.word 1

.word 0

.word 0

.word 0

.word 0

.word 0

.word 0

.word 0

.word 0

Department of ECE Page 88


Digital Signal processing Lab

.word 0

.word 0

.word 0

.word 0

.word 0

.word 0

.word 0

.word 0

.word 0

.word 1

.word 1

.word 1

.word 2

.word 2

.word 2

.word 3

.word 3

.word 4

.word 4

.word 5

.word 6

.word 6

.word 7

.word 7

.word 8

.word 9

.word 10

.word 10

Department of ECE Page 89


Digital Signal processing Lab

.word 11

.word 12

.word 13

.word 14

.word 15

.word 16

.word 17

.word 18

.word 19

.word 20

.word 21

.word 22

.word 23

.word 24

.word 25

.word 26

.word 28

.word 29

.word 30

.word 31

.word 33

.word 34

.word 35

.word 37

.word 38

.word 39

.word 41

.word 42

Department of ECE Page 90


Digital Signal processing Lab

.word 44

.word 45

.word 47

.word 48

.word 50

.word 51

.word 53

.word 54

.word 56

.word 57

.word 59

.word 60

.word 62

.word 64

.word 65

.word 67

.word 69

.word 70

.word 72

.word 74

.word 75

.word 77

.word 79

.word 80

.word 82

.word 84

.word 86

.word 87

Department of ECE Page 91


Digital Signal processing Lab

.word 89

.word 91

.word 93

.word 94

.word 96

.word 98

.word 100

.end

SAWTOOTH WAVEFORM GENERRATION

.MMREGS

.TEXT

START:

LDP #120H

LACC #0H ;change lower amplitude

SACL 0

LOOP: LACC 0

OUT 0,04H

ADD #05h ;change frequency

SACL 0

SUB #0FFFh ;change upper amplitude

BCND LOOP,LEQ

B START

.END

Result:
Thus the waveforms are generated using DSP processor.

Department of ECE Page 92


Digital Signal processing Lab

Ex.No:
Date :

IMPLEMENTATION OF CONVOLUTION

AIM:

To calculate the convolution using DSP processor for the sequence.

x (n)=[1 3 1 3]

h (n)=[0 1 2 1]

ESSENTIALS REQUIRED:

DSP trainer kit: TMS 320C50

Universal debugger for C50

PROGRAM:

.mmregs

.text

START:

LDP #02H

LAR AR1,#8100H ; x(n) datas

lar ar0,#08200H ;h(n) datas

LAR AR3,#8300H ;y(n) starting

LAR AR4,#0007 ;N1+N2-1

Department of ECE Page 93


Digital Signal processing Lab

;to fold the h(n) values

lar ar0,#8203H ; data mem 8200 to program mem c100(tblw)

lacc #0c100h

mar *,ar0

rpt #3

tblw *- ;to move 8203- 8200 to c100- c103

;padding of zerros for x(n) values

lar ar6,#8104h

mar *,ar6

lacc #0h

rpt #3h

sacl *+

;convalution operation starts

LOP: MAR *,AR1

LACC *+

SACL 050H ;starting of the scope of multiplication

LAR AR2,#0153H ; end of the array, to be multiplied with h(n) {150+N1-1}

MAR *,AR2

Department of ECE Page 94


Digital Signal processing Lab

ZAP

RPT #03H ;N1-1 times so that N1 times

MACD 0C100H,*-

APAC ;to accmulate the final product sample

MAR *,AR3

SACL *+

MAR *,AR4

BANZ LOP,*-

H: B H

RESULT:

Thus the linear convolution using DSP processor was calculated and the output is verified.

Department of ECE Page 95


Digital Signal processing Lab

Ex.No:
Date :

IMPLEMENTATION OF FIR FILTER

AIM:

To implement a band pass and band reject FIR filter using Blackmann window.

APPARATUS REQUIRED:

DSP trainer kit: TMS 320C50

Universal debugger for C50

PROGRAM:

BAND PASS:

* Approximation type: Window design - Blackmann Window

* Filter type: bandpass filter

* Filter Order: 52

* lower Cutoff frequency in KHz = 3.000000Hz

* upper Cutoff frequency in KHz = 5.000000Hz

.mmregs
.text

B START

CTABLE:

.word 024AH

Department of ECE Page 96


Digital Signal processing Lab

.word 010FH
.word 0FH
.word 0FFECH
.word 0C6H
.word 0220H
.word 0312H
.word 02D3H
.word 012FH
.word 0FEBDH
.word 0FC97H
.word 0FBCBH
.word 0FCB0H
.word 0FE9EH
.word 029H
.word 0FFDCH
.word 0FD11H
.word 0F884H
.word 0F436H
.word 0F2A0H
.word 0F58AH
.word 0FD12H
.word 075FH
.word 01135H
.word 01732H
.word 01732H
.word 01135H
.word 075FH
.word 0FD12H
.word 0F58AH
.word 0F2A0H
.word 0F436H
.word 0F884H
.word 0FD11H
.word 0FFDCH
.word 029H
.word 0FE9EH
.word 0FCB0H
.word 0FBCBH
.word 0FC97H
.word 0FEBDH
.word 012FH
.word 02D3H
.word 0312H
.word 0220H
.word 0C6H

Department of ECE Page 97


Digital Signal processing Lab

.word 0FFECH
.word 0FH
.word 010FH
.word 024AH
*
* Move the Filter coefficients
* from program memory to data memory

START:

MAR *,AR0

LAR AR0,#0200H

RPT #33H

BLKP CTABLE,*+

SETC CNF

* Input data and perform convolution

ISR: LDP #0AH

LACC #0

SACL 0

OUT 0,05 ;pulse to find sampling frequency

IN 0,06H

LAR AR7,#0 ;change value to modify sampling freq.

Department of ECE Page 98


Digital Signal processing Lab

MAR *,AR7

BACK: BANZ BACK,*-

IN 0,4

NOP

NOP

NOP

NOP

MAR *,AR1

LAR AR1,#0300H

LACC 0

AND #0FFFH

SUB #800H

SACL *

LAR AR1,#333H

MPY #0

ZAC

RPT #33H

MACD 0FF00H,*-

APAC

LAR AR1,#0300H

Department of ECE Page 99


Digital Signal processing Lab

SACH * ;give as sach *,1 incase of overflow

LACC *

ADD #800H

SACL *

OUT *,4

LACC #0FFH

SACL 0

OUT 0,05

NOP

B ISR

.end

BAND REJECT:

* Approximation type: Window design - Blackmann Window

* Filter type: bandreject filter

* Filter Order: 52

* lower Cutoff frequency in KHz = .000000Hz

* upper Cutoff frequency in KHz = .000000Hz

.mmregs

.text

B START

Department of ECE Page 100


Digital Signal processing Lab

CTABLE:

.word 0FEB9H
.word 14EH
.word 0FDA1H
.word 155H
.word 0FE1BH
.word 282H
.word 0FEAFH
.word 2ACH
.word 0FD35H
.word 8DH
.word 0F9D9H
.word 0FE07H
.word 0F7CCH
.word 0FEE2H
.word 0FA2FH
.word 4BAH
.word 1AH
.word 25CH
.word 420H
.word 1008H
.word 89H
.word 0D61H
.word 0F3F2H
.word 0AF9H
.word 0DB7EH
.word 045DFH
.word 045DFH
.word 0DB7EH
.word 0AF9H
.word 0F3F2H
.word 0D61H
.word 89H
.word 1008H
.word 420H
.word 25CH
.word 1AH
.word 4BAH
.word 0FA2FH
.word 0FEE2H
.word 0F7CCH
.word 0FE07H
.word 0F9D9H
.word 8DH
.word 0FD35H
.word 2ACH

Department of ECE Page 101


Digital Signal processing Lab

.word 0FEAFH
.word 282H
.word 0FE1BH
.word 155H
.word 0FDA1H
.word 14EH
.word 0FEB9H

* Move the Filter coefficients

* from program memory to data memory

START:

MAR *,AR0

LAR AR0,#0200H

RPT #33H

BLKP CTABLE,*+

SETC CNF

* Input data and perform convolution

ISR: LDP #0AH


LACC #0

Department of ECE Page 102


Digital Signal processing Lab

SACL 0

OUT 0,05 ;pulse to find sampling frequency

IN 0,06H

LAR AR7,#0 ;change value to modify sampling freq.

MAR *,AR7

BACK: BANZ BACK,*-

IN 0,4

NOP

NOP

NOP

NOP

MAR *,AR1

LAR AR1,#0300H

LACC 0

AND #0FFFH

SUB #800H

SACL *

LAR AR1,#333H

Department of ECE Page 103


Digital Signal processing Lab

MPY #0

ZAC

RPT #33H

MACD 0FF00H,*-

APAC

LAR AR1,#0300H

SACH * ;give as sach *,1 incase of overflow

LACC *

ADD #800H

SACL *

OUT *,4

LACC #0FFH

SACL 0

OUT 0,05

NOP

B ISR

.end

Result:
Thus a band pass and band reject FIR filter using Blackmann window is implemented.

Department of ECE Page 104

You might also like