0% found this document useful (0 votes)
5 views

DSP LAB

The document provides an introduction to MATLAB, detailing its functions, features, and the signal processing toolbox. It includes examples of generating various discrete-time waveforms, performing convolution of signals, and sampling rate conversion using MATLAB. The document also outlines the procedures, algorithms, and sample code for each task, emphasizing MATLAB's capabilities in scientific and engineering computations.

Uploaded by

SenthilKumar M
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

DSP LAB

The document provides an introduction to MATLAB, detailing its functions, features, and the signal processing toolbox. It includes examples of generating various discrete-time waveforms, performing convolution of signals, and sampling rate conversion using MATLAB. The document also outlines the procedures, algorithms, and sample code for each task, emphasizing MATLAB's capabilities in scientific and engineering computations.

Uploaded by

SenthilKumar M
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 60

EX.

NO:1
DATE:
INTRODUCTION TO MATLAB

AIM:
To familiarise with MATLAB software, general functions and signal
processing toolbox functions
THEORY:
The name MATLAB stands for MATrix LABoratory produced by
Mathworks Inc., USA. It is a matrix-based
powerful software package for scientific and engineering computation and
visualization. Complex numerical problems
can be solved in a fraction of the time that required with other high level
languages. It provides an interactive environment
with hundreds of built -in –functions for technical computation, graphics and
animation. In addition to built-in-functions,
user can create his own functions.
MATLAB offers several optional toolboxes, such as signal processing,
control systems, neural networks etc.
It is command driven software and has online help facility.
MATLAB has three basic windows normally; command window, graphics
window and edit window.
Command window is characterized by the prompt ‘>>’.
All commands and the ready to run program filename can be typed here.
Graphic window gives the display of the figures as
the result of the program. Edit window is to create program files with an
extension .m.
Some important commands in MATLAB
Help List topics on which help is available
Help command name Provides help on the topic selected
Demo Runs the demo program
Who Lists variables currently in the workspace
Whos Lists variables currently in the workspace with their size
Clear Clears the workspace, all the variables are removed
Clear x,y,z Clears only variables x,y,z
Quit Quits MATLAB

1
Some of the frequently used built-in-functions in Signal Processing
Toolbox
filter(b.a.x) Syntax of this function is Y = filter(b.a.x)
It filters the data in vector x with the filter described by vectors
a and b to create the filtered data y.
fft (x) It is the DFT of vector x
ifft (x) It is the DFT of vector x
conv (a,b) Syntax of this function is C = conv (a,b)
It convolves vectors a and b. The resulting vector is of
Length, Length (a) + Length (b)-1
deconv(b,a) Syntax of this function is [q,r] = deconv(b,a)
It deconvolves vector q and the remainder in vector r such that
b = conv(a,q)+r
butter(N,Wn) designs an Nth order lowpass digital
Butterworth filter and returns the filter coefficients in length
N+1 vectors B (numerator) and A (denominator). The coefficients
are listed in descending powers of z. The cutoff frequency
Wn must be 0.0 < Wn < 1.0, with 1.0 corresponding to
half the sample rate.
buttord(Wp, Ws, Rp, Rs) returns the order N of the lowest
order digital Butterworth filter that loses no more than Rp dB in
the passband and has at least Rs dB of attenuation in the stopband.
Wp and Ws are the passband and stopband edge frequencies,
Normalized from 0 to 1 ,(where 1 corresponds to pi rad/sec)
Cheby1(N,R,Wn) designs an Nth order lowpass digital
Chebyshev filter with R decibels of peak-to-peak ripple in the
passband. CHEBY1 returns the filter coefficients in length N+1
vectors B (numerator) and A (denominator). The cutoff frequency
Wn must be 0.0 < Wn < 1.0, with 1.0 corresponding to half the
sample rate.
Cheby1(N,R,Wn,'high') designs a highpass filter.
Cheb1ord(Wp, Ws, Rp, Rs) returns the order N of the lowest
order digital Chebyshev Type I filter that loses no more than Rp dB
in the passband and has at least Rs dB of attenuation in the stopband.
Wp and Ws are the passband and stopband edge frequencies, normalized
from 0 to 1 (where 1 corresponds to pi radians/sample)
cheby2(N,R,Wn) designs an Nth order lowpass digital
Chebyshev filter with the stopband ripple R decibels down and
stopband edge frequency Wn. CHEBY2 returns the filter

2
coefficients in length N+1 vectors B (numerator) and A .
The cutoff frequency Wn must be 0.0 < Wn < 1.0, with 1.0 corresponding
to half the sample rate.
cheb2ord(Wp, Ws, Rp, Rs) returns the order N of the lowest
order digital Chebyshev Type II filter that loses no more than Rp dB
in the passband and has at least Rs dB of attenuation in the stopband.
Wp and Ws are the passband and stopband edge frequencies,
abs(x) It gives the absolute value of the elements of x. When x is
complex, abs(x) is the complex modulus (magnitude)
of the elements of x.
butter(N,Wn) designs an Nth order lowpass digital
Butterworth filter and returns the filter coefficients in length
N+1 vectors B (numerator) and A (denominator). The coefficients
are listed in descending powers of z. The cutoff frequency
Wn must be 0.0 < Wn < 1.0, with 1.0 corresponding to
half the sample rate.
buttord(Wp, Ws, Rp, Rs) returns the order N of the lowest
order digital Butterworth filter that loses no more than Rp dB in
the passband and has at least Rs dB of attenuation in the stopband.
Wp and Ws are the passband and stopband edge frequencies,
Normalized from 0 to 1 ,(where 1 corresponds to pi rad/sec)
Cheby1(N,R,Wn) designs an Nth order lowpass digital
Chebyshev filter with R decibels of peak-to-peak ripple in the
passband. CHEBY1 returns the filter coefficients in length N+1
vectors B (numerator) and A (denominator). The cutoff frequency
Wn must be 0.0 < Wn < 1.0, with 1.0 corresponding to half the
sample rate.
Cheby1(N,R,Wn,'high') designs a highpass filter.
Cheb1ord(Wp, Ws, Rp, Rs) returns the order N of the lowest
order digital Chebyshev Type I filter that loses no more than Rp dB
in the passband and has at least Rs dB of attenuation in the stopband.
Wp and Ws are the passband and stopband edge frequencies, normalized
from 0 to 1 (where 1 corresponds to pi radians/sample)
cheby2(N,R,Wn) designs an Nth order lowpass digital
Chebyshev filter with the stopband ripple R decibels down and
stopband edge frequency Wn. CHEBY2 returns the filter
coefficients in length N+1 vectors B (numerator) and A .
The cutoff frequency Wn must be 0.0 < Wn < 1.0, with 1.0 corresponding
to half the sample rate.

3
cheb2ord(Wp, Ws, Rp, Rs) returns the order N of the lowest
order digital Chebyshev Type II filter that loses no more than Rp dB
in the passband and has at least Rs dB of attenuation in the stopband.
Wp and Ws are the passband and stopband edge frequencies,
abs(x) It gives the absolute value of the elements of x. When x is
complex, abs(x) is the complex modulus (magnitude)
of the elements of x.

RESULT:
Thus the details about MATLAB software is studied.

4
EX. NO:2
DATE:
WAVEFORM GENERATION

AIM:
Write a program in MATLAB to generate the following waveforms
(Discrete – Time signal)

1. Unit Impulse sequence,


2. Unit step sequence,
3. Unit Ramp sequence,
4. Sinusoidal sequence,
5. Exponential sequence,
6. Random sequence,

APPARATUS REQUIRED:
Pentium 4 Processor, MATLAB software
THEORY:
Real signals can be quite complicated. The study of signals therefore
starts with the analysis of basic and fundamental signals. For linear systems,
a complicated signal and
its behaviour can be studied by superposition of basic signals. Common
basic signals
are:

Discrete – Time signals:


1, for n 0
x (n)  (n)  
 Unit impulse sequence. 0, otherwise
1, for n 0
x ( n )  u( n )  
 Unit step sequence. 0, otherwise

5
n, for n 0
x ( n)  r ( n)  
 Unit ramp sequence. 0, otherwise
 Sinusoidal sequence. x(n)  A sin(n   ) .

 Exponential sequence. x(n) = A an, where A and a are constant.

ALGORITHM/PROCEDURE:
1. Start the program
2. Get the inputs for signal generation
3. Use the appropriate library function
4. Display the waveform

%WAVE FORM GENERATION


%DT SIGNAL
%UNIT IMPULSE
clc;
clear all;
close all;
n1=-3:1:3;
x1=[0,0,0,1,0,0,0];
subplot(2,3,1);
stem(n1,x1);
xlabel('time');
ylabel('Amplitude');
title('Unit impulse signal');
%UNIT STEP SIGNAL
n2=-5:1:25;
x2=[zeros(1,5),ones(1,26)];
subplot(2,3,2);
stem(n2,x2);
xlabel('time');
ylabel('Amplitude');
title('Unit step signal');
6
%EXPONENTIAL SIGNAL
a=input('Enter the value of a:');
n3=-10:1:20;
x3=power(a,n3);
subplot(2,3,3);
stem(n3,x3);
xlabel('time');
ylabel('Amplitude');
title('Exponential signal');
%UNIT RAMP SIGNAL
n4=-10:1:20;
x4=n4;
subplot(2,3,4);
stem(n4,x4);
xlabel('time');
ylabel('Amplitude');
title('Unit ramp signal');
%SINUSOIDAL SIGNAL
A=input('Enter the amplitude:');
f=input('Enter the frequency:');
n5=-10:1:20;
x5=A*sin(2*pi*f*n5);
subplot(2,3,5);
stem(n5,x5);
xlabel('time');
ylabel('Amplitude');
title('Sinusoidal signal');
%RANDOM SIGNAL
n6=-10:1:20;
x6=rand(1,31);
subplot(2,3,6);
stem(n6,x6);
xlabel('time');
ylabel('Amplitude');
title('Random signal');

7
FLOWCHART:

START

ENTER THE SIGNAL PARAMETERS


(AMPLITUDE, TIME AND
FREQUENCY)

Generate the waveform by using the appropriate


library function

PLOT THE WAVEFORMS

STOP

RESULT:
The program to generate various waveforms is written, executed
and the
output is verified.

8
EX. NO:3
DATE:
CONVOLUTION OF SIGNALS

AIM:
TO write a MATLAB program to compute convolution of two given
sequences

APPARATUS REQUIRED:
Pentium 4 Processor, MATLAB software
PROCEDURE:
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\
Figure window
ALGORITHM:-

• Read the input sequence x[n] ,and plot


• Read the impulse sequence h[n] , and
plot
• Use the matlab function ‘conv’
• Convolve the two sequence and plot the
result

9
PROGRAM:
LINEAR CONVOLUTION:

clc; clear all;closeall;


a=input('Enter the starting
point of x[n]='); b=input('Enter
the starting point of h[n]=');
x=input('Enter the co-
efficients of x[n]=');
h=input('Enter the co-
efficients of h[n]=');
y=conv(x,h);
subplot(3,1,1);
p=a:(a+length(x)-1);
stem(p,x);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('INPUT x(n)');
subplot(3,1,2);
q=b:(b+length(h)-1);
stem(q,h);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('IMPULSE RESPONSE
h(n)');
subplot(3,1,3);
10
n=a+b:length(y)+a+b-1;
stem(n,y);
grid on;
disp(y)
xlabel('Time');
ylabel('Amplitude');
title('LINEAR
CONVOLUTION');

CIRCULAR CONVOLUTION:

clc; clear all; close all;


x=input('Enter the co-efficients of x1[n]=');
h=input('Enter the co-efficients of x2[n]=');
y=crconc(x,h);
subplot(3,1,1);
n=0:(length(x)-1);
stem(n,x);
grid on;
xlabel('TIME');
ylabel('AMPLITUDE');
title('x1[n]');
subplot(3,1,2);
n=0:(length(h)-1);
stem(n,h);grid on;
xlabel('TIME');
ylabel('AMPLITUDE’);
title('x
2[n]');
subplo
t(3,1,3
); n=0:
(length
11
(y)-1);
stem(n
,y);
grid
on;
disp(y) xlabel('TIME');
ylabel('AMPLITUDE');
title('OUTPUTx3[n]');

FLOWCHART:

START

ENTER THE INPUT SEQUENCE x[n] & SYSTEM RESPONSE h[n]

PERFORM LINEAR AND CIRCULAR CONVOLUTION IN


TIME DOMAIN

PLOT THE WAVEFORMS AND ERROR

STOP

12
13
RESULT:
Thus the linear and circular convolution signal is generated and
verified
by MATLAB.

EX. NO: 4
DATE:
SAMPLING RATE CONVERSION

AIM:
Write a MATLAB Script to perform sampling rate conversion
for any given arbitrary sequence (D.T) or signal (C.T) by
interpolation, decimation, upsampling, downsampling and
resampling (i.e. fractional value)
.
APPARATUS REQUIRED:
PC, MATLAB software

THEORY:

SAMPLING PROCESS:

14
It is a process by which a continuous time signal is converted
into discrete time signal. X[n] is the discrete time signal obtained by
taking samples of the analog signal x(t) every T seconds, where T is
the sampling period.
X[n] = x (t) x p (t)
Where p(t) is impulse train; T – period of the train

SAMPLING THEOREM:
It states that the band limited signal x(t) having no frequency
components above Fmax Hz is specified by the samples that are taken
at a uniform rate greater than 2 Fmax Hz (Nyquist rate), or the
frequency equal to twice the highest frequency of x(t).
Fs ≥ 2 Fmax

ALGORITHM/PROCEDURE:
1. Generate a sinusoidal waveform
2. Using the appropriate library function for
interpolation ,decimation ,upsampling ,
downsampling and resampling, perform sampling rate
conversion for the sinusoidal waveform
3. Find the spectrum of all the signals and compare them in
frequency domain.
4. Display the resultant waveforms

Source code :

15
clc;
clear all;
close all;
%continuous sinusoidal signal
a=input('Enter the amplitude:');
f=input('Enter the Timeperiod:');
t=-10:1:20;
x=a*sin(2*pi*f*t);
subplot(2,3,1);
plot(t,x);
xlabel('time');
ylabel('Amplitude');
title('Sinusoidal signal');
%decimating the signal
d=input('Enter the value by which the signal is to be
decimated:');
y1=decimate(x,d);
subplot(2,3,2);
stem(y1);
xlabel('time');
ylabel('Amplitude');
title('Decimated signal');
%interpolating the signal
i=input('Enter the value by which the signal is to be
interpolated:');
y2=interp(x,i);
subplot(2,3,3);
stem(y2);
xlabel('time');
ylabel('Amplitude');
title('Interpolated signal');
%resampling the signal
y3=resample(x,3,2);
subplot(2,3,4);
stem(y3);
xlabel('time');
ylabel('Amplitude');
title('Resampled signal');
%downsampling the signal
y4=downsample(x,2);
16
subplot(2,3,5);
stem(y4);
xlabel('time');
ylabel('Amplitude');
title('Downsampled signal');
%upsampling the signal
y5=upsample(x,3);
subplot(2,3,6);
stem(y5);
xlabel('time');
ylabel('Amplitude');
title('Upsampled signal');

FLOWCHART:

START

ENTER THE SIGNAL PARAMETERS (AMPLITUDE,


TIME AND FREQUENCY)

PERFORM THE SAMPLING RATE CONVERSION


ON THE INPUT BY using upsample,
DOWNSAMPLE and resample
17

PERFORM interpolation and decimation ON THE


RESULT:

18
The program written using library functions and the sampling
rate conversion process is studied.

EX. NO: 5 DESIGN OF BUTTERWORTH FILTERS


DATE:

AIM:
Write a MATLAB Script to design Analog Butterworth filters
for the given specifications.

APPARATUS REQUIRED:
PC, MATLAB software

THEORY:

BUTTERWORTH FILTER:
Low pass Analog Butterworth filters are all pole filters
characterised by magnitude frequency response by
1
2N
1+ Ω
( )
|H ( jω)|2 = Ωc

where N is the order of the filter and Ω c is the cut-off


frequency.
As N , the low pass filter is said to be normalized. All types
of filters namely-Low pass, High pass, Band pass and Band

19
elimination filters can be derived from the Normalized Low pass
filter.

STEPS IN DESIGNING ANALOG FILTER:


1. Transform the given specification to a Normalized Low pass
specification
2. Find the order of the filter N and cut-off frequency c
3. Find the transfer function H(s) of normalized LPF.
4. Use the applicable analog-to-analog transformation to get the
transfer function of the required filter.

ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop (or go to Start – All
programs and click on MATLAB) to get into the Command
Window.
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the
Command window.
3. Write the program in the ‘Edit’ window and save it in ‘M-file’.
4. Run the program.
5. Enter the input in the command window.
6. The result is displayed in the Command window and the
graphical output is displayed in the Figure Window.
Butterworth Filters
SOURCE CODE:1
clc;
clear all;
close all;
%% Butterworth low pass Filter

20
% Filter Specifications

k1=input('Enter the passband gain in db:');


k2=input('Enter the stopband gain in db:');
w1=input('Enter the passband edge frequency in rad/Sec:');
w2=input('Enter the stopband edge frequency in rad/Sec:');

%Find the order and Cutofrf frequency using the given specification
of
%filter
[n,Wc]=buttord(w1,w2,k1,k2,'s');
disp('The order is:');
disp(n);
disp('The cutoff frequency is:');
disp(Wc);

% Low pass filtering


[b,a]=butter(n,Wc,'low','s');

%Plotting magnitude & phase response

f=linspace(1,512,1000);
h=freqs(b,a,f);

m=20*log(abs(h));
subplot(2,1,1);
semilogx(f,m);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude response of Butterworth LPF');

% Phase response
p=angle(h);
subplot(2,1,2);
semilogx(f,p);
xlabel('Frequency');
ylabel('Phase');
title('Phase response of Butterworth LPF');

SOURCE CODE:2

21
clc;
clear all;
close all;
%% Butterworth high pass Filter
% Filter Specifications

k1=input('Enter the passband gain in db:');


k2=input('Enter the stopband gain in db:');
w1=input('Enter the passband edge frequency in rad/Sec:');
w2=input('Enter the stopband edge frequency in rad/Sec:');

%Find the order and Cutofrf frequency using the given specification
of
%filter
[n,Wc]=buttord(w1,w2,k1,k2,'s');
disp('The order is:');
disp(n);
disp('The cutoff frequency is:');
disp(Wc);

% Low pass filtering


[b,a]=butter(n,Wc,'high','s');

%Plotting magnitude & phase response

f=linspace(1,512,1000);
h=freqs(b,a,f);

m=20*log(abs(h));
subplot(2,1,1);
semilogx(f,m);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude response of Butterworth HPF');

% Phase response
p=angle(h);
subplot(2,1,2);
semilogx(f,p);
xlabel('Frequency');
ylabel('Phase');
22
title('Phase response of Butterworth HPF');

SOURCE CODE:3
clc;
clear all;
close all;
%% Bandpass Filter Specifications
Wp=input('Enter the pass band edge frequency : ');
Ws=input('Enter the stop band edge frequency : ');
Rp=input('Enter the Pass band ripple: ');
Rs=input('Enter the stop band gain: ');

%To find order of the filter


[N]=buttord(Wp,Ws,Rp,Rs,'s')

%To find cut off frequency


Wc=[Wp Ws];

%Band pass Filtering


[b,a]=butter(N,Wc,'bandpass','s');

%plotting magnitude and phase response


figure(1);freqs(b,a);

SOURCE CODE:4
clc;
clear all;
close all;
%% Bandstop Filter Specifications
Wp=input('Enter the pass band edge frequency : ');
Ws=input('Enter the stop band edge frequency : ');
Rp=input('Enter the Pass band ripple: ');
Rs=input('Enter the stop band gain: ');

%To find order of the filter


[N]=buttord(Wp,Ws,Rp,Rs,'s')

%To find cut off frequency


Wc=[Wp Ws];

23
%Band stop Filtering
[b,a]=butter(N,Wc,'stop','s');

%plotting magnitude and phase response


figure(1);freqs(b,a);

FLOWCHART:

START

ENTER THE FILTER SPECIFICATIONS (PASS,


STOP BAND GAINS AND EDGE FREQUENCIES)

DESIGN THE ANALOG BUTTERWORTH


and chebyshev FILTER

PLOT THE WAVEFORMS

STOP

24
RESULT:
Analog Butterworth Filter is designed for the given

specifications, and manually verified the order, cut off frequency and

filter co-efficient of the filter.

EX. NO:6 FAST FOURIER TRANSFORM ALGORITHMS


DATE :

AIM:
Write a MATLAB Script to compute Discrete Fourier
Transform and Inverse Discrete Fourier Transform of the given
sequence using FFT algorithms (DIT-FFT & DIF-FFT)
.
APPARATUS REQUIRED:
PC, MATLAB software

THEORY:

DFT is a powerful tool for performing frequency analysis of


discrete time signal and it is described as a frequency domain
representation of a DT sequence.

25
The DFT of a finite duration sequence x[n] is given by
N−1
∑ x ( n ) e− j 2 πnk/N
X (k) = n=0 k=0, 1….N-1
which may conveniently be written in the form
N −1
∑ x ( n ) wnk
N
X (k) = n=0 k=0, 1….N-1
where WN=e-j2/N which is known as Twiddle or Phase
factor.
ALGORITHM/PROCEDURE:
1. Input the given sequence x[n]
2. Compute the Discrete Fourier Transform using FFT library
function (ditfft or diffft) and obtain X[k]
3. Compute the Inverse Discrete Fourier Transform using FFT
library function (ditfft or diffft) and obtain X[n] by following
steps
a. Take conjugate of X [k] and obtain X[k]*
b. Compute the Discrete Fourier Transform using FFT
library function (ditfft or diffft) for X[k]* and obtain
N.x[n]*
c. Once again take conjugate for N.x[n]* and divide by N
to obtain x[n]
4. Display the results.

SOURCE CODE:(DITFFT)
clc;
clear all;
close all;

26
N=input('Enter the number of elements:');
for i=1:N
re(i)= input('Enter the real part of the element:');
im(i)= input('Enter the imaginary part of the element:');
end
%% Call Dit_fft function
[re1,im1]= ditfft(re,im,N);
disp(re1);
disp(im1);

figure(1);
subplot(2,2,1);
stem(re1);
xlabel('Time period');
ylabel('Amplitude');
title('Real part of the output');
subplot(2,2,2);
stem(im1);
xlabel('Time period');
ylabel('Amplitude');
title('Imaginary part of the output');

%%dit_ifft

N=input('Enter the number of elements:');


for i=1:N
re(i)= input('Enter the real part of the element:');
im(i)= input('Enter the imaginary part of the element:');
end
for i=1:N
re(i)=re(i);
im(i)=-im(i);
end
%% call dit_ifft function

[re1,im1]=ditifft(re,im,N);
for i=1:N
re1(i)=re1(i)/N;
im1(i)=-im1(i)/N;
end

27
disp(re1);
disp(im1);
%figure(2)
subplot(2,2,3);
stem(re1);
xlabel('Time period');
ylabel('Amplitude');
title('Real part of the output');

subplot(2,2,4);
stem(im1);
xlabel('Time period');
ylabel('Amplitude');
title('Imaginary part of the output');

Source code :(DIFFFT)

%% DIF_FFT

clc;
clear all;
close all;
%%
N=input('Enter the number of points in DIF DFT:');

for i=1:N
re(i)=input('Enter the real part of the element:');
im(i)=input('Enter the imaginary part of the element:');
end

%%
% Call DIf_FFT Function
[re1, im1]=diffft(re,im,N);
display(re1);
display(im1);
figure(1);
subplot(2,2,1);
stem(re1);
xlabel('Time');
ylabel('Amplitude');

28
title('Real part of the output');

subplot(2,2,2);
stem(im1);
xlabel('Time');
ylabel('Amplitude');
title('Imaginary part of the output');

%% DIF IFFT
N=input('Enter the number of points in DIF IFFT:');
for i=1:N
re(i)=input('Enter the real part of the element:');
im(i)=input('Enter the imaginary part of the element:');
end
for i=1:N
re(i)=re(i);
im(i)=-im(i);
end
%% Call dif_ifft function
[re1, im1]=ditifft(re,im,N);
for i=1:N
re1(i)=re1(i)/N;
im1(i)=-im1(i)/N;
end
display(re1)
display(im1);
% figure(2);
subplot(2,2,3);
stem(re1);
xlabel('Time');
ylabel('Amplitude');
title('Real part of the output');

subplot(2,2,4);
stem(im1);
xlabel('Time');
ylabel('Amplitude');
title('Imaginary part of the output');

29
FLOWCHART:

START

ENTER THE INPUT SEQUENCE IN TIME DOMAIN


OR FREQUENCY DOMAIN

PERFORM DIT/DIF-FFT FOR TIME SAMPLES


or PERFORM IDIT/IDIT-FFT FOR FREQuency
SAMPLES

PLOT THE WAVEFORMS

STOP 30
RESULT:
The DFT and IDFT of the given sequence are computed using
FFT algorithm both DITFFT and DIFFFT.

EX. NO: 7 DESIGN OF CHEBYSHEV FILTERS


DATE:

AIM:
Write a MATLAB Script to design Analog Chebyshev filter for
the given specifications.

APPARATUS REQUIRED:
PC, MATLAB software

THEORY:

Chebyshev Filters :
There are two types of Chebyshev filters.
Type I are all-pole filters that exhibit equi-ripple behaviour in pass
band and monotonic characteristics in stop band.
31
Type II are having both poles and zeros and exhibit monotonic
behavior in pass band and equi-ripple behavior in stop band. The zero
lies on the imaginary axis.
The magnitude-squared function is given as
1
|H ( jω)|2 = 2
1+ε C 2N (Ω /Ω p )
ε is the ripple parameter in pass band
CN(x) is the Nth order Chebyshev polynomial defined as

CN(x) =
{Cos(Ncosh−1 x) , |x|≤1 ¿ ¿¿¿

STEPS IN DESIGNING ANALOG FILTER:


1.Transform the given specification to a Normalized Low pass
specification
1. Find the order of the filter N and cut-off frequency c
2. Find the transfer function H(s) of normalized LPF.
3. Use the applicable analog-to-analog transformation to get the
transfer function of the required filter.

ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop (or go to Start – All
programs and click on MATLAB) to get into the Command
Window.

32
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the
Command window.
3. Write the program in the ‘Edit’ window and save it in ‘M-file’.
4. Run the program.
5. Enter the input in the command window.
6. The result is displayed in the Command window and the
graphical output is displayed in the Figure Window.

CHEBYSHEV FILTERS :
Source code:1
clc;
clear all;
close all;
%% Chebyshev low pass Filter
% Filter Specifications

k1=input('Enter the passband ripple in db:');


k2=input('Enter the stopband attenuation in db:');
w1=input('Enter the passband edge frequency in rad/Sec:');
w2=input('Enter the stopband edge frequency in rad/Sec:');

%Find the order and Cutofrf frequency using the given specification
of
%filter
[n,Wc]=cheb1ord(w1,w2,k1,k2,'s');
disp('The order is:');
disp(n);
disp('The cutoff frequency is:');
disp(Wc);

% Low pass filtering


[b,a]=cheby1(n,k1,w1,'low','s');
figure(1);freqs(b,a);

Source code:2
clc;
33
clear all;
close all;
%% Chebyshev High pass Filter
% Filter Specifications

k1=input('Enter the passband ripple in db:');


k2=input('Enter the stopband attenuation in db:');
w1=input('Enter the passband edge frequency in rad/Sec:');
w2=input('Enter the stopband edge frequency in rad/Sec:');

%Find the order and Cutofrf frequency using the given specification
of
%filter
[n,Wc]=cheb1ord(w1,w2,k1,k2,'s');
disp('The order is:');
disp(n);
disp('The cutoff frequency is:');
disp(Wc);

% High pass filtering


[b,a]=cheby1(n,k1,w1,'high','s');
figure(1);freqs(b,a);

Source code: 3
clc;
clear all;
close all;
%% Bandpass Filter Specifications
Wp=input('Enter the pass band edge frequency : ');
Ws=input('Enter the stop band edge frequency : ');
Rp=input('Enter the Pass band ripple: ');
Rs=input('Enter the stop band gain: ');

%To find order of the filter


[N]=cheb1ord(Wp,Ws,Rp,Rs,'s')

%To find cut off frequency


Wc=[Wp Ws];

34
%Band pass Filtering
[b,a]=cheby1(N,Rp,Wc,'bandpass','s');

%plotting magnitude and phase response


figure(1);freqs(b,a);

Source code: 4
clc;
clear all;
close all;
%% Bandstop Filter Specifications
Wp=input('Enter the pass band edge frequency : ');
Ws=input('Enter the stop band edge frequency : ');
Rp=input('Enter the Pass band ripple: ');
Rs=input('Enter the stop band gain: ');

%To find order of the filter


[N]=cheb1ord(Wp,Ws,Rp,Rs,'s')

%To find cut off frequency


Wc=[Wp Ws];

%Bandstop Filtering
[b,a]=cheby1(N,Rp,Wc,'stop','s');

%plotting magnitude and phase response


Figure(1);freqs(b,a);

FLOWCHART:

START

ENTER THE FILTER SPECIFICATIONS (PASS,


STOP BAND GAINS AND EDGE FREQUENCIES)

35

DESIGN THE ANALOG BUTTERWORTH


and chebyshev FILTER
36
RESULT:
Analog Chebyshev Filter is designed for the given

specifications, and manually verified the order, cut off frequency and

filter co-efficient of the filter.

verified the order, cut off frequency and filter co-efficient of

EX. NO:8
the filter.
DATE :
DESIGN OF FIR FILTERS

AIM:
Write a MATLAB Script to design a low pass FIR filter using
Window Method for the given specifications
.
APPARATUS REQUIRED:
PC, MATLAB software

THEORY:

A digital filter is a discrete time LTI system. It is classified


based on the length of the impulse response as
IIR filters:
Where h [n] has infinite number of samples and is recursive
type.

37
FIR filters:
They are non-recursive type and h [n] has finite number of
samples.
The transfer function is of the form:
N −1
H ( z )= ∑ hn z −n
n=0

This implies that it has (N-1) zeros located anywhere in the z-


plane and (N-1) poles at Z = h.

THE FIR FILTER CAN BE DESIGNED BY:


 Fourier series method
 Frequency sampling method
 Window method
Most of the FIR design methods are interactive procedures and
hence require more memory and execution time. Also implementation
of narrow transition band filter is costly. But there are certain reasons
to go for FIR.

TYPES OF WINDOWS:
1. Rectangular
2. Triangular
3. Hamming
4. Hanning
5. Blackman
6. Kaiser
POGRAM:

38
Source code :1
%windows technique of Rectangular window using low pass filter
clc;
clear all;
close all;
N=input('Size of window:');
wc=input('Cut off frequency:');
h=fir1(N-1,wc/pi,boxcar(N));
tf(h,1,1,'variable','z^-1');
freqz(h);
xlabel('Frequency');
ylabel('Magnitude');
title('FIR Filter');

Source code :2
%windows technique of Triangular(Bartlet Window) using High pass
filter
clc;
clear all;
close all;
N=input('Size of window:');
wc=input('Cut off frequency:');
h=fir1(N-1,wc/pi,'high',triang(N));
tf(h,1,1,'variable','z^-1');
freqz(h);
xlabel('Frequency');
ylabel('Magnitude');
title('FIR Filter');

Source code :3
%windows technique of Hamming using Band pass filter
clc;
clear all;
close all;
N=input('Size of window:');
wc1=input('Lower Cut off frequency:');
wc2=input('Upper Cut off frequency:');
wc=[wc1 wc2];

39
h=fir1(N-1,wc/pi,'bandpass',hamming(N));
tf(h,1,1,'variable','z^-1');
freqz(h);
xlabel('Frequency');
ylabel('Magnitude');
title('FIR Filter');

Source code :4
%windows technique of Hanning using Band stop filter
clc;
clear all;
close all;
N=input('Size of window:');
wc1=input('Lower Cut off frequency:');
wc2=input('Upper Cut off frequency:');
wc=[wc1 wc2];
h=fir1(N-1,wc/pi,'stop',hanning(N));
tf(h,1,1,'variable','z^-1');
freqz(h);
xlabel('Frequency');

ylabel('Magnitude');
title('FIR Filter');

Source code :5
%windows technique of Blackman window using low pass filter
clc;
clear all;
close all;
N=input('Size of window:');
wc=input('Cut off frequency:');
h=fir1(N-1,wc/pi,blackman(N));
tf(h,1,1,'variable','z^-1');
freqz(h);
xlabel('Frequency');
ylabel('Magnitude');
title('FIR Filter');

40
FLOWCHART:

START

ENTER THE FILTER SPECIFICATIONS (ORDER OF


THE FILTER, CUT-OFF FREQUENCY)

dESIGN THE FILTER

PLOT THE WAVEFORMS


41

STOP
RESULT:
The given low pass filter was designed using Window method

and manually verified filter co-efficient of the filters

EX. NO: 9
DATE:
DESIGN OF IIR FILTERS

AIM:
Write a MATLAB Script to design Butterworth and
Chebyshev low pass filters using
Bilinear Transformation
Impulse Invariant Transformation
.
APPARATUS REQUIRED:
PC, MATLAB software

THEORY:

42
A digital filter is a linear time invariant discrete time system.
The digital filters are classified into two, based on their lengths of
impulse response
1. Finite Impulse response (FIR)
They are of non-recursive type and h [n] has finite
number of samples
2. Infinite Impulse response (IIR)
h[n] has finite number of samples. They are of
recursive type. Hence, their transfer function is of the
form

H ( z )  h ( n ) z  n
n 0

M −1
∑ bk Z−k
K=0
H ( Z )= N −1
1+ ∑ a j Z− j
j=1

The digital filters are designed from analog filters. The two
widely used methods for digitizing the analog filters include

1. Bilinear transformation
2. Impulse Invariant transformation

The bilinear transformation maps the s-plane into the z-plane by


2 1−Z −1
H ( S )|s = ×
H(Z) = T 1+Z −1

This transformation maps the jΩ axis (from Ω = -∞ to +∞)


repeatedly around the unit circle (exp ( jw), from w=-π to π ) by

43
2 
  tan  
T  2
BILINEAR TRANSFORMATION:
DESIGN STEPS:
1. From the given specifications, Find pre-warped analog
frequencies using
2 
  tan  
T  2
2. Using the analog frequencies, find H(s) of the analog
filter
2 1−Z −1
S= ×
3. Substitute T 1+Z−1 in the H(s) of Step:2

IMPULSE INVARIANT TRANSFORMATION:


DESIGN STEPS:
1. Find the analog frequency using  =  / T
2. Find the transfer function of analog filter Ha(s)
3. Express the analog filter transfer function as a sum of
single pole filters
4. Compute H(Z) of digital filter using the formula
N
Ck
H ( Z )=∑
−TP k Z−1
k=1
1−e

ALGORITHM/PROCEDURE:

1. Calculate the attenuation in dB for the given design


parameters

44
2. Design the analog counterpart
3. Using Impulse Invariant /Bilinear transformation design the
digital filter
4. Display the transfer function. Plot the magnitude response and
phase response

SOURCE CODE:
/ Butterworth Lowpass Impulse invariant method
clc;
clear all;
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,bothe ripple gains should be b/w .1 to .3
disp(' Butterworth Lowpass filter using Impulse invariant method
');

T=input('Enter the Sampling Frequency in rad/sec: ');


Sp=input('Enter the Pass-band Ripple Gain: ');
Wp=input('Enter the Pass-band Edge Frequency in rad/sec: ');
Ss=input('Enter the Stop-band Ripple Gain: ');
Ws=input('Enter the Stop-band Edge Frequency in rad/sec: ');

% Calculation of ohmp,ohms,Ap,As
Ap=abs(20*log10(1-Sp));
As=abs(20*log10(Ss));

ohmp=Wp/T;
ohms=Ws/T;
% Butterworth Filter
% Calculation of order and cutoff freq. for the above filter specs.
45
[n,Wc]=buttord(ohmp,ohms,Ap,As,'s');

% Low Pass Filtering


[b,a]=butter(n,Wc,'low','s');
[bz,az] = impinvar(b,a,T);
tf(bz,az,T);
O=linspace(-pi,pi,50);
% O is the freq. axis
H=freqz(bz,az,O);

% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using Impulse Invariant
Method');

% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Impulse Invariant
Method');

/ Butterworth Lowpass Bilinear Transformation


Method

clc;
clear all;
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,both the ripple gains should have band width( .1 to .3)

46
disp(' Butterworth Lowpass filter using Bilnear transformation
method ');

T=input('Enter the Sampling Frequency in rad/sec: ');


Sp=input('Enter the Pass-band Ripple Gain: ');
Wp=input('Enter the Pass-band Edge Frequency in rad/sec: ');
Ss=input('Enter the Stop-band Ripple Gain: ');
Ws=input('Enter the Stop-band Edge Frequency in rad/sec: ');

% Calculation of ohmp,ohms,Ap,As
Ap=abs(20*log10(1-Sp));
As=abs(20*log10(Ss));
ohmp=Wp/T;
ohms=Ws/T;
% Butterworth Filter
% Calculation of order and cutoff freq. for the above filter specs.
[n,Wc]=buttord(ohmp,ohms,Ap,As,'s');

% Low Pass Filtering


[b,a]=butter(n,Wc,'low','s');
[bz,az] = bilinear(b,a,1/T);
tf(bz,az,T);
O=linspace(-pi,pi,50);
% O is the freq. axis
H=freqz(bz,az,O);

% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using Bilinear
Transformation Method');

% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
xlabel('Frequency');

47
ylabel('Phase');
title('Phase Response of IIR Filter using Bilinear Transformation
Method');

/ Chebyshev Lowpass Impulse invariant method

clc;
clear all;
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,bothe ripple gains should be b/w .1 to .3
disp(' Chebyshev Lowpass filter using Impulse invariant method
');

T=input('Enter the Sampling Frequency in rad/sec: ');


Sp=input('Enter the Pass-band Ripple Gain: ');
Wp=input('Enter the Pass-band Edge Frequency in rad/sec: ');
Ss=input('Enter the Stop-band Ripple Gain: ');
Ws=input('Enter the Stop-band Edge Frequency in rad/sec: ');

% Calculation of ohmp,ohms,Ap,As
Ap=abs(20*log10(1-Sp));
As=abs(20*log10(Ss));
ohmp=Wp/T;
ohms=Ws/T;
% Chebyshev Filter
% Calculation of order and cutoff freq. for the above filter specs.
[n,Wc2]=cheb1ord(ohmp,ohms,Ap,As,'s')

% Low Pass Filtering


[b,a]=cheby1(n,Ap,Wc2,'low','s');
[bz,az] = impinvar(b,a,T);
tf(bz,az,T);
O=linspace(-pi,pi,50);
% O is the freq. axis
H=freqz(bz,az,O);

48
% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using Impulse Invariant
Method');

% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Impulse Invariant
Method');

/Chebyshev Lowpass Bilinear Transformation Method

clc;
clear all;
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,bothe ripple gains should be b/w .1 to .3
disp(' Chebyshev Lowpass filter using Bilnear transformation
method ');

T=input('Enter the Sampling Frequency in rad/sec: ');


Sp=input('Enter the Pass-band Ripple Gain: ');
Wp=input('Enter the Pass-band Edge Frequency in rad/sec: ');
Ss=input('Enter the Stop-band Ripple Gain: ');
Ws=input('Enter the Stop-band Edge Frequency in rad/sec: ');

% Calculation of ohmp,ohms,Ap,As

49
Ap=abs(20*log10(1-Sp));
As=abs(20*log10(Ss));
ohmp=Wp/T;
ohms=Ws/T;
% Chebyshev Filter
% Calculation of order and cutoff freq. for the above filter specs.
[n,Wc2]=cheb1ord(ohmp,ohms,Ap,As,'s')

% Low Pass Filtering


[b,a]=cheby1(n,Ap,Wc2,'low','s');
[bz,az] = bilinear(b,a,1/T);
tf(bz,az,T);
O=linspace(-pi,pi,50);
% O is the freq. axis
H=freqz(bz,az,O);

% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using Bilinear
Transformation Method');

% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Bilinear Transformation
Method');

50
FLOWCHART:

START

ENTER THE FILTER SPECIFICATIONS (PASS,


STOP BAND GAINS AND EDGE FREQUENCIES)

DESIGN THE ANALOG BUTTERWORTH and


CHEBYSHEV LOW PASS FILTER

CONVERT THE LOW PASS FILTERS in to


digital filterS by using the impulse invariant and
bilinear TRANSFORMATIONS

PLOT THE WAVEFORMS

STOP

51
RESULT:
Butterworth and Chebyshev Lowpass filters were designed

using Bilinear and Impulse Invariant transformations, and manually

52
verified the order, cut off frequency and filter co-efficient of the

filters.

EX. NO: 10 INTRODUCTION TO THE TMS 320C6713


DATE:

AIM:
To study about the TMS 320C6713.

Theoy:

53
54
55
FUNCTIONAL OVERVIEW OF THE TMS 320C6713 DSK

56
CODE COMPOSER STUDIO

The Code Composer Studio (CCS) provides an integrated


development environment(IDE) to incorporate the software tools.
CCS includes tools for code generation,such as a C compiler, an
assembler, and a linker. It has graphical capabilitiesand supports
real-time debugging. It provides an easy-to-use software tool to
buildand debug programs.

The C compiler compiles a C source program with


extension .c to produce an assembly source file with
extension.asm.The assembler assembles an.asm source file to
produce a machine language object file with extension.obj.The
linker combinesobject files and object libraries as input to produce
an executable file with extension.out. This executable file
represents a linked common object file format (COFF), popular in
Unix-based systems and adopted by several makers of digital signal
processors . This executable file can be loaded and run directly on
the C6713 processor.

To create an application project, one can “add” the


appropriate files to the project. Compiler/linker options can readily
be specified. A number of debugging features are available,
including setting breakpoints and watching variables, viewing
memory, registers, and mixed C and assembly code, graphing
results, and monitoringexecution time. One can step through a
program in different ways (step into, orover, or out).

Real-time analysis can be performed using real-time data


exchange (RTDX) associated with DSP/BIOS .RTDX allows for data
exchange between the host and the target and analysis in real time

57
without stopping the target. Key statistics and performance can be
monitored in real time. Through the Joint Team Action Group
(JTAG), communication with on-chip emulation support occurs to
control and monitor program execution. The C6713 DSK board
includes a JTAG emulator interface.

BASIC OPERATION

58
RESULT:
Thus the details about the TMS 320C6713 was studied.

59
60

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy