3.new DSP Lab DOC

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 92

Exp.No.

1
Exc.No.
GENERATION OF RANDOM SIGNALS
Dt.

AIM: Write a program in MATLAB to generate the


following waveforms

1.Unit Impulse sequence, 2)Unit step sequence, 3.Unit


Ramp sequence, 4)Exponential sequence,
5.Sinusoidal sequence,

EQUIPMENT:

Operating System – Windows XP

Software – MATLAB 7.5

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
behavior can be studied by superposition of basic signals.
Common basic signals are:

Discrete – Time signals:

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

1, for n  0
 Unit step sequence. x (n)  u(n)  
0, otherwise
n, for n  0
 Unit ramp sequence. x (n)  r (n)  
0, otherwise
 Sinusoidal sequence. x (n)  A sin(n   ) .
 Exponential sequence. x(n) = A a n, where A and a are
constant.
PROCEDURE:

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 1


1. The Power is switched ON.
2. Open the MATLAB software by clicking
‘MATLAB’ icon on desktop.
3. Open the Editor window & Write a program in
it.
4. Save the program in Workspace as .m file.
5.Run the program & View the Graph

Source code :

%WAVE FORM GENERATION

%DT SIGNAL

%UNIT IMPULSE

clc;
clear all;
close all;
n0=input('enter the value of n0');
n1=input('enter the value of n1');
n2=input('enter the value of n2');
[x,n]=impseq(n0,n1,n2);
stem(n,x);
xlabel('n');
ylabel('x(n)');

function [x,n] = impseq(n0,n1,n2)


% Generates x(n) = delta(n-n0); n1 <= n <= n2
% ----------------------------------------------
% [x,n] = impseq(n0,n1,n2)
%
n = [n1:n2];
x = [(n-n0) == 0];

%UNIT STEP SIGNAL

clc;
clear all;
close all;
n0=input('enter the value of n0');
n1=input('enter the value of n1');
n2=input('enter the value of n2');

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 2


[x,n]=stepseq(n0,n1,n2);
stem(n,x);
xlabel('n');
ylabel('x(n)');
title('Unit step signal');

function [x,n] = stepseq(n0,n1,n2)


% Generates x(n) = u(n-n0); n1 <= n <= n2
% ------------------------------------------
% [x,n] = stepseq(n0,n1,n2)
%
n = [n1:n2];
x = [(n-n0) >= 0];

%EXPONENTIAL SIGNAL

clc;
clear all;
close all;
a=input('enter the value of a');
n=[0:10];
x=a.^n;
stem(x);
xlabel('n');
ylabel('x(n)');
title('exponential seq');
%UNIT RAMP SIGNAL

n=-10:10;
x=n;
stem(n,x);
xlabel('time');
ylabel('Amplitude');
title('Unit ramp signal');
%SINUSOIDAL SIGNAL
clc;
clear all;
close all;
A=input('Enter the amplitude:');

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 3


f=input('Enter the frequency:');
n=-2:.1:2;
x=A*sin(2*pi*f*n);
stem(n,x);
xlabel('time');
ylabel('Amplitude');
title('Sinusoidal signal');

output: 1)unit impulse:

0.9

0.8

0.7

0.6
x(n)

0.5

0.4

0.3

0.2

0.1

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
n

2)unit step sequence

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 4


Unit step signal
1

0.9

0.8

0.7

x(n) 0.6

0.5

0.4

0.3

0.2

0.1

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
n

3)exponential sequence

exponential seq
1

0.9

0.8

0.7

0.6
x(n)

0.5

0.4

0.3

0.2

0.1

0
1 2 3 4 5 6 7 8 9 10 11
n

4).Unit Ramp

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 5


Unit ramp signal
10

Amplitude 2

-2

-4

-6

-8

-10
-10 -8 -6 -4 -2 0 2 4 6 8 10
time

5)Sinusoidal sequence:

Sinusoidal signal
2

1.5

1
Amplitude

0.5

-0.5

-1

-1.5

-2
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
time

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 6


Result:

Viva questions:

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 7


III B.TECH - II SEM (R13) ECE: DSP LAB

Exp.No. 2
Exc.No.
ENERGY AND POWER OF A SIGNAL
Dt.

Aim: Write a program in MATLAB to find energy and power of given signal

Equipment: Operating System – Windows XP

Software – MATLAB 7.5

Theory:

clear all;
close all;
clc;
n= 0:0.01:4;
x = cos(2*pi*n);
M = length(x);
sum = 0;
for i = 1:M,
sum = sum + x(i)*x(i);
end;
disp('Energy of the given sequence is ..... :: ');
Energy = sum;
disp(Energy);
disp('Average Power of the given sequence is ..... :: ');
Average_power = sum/M;
disp(Average_power);
PROCEDURE:

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 8


III B.TECH - II SEM (R13) ECE: DSP LAB

1. The Power is switched ON.


2. Open the MATLAB software by clicking ‘MATLAB’ icon on desktop.
3. Open the Editor window & Write a program in it.
4. Save the program in Workspace as .m file.
5. Run the program & View the output values

Output:

Result:

Viva Questions:

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 9


III B.TECH - II SEM (R13) ECE: DSP LAB

Exp.No. 3 a)
Exc.No.
LINEAR CONVOLUTION
Dt.

AIM: To verify the Linear Convolution between two given sequences.

EQUIPMENT:

Operating System – Windows XP


Software – MATLAB 7.5
Theory:
LINEAR CONVOLUTION:
The response y[n] of a LTI system for any arbitrary input x[n] is given by convolution of
impulse response h[n] of the system and the arbitrary input x[n].

y[n] = x[n]*h[n] = or

If the input x[n] has N1 samples and impulse response h[n] has N2 samples then the output
sequence y[n] will be a finite duration sequence consisting of (N 1 + N2 - 1) samples. The
convolution results in a non periodic sequence called Aperiodic convolution.

STEPS IN LINEAR CONVOLUTION:


The process of computing convolution between x[k] and h[k] involves four steps.

1. Folding: Fold h[k] about k=0 to obtain h[-k]


2. Shifting: Shift h[-k] by ‘n0’to right if ‘n0’ is positive and shift h[-k] by ‘n0’ to the left if
‘n0’ is negative. Obtain h[n0-k]
3. Multiplication : Multiply x[k] by h[n0-k] to obtain the product sequence
yn0 [k] = x[k] h [n0 –k]

4. Summation: Find the sum of all the values of the product sequence to obtain values of
output at n = n0
Repeat steps 2 to 4 for all possible time shifts ‘n0’ in the range - <n<

Algorithm to implement ‘C’ or Assembly program for Convolution:

Eg: x[n]={1, 2, 3, 4}
h[k]={1, 2, 3, 4}
where n=4, k=4.; size of n&k should be a multiple of 4.
If n & k are not multiples of 4, pad with zero’s to make multiples of 4
r=n+k-1; size of output sequence
=4+4-1
=7

r=0 0 1 2 3 4 5 6

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 10


III B.TECH - II SEM (R13) ECE: DSP LAB

n=0 x[0]h[0] x[0]h[1] x[0]h[2] x[0]h[3]

1 x[1]h[0] x[1]h[1] x[1]h[2] x[1]h[3]

2 x[2]h[0] x[2]h[1] x[2]h[2] x[2]h[3]

3 x[3]h[0] x[3]h[1] x[3]h[2] x[3]h[3]

Output : y[r] = { 1, 4, 10, 20, 25, 24, 16}

Program

% MATLAB program for linear convolution


%linear convolution program
clc;
clear all;
close all;
disp('linear convolution program');
x=input('enter i/p x(n):');
m=length(x);
h=input('enter i/p h(n):');
n=length(h);
x=[x,zeros(1,n)];
subplot(2,2,1), stem(x);
title('i/p sequence x(n)is:');
xlabel('---->n');
ylabel('---->x(n)');grid;
h=[h,zeros(1,m)];
subplot(2,2,2), stem(h);
title('i/p sequence h(n)is:');
xlabel('---->n');
ylabel('---->h(n)');grid;
disp('convolution of x(n) & h(n) is y(n):');
y=zeros(1,m+n-1);
for i=1:m+n-1
y(i)=0;
for j=1:m+n-1
if(j<i+1)
y(i)=y(i)+x(j)*h(i-j+1);
end
end
end
disp(y);
subplot(2,2,[3,4]),stem(y);
title('convolution of x(n) & h(n) is :');
xlabel('---->n');
ylabel('---->y(n)');grid;

PROCEDURE:

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 11


III B.TECH - II SEM (R13) ECE: DSP LAB

1. The Power is switched ON.


2. Open the MATLAB software by clicking ‘MATLAB’ icon on desktop.
3. Open the Editor window & Write a program in it.
4. Save the program in Workspace as .m file.
5. Run the program & View the Graph.

OUTPUT:

i/p sequence x(n)is: i/p sequence h(n)is:


6 5

4
---->x(n)

---->h(n)

2 0

-2 -5
0 5 10 0 5 10
---->n ---->n
convolution of x(n) & h(n) is :
40

30
---->y(n)

20

10

-10
1 2 3 4 5 6 7 8
---->n

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 12


III B.TECH - II SEM (R13) ECE: DSP LAB

Result:

Exp.No. 3 b) CROSS &AUTO CORRELATION

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 13


III B.TECH - II SEM (R13) ECE: DSP LAB

Exc.No.

Dt.

AIM: Write a program in MATLAB to find cross and auto correlation of a two given sequences

EQUIPMENT:

Operating System – Windows XP


Software – MATLAB 7.5
Theory:
Correlation of Discrete-Time Signals
A signal operation similar to signal convolution, but with completely different physical meaning, is
signal correlation. The signal correlation operation can be performed either with one signal
(autocorrelation) or between two different signals (crosscorrelation). Physically, signal
autocorrelation indicates how the signal energy (power) is distributed within the signal, and as such
is used to measure the signal power. Typical applications of signal autocorrelation are in radar,
sonar, satellite,and wireless communications systems. Devices that measure signal power using
signal correlation are known as signal correlators. There are also many applications of signal
crosscorrelation in signal processing systems, especially when the signal is corrupted by another
undesirable signal (noise) so that the signal estimation (detection) from a noisy signal has to be
performed. Signal crosscorrelation can be also considered as a measure of similarity of two signals.

Source code for cross correlation


clc;
clear all;
close all;
x=input('Enter the first Sequence : ');
h=input('Enter the second sequence : ');
subplot(2,2,1), stem(x);
title('i/p sequence x(n)is:');
xlabel('---->n');
ylabel('---->x(n)');grid;
subplot(2,2,2), stem(h);
title('i/p sequence h(n)is:');
xlabel('---->n');
ylabel('---->h(n)');grid;
n=length(x);
m=length(h);
k=n+m-1;

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 14


III B.TECH - II SEM (R13) ECE: DSP LAB

x=[x zeros(1,k-n)]';
h=wrev(h);
h=[h zeros(1,k-m)]';
for i=1:k
c(:,i)=circshift(x,i-1);
end
y=c*h;
disp('Correlation of the sequences')
disp(y');
subplot(2,2,[3,4]),stem(y);
title('crosscorrelation of x(n) & h(n) is :');
xlabel('---->n');
ylabel('---->y(n)');grid;

Source code for auto correlation


clc;
clear all;
close all;
x=input('Enter the input Sequence : ');
n=length(x);
k=n+n-1;
x1=[x zeros(1,k-n)]';
h=wrev(x);
h=[h zeros(1,k-n)]';
for i=1:k
c(:,i)=circshift(x1,i-1);
end
y=c*h;
disp('Correlation of the sequences')
disp(y');

PROCEDURE:

1. The Power is switched ON.


2. Open the MATLAB software by clicking ‘MATLAB’ icon on desktop.
3. Open the Editor window & Write a program in it.
4. Save the program in Workspace as .m file.
5. Run the program & View the Graph.

For cross correlation:


Output:

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 15


III B.TECH - II SEM (R13) ECE: DSP LAB

i/p sequence x(n)is: i/p sequence h(n)is:


6 6

---->x(n)

---->h(n)
4 4

2 2

0 0
1 2 3 4 1 2 3 4 5
---->n ---->n
crosscorrelation of x(n) & h(n) is :
60
---->y(n)

40

20

0
1 2 3 4 5 6 7 8
---->n

Auto correlation

Result:

VIVA QUESTIONS
1. What is the requirement for convolution?
2. What is the difference between convolution & correlation?
3. What is meant by impulse response?
4. Is it possible to represent any discrete time signal in terms of impulses? If yes, represent by using
an example.
5. Draw the h(2n-k) & h(n-2k) for the following sequence h(n) = { 4 3 2 1} assume (i) k= 3
(ii) k =5.
6. Write the expressions for LTI system convolution formula & causal LTI system convolution
formula.
7. What is the length of linear convolution if length of input & impulse responses are N1 & N2
respectively?
8. What is the difference between continuous and discrete convolution?

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 16


III B.TECH - II SEM (R13) ECE: DSP LAB

Exp.No. 4
Exc.No.
DTFT OF A GIVEN SIGNAL
Dt.

Aim: Write a MATLAB program to find DTFT of given signal

EQUIPMENT:

Operating System – Windows XP


Software – MATLAB 7.5
Theory:

clc;
clear all;
close all;
x=input('enter the input seq');
n=length(x);
n=1:n;
%n = -1:3;
%x = 1:5;
k = 0:500;
w = (pi/500)*k;
X = x * (exp(-j*pi/500)) .^ (n'*k);
magX = abs(X);
angX = angle(X);
realX = real(X);
imagX = imag(X);
subplot(2,2,1);
plot(k/500,magX);grid
xlabel('frequency in pi units');
title('Magnitude Part')

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 17


III B.TECH - II SEM (R13) ECE: DSP LAB

subplot(2,2,3);
plot(k/500,angX/pi);grid
xlabel('frequency in pi units');
title('Angle Part')
subplot(2,2,2);
plot(k/500,realX);grid
xlabel('frequency in pi units');
title('Real Part')
subplot(2,2,4);
plot(k/500,imagX);grid
xlabel('frequency in pi units');
title('Imaginary Part')

PROCEDURE:

1. The Power is switched ON.


2. Open the MATLAB software by clicking ‘MATLAB’ icon on desktop.
3. Open the Editor window & Write a program in it.
4. Save the program in Workspace as .m file.
Run the program & View the Graph

Output:

Magnitude Part Real Part


10 10

5 0

-5

0 -10
0 0.5 1 0 0.5 1
frequency in pi units frequency in pi units
Angle Part Imaginary Part
1 5

0.5
0
0
-5
-0.5

-1 -10
0 0.5 1 0 0.5 1
frequency in pi units frequency in pi units

Result:

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 18


III B.TECH - II SEM (R13) ECE: DSP LAB

Exp.No. 5
Exc.No.
N-Point FFT
Dt.

AIM:

Write a MATLAB program to perform the Discrete Fourier Transform for the given
sequences.
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)

EQUIPMENT:

Operating System – Windows XP


Software – MATLAB 7.5
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.

The DFT of a finite duration sequence x[n] is given by

X (k) = k=0, 1….N-1

which may conveniently be written in the form

X (k) = k=0, 1….N-1

where WN=e-j2/N which is known as Twiddle or Phase factor.

COMPUTATION OF DFT:

To compute DFT, it requires N2 multiplication and (N-1) N complex addition. Direct


computation of DFT is basically inefficient precisely because it does not exploit the symmetry and
periodicity properties of phase factor WN.

FAST FOURIER TRANSFORM (FFT):

FFT is a method of having computationally efficient algorithms for the execution of DFT,
under the approach of Divide and Conquer. The number of computations can be reduced in N point
DFT for complex multiplications to N/2log2N and for complex addition to N/2log2N.

Types of FFT are,

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 19


III B.TECH - II SEM (R13) ECE: DSP LAB

(i) Decimation In Time (DIT)


(ii) Decimation In Frequency (DIF)
IDFT USING FFT ALGORITHMS:
The inverse DFT of an N point sequence X (k), where k=0,1,2…N-1 is defined as ,

x [n] =

where, wN=e-j2/N.

Taking conjugate and multiplying by N, we get,

N x*[n] =

The right hand side of the equation is the DFT of the sequence X*(k). Now x[n] can be found
by taking the complex conjugate of the DFT and dividing by N to give,

x [n]=

RADIX-2 DECIMATION IN TIME FFT:

The idea is to successively split the N-point time domain sequence into smaller sub
sequence. Initially the N-point sequence is split into x e[n] and xo[n], which have the even and
odd indexed samples of x[n] respectively. The N/2 point DFT’s of these two sequences are
evaluated and combined to give N-point DFT. Similarly N/2 point sequences are represented as
a combination of two N/4 point DFT’s. This process is continued, until we are left with 2 point
DFT.

RADIX-2 DECIMATION IN FREQUENCY FFT:

The output sequence X(k) is divided into smaller sequence.. Initially x[n] is divided
into two sequences x1[n], x2[n] consisting of the first and second N/2 samples of x[n]
respectively. Then we find the N/2 point sequences f[n] and g[n] as

f[n]= x1[n]+x2[n],

g[n]=( x1[n]-x2[n] )wNk

The N/2 point DFT of the 2 sequences gives even and odd numbered output samples. The above
procedure can be used to express each N/2 point DFT as a combination of two N/4 point DFTs.
This process is continued until we are left with 2 point DFT.

LIBRARY FUNCTION:

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 20


III B.TECH - II SEM (R13) ECE: DSP LAB

 fft: Discrete Fourier transform.


fft(x) is the discrete Fourier transform (DFT) of vector x. For matrices, the FFT operation is
applied to each column. For N-Dimensional arrays, the FFT operation operates on the first non-
singleton dimension.

 ditfft: Decimation in time (DIT)fft


ditfft(x) is the discrete Fourier transform (DFT) of vector x in time domain decimation

 diffft: Decimation in frequency (DIF)fft


diffft(x) is the discrete Fourier transform (DFT) of vector x in Frequency domain decimation

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.

SOUCRCE CODE TO FIND DFT A GIVEN SEQUENCE USING DFT FORMULA

clc;
clear all;
close all;
x = input('Enter the input sequence = ');
N = length(x);
for k = 1:N
y(k) = 0;
for n = 1:N
y(k) = y(k)+x(n).*exp((-1i*2*pi*(k-1)*(n-1))/N);
end
end
%code block to plot the input sequence
t = 0:N-1;
subplot(2,2,1);
stem(t,x);
ylabel('Amplitude ---->');
xlabel('n ---->');
title('Input Sequence');
grid on;

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 21


III B.TECH - II SEM (R13) ECE: DSP LAB

magnitude = abs(y); % Find the magnitudes of individual FFT points


disp('FFT Sequence = ');
disp(magnitude);
%code block to plot the FFT sequence
t = 0:N-1;
subplot(2,2,2);
stem(t,magnitude);
ylabel('Amplitude ---->');
xlabel('K ---->');
title('FFT Sequence');
grid on;
R = length(y);
for n = 1:R
x1(n) = 0;
for k = 1:R
x1(n) = x1(n)+(1/R)*y(k)*exp(1i*2*pi*(k-1)*(n-1)/R);
end
end
%code block to plot the IFFT sequence
t = 0:R-1;
subplot(2,2,3);
stem(t,x1);
magnitude=abs(x1);
disp('IFFT Sequence = ');
disp(magnitude);
ylabel('Amplitude ---->');
xlabel('n ---->');
title('IFFT sequence');
grid on;

output:

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 22


III B.TECH - II SEM (R13) ECE: DSP LAB

Input Sequence FFT Sequence


4 10

Amplitude ---->

Amplitude ---->
3

2 5

0 0
0 1 2 3 0 1 2 3
n ----> K ---->
IFFT sequence
4

3
Amplitude ---->

0
0 0.5 1 1.5 2 2.5 3
n ---->

SOURCE CODE:(DITFFT)

clc;
clear all;
close all;
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');

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 23


III B.TECH - II SEM (R13) ECE: DSP LAB

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
disp(re1);
disp(im1);
%figure(2)
subplot(2,2,3);
stem(re1);
xlabel('Time period');
ylabel('Amplitude');

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 24


III B.TECH - II SEM (R13) ECE: DSP LAB

title('Real part of the output');


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

Function Table:(DITFFT)

function [ re, im ] = ditfft( re, im, N)


%UNTITLED5 Summary of this function goes here
% Detailed explanation goes here
N1=N-1;
N2=N/2;
j=N2+1;
M=log2(N);

% Bit reversal sorting

for i=2:N-2
if i<j
tr=re(j);
ti=im(j);
re(j)=re(i);
im(j)=im(i);
re(i)=tr;
im(i)=ti;
end
k=N2;
while k<=j
j=j-k;

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 25


III B.TECH - II SEM (R13) ECE: DSP LAB

k=k/2;
end
j=j+k;
j=round(j);
end
for l=1:M
le=2.^l;
le2=le/2;
ur=1;
ui=0;
sr=cos(pi/le2);
si=sin(pi/le2);
for j=2:(le2+1)
jm=j-1;
for i=jm:le:N
ip=i+le2;
tr=re(ip)*ur-im(ip)*ui;
ti=re(ip)*ui-im(ip)*ur;
re(ip)=re(i)-tr;
im(ip)=im(i)-ti;
re(i)=re(i)+tr;
im(i)=im(i)+ti;
end
tr=ur;
ur=tr*sr-ui*si;
ui=tr*si+ui*sr;
end
end

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 26


III B.TECH - II SEM (R13) ECE: DSP LAB

Function Table:(DITIFFT)
function [ re,im] = ditifft(re,im,N)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
N1=N-1;
N2=N/2;
j=N2+1;
M=log2(N);
%Bit reversal sorting
for i=2:N-2
if i<j
tr=re(j);
ti=im(j);
re(j)=re(i);
im(j)=im(i);
re(i)=tr;
im(i)=ti;
end
k=N2;
while k<=j
j=j-k;
k=k/2;
end
j=j+k;
j=round(j);
end
for l=1:M
le=2.^l;
le2=le/2;
ur=1;
ui=0;

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 27


III B.TECH - II SEM (R13) ECE: DSP LAB

sr=cos(pi/le2);
si=-sin(pi/le2);
for j=2:(le2+1)
jm=j-1;
for i=jm:le:N
ip=i+le2;
tr=re(ip)*ur-im(ip)*ui;
ti=re(ip)*ui+im(ip)*ur;
re(ip)=re(i)-tr;
im(ip)=im(i)-ti;
re(i)=re(i)+tr;
im(i)=im(i)+ti;
end
tr=ur;
ur=tr*sr-ui*si;
ui=tr*si+ui*sr;
end
end
end

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 28


III B.TECH - II SEM (R13) ECE: DSP LAB

Command Window:

Result:

VIVA QUESTIONS:
1. FFT is in complex domain how to use it in real life signals optimally?
2. What is the difference between FFT and IFFT?
3. Explain using convolution the effects of taking an FFT of a sample with no windowing
4. What is the need of FFT ?
5. What’s the difference between FFT and DFT?
6. Why do we need Fourier transform in DSP?
7. Give any practical application of fft in daily life?
8. What is the importance of fft in OFDMA technology?
9. In STB DVB how many point fft is currently using?
10. Give FFT & IFFT formulae and calculate for any sequence?
11. What is "decimation-in-time" versus "decimation-in-frequency"?
12. What is "bit reversal"?
13. How does the FFT work?

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 29


III B.TECH - II SEM (R13) ECE: DSP LAB

Exp.No. 6
Exc.No.
FIR FILTER
Dt.

AIM:
To verify FIR filters.

EQUIPMENTS:
Operating System – Windows XP
Software - MATLAB 7.5

THEORY:
A Finite Impulse Response (FIR) filter is a discrete linear time-invariant system whose
output is based on the weighted summation of a finite number of past inputs. An FIR transversal
filter structure can be obtained directly from the equation for discrete-time convolution.

In this equation, x(k) and y(n) represent the input to and output from the filter at time n. h(n-
k) is the transversal filter coefficients at time n. These coefficients are generated by using FDS
(Filter Design Software or Digital filter design package). FIR – filter is a finite impulse response
filter. Order of the filter should be specified. Infinite response is truncated to get finite impulse
response. placing a window of finite length does this. Types of windows available are Rectangular,
Bartlett, Hamming, Hanning, Blackmann window etc. This FIR filter is an all zero filter.
% Algorithm for FIR filter%
Step 1: read the specifications of the filter
rp : pass band ripple
rs: stop band ripple
fp : pass band frequency
fs : stop band frequency
step2: wp = 2 fp / f, ws = 2 x fs / f
Num=20log10sqrt (rp*rs)-13
Den=14.6*fs-fp/f
Step 3: n=num/den
up truncate n and find its absolute value
n1=n+1;
if n/2 ~=0;
n1=n;
n=n-1;
Step 4: select the window type (i.e. rectangular, triangular, Kaiser) and find the filter
response using the function y=rectwin(n1) where n1 is the n1-point rectangular window
Step 5: for LPF
X1=fir1 (n,wp,y)
Step 6: plot magnitude and phase response of FIR filters

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 30


III B.TECH - II SEM (R13) ECE: DSP LAB

PROGRAM:
%fir filt design window techniques
clc;
clear all;
close all;
rp=input('enter passband ripple');
rs=input('enter the stopband ripple');
fp=input('enter passband freq');
fs=input('enter stopband freq');
f=input('enter sampling freq ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
c=input('enter your choice of window function 1. rectangular 2. triangular 3.kaiser: \n ');
if(c==1)
y=rectwin(n1);
disp('Rectangular window filter response');
end
if (c==2)
y=triang(n1);
disp('Triangular window filter response');
end
if(c==3)
y=kaiser(n1);
disp('kaiser window filter response');
end
%LPF
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);plot(o/pi,m);
title('LPF');
ylabel('Gain in dB-->');
xlabel('(a) Normalized frequency-->');
%HPF
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);plot(o/pi,m);

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 31


III B.TECH - II SEM (R13) ECE: DSP LAB

title('HPF');
ylabel('Gain in dB-->');
xlabel('(b) Normalized frequency-->');
%BPF
wn=[wp ws];
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);plot(o/pi,m);
title('BPF');
ylabel('Gain in dB-->');
xlabel('(c) Normalized frequency-->');
%BSF
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);plot(o/pi,m);
title('BSF');
ylabel('Gain in dB-->');
xlabel('(d) Normalized frequency-->');

OUTPUT:

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 32


III B.TECH - II SEM (R13) ECE: DSP LAB

LPF HPF
0 50

Gain in dB--> -20

Gain in dB-->
0
-40
-50
-60

-80 -100
0 0.5 1 0 0.5 1
(a) Normalized frequency--> (b) Normalized frequency-->
BPF BSF
20 0

0
Gain in dB-->

Gain in dB-->
-10
-20
-20
-40

-60 -30
0 0.5 1 0 0.5 1
(c) Normalized frequency--> (d) Normalized frequency-->

RESULT:

VIVA QUESTIONS
1. What are the advantages of FIR as compared to IIR?
2. How many types of FIR design methods are used in real time?.
3. What is meant by Gibbs Phenomenon? Where we find such type of effect in FIR filters?
4. What are the advantages& disadvantages of Rectangular window FIR filter as compared to
remaining window techniques?
5. Which window technique having less peak amplitude of side lobe as compared to all?
6. What do you understand by linear phase responce?
7. To design all types of filters what would be the expected impulse response?
8. What are the properties of FIR filter?.
9. How the zeros in FIR filter is located?
10. What are the desirable characteristics

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 33


III B.TECH - II SEM (R13) ECE: DSP LAB

Exp.No. 7 A
Exc.No.
DESIGN OF BUTTERWORTH FILTERS
Dt.

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

2
=

where N is the order of the filter and 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 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.

LIBRARY FUNCTIONS:

 butter: Butterworth digital and analog filter design.


[B, A] = butter (N,Wn) designs an Nth order Low pass digital Butterworth filter and returns
the filter coefficient vectors B (numerator) and A (denominator) in length N+1. The
coefficients are listed in descending powers of z. The cut-off frequency Wn must be in the
range 0.0 < Wn < 1.0, with 1.0 corresponding to half the sample rate.

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 34


III B.TECH - II SEM (R13) ECE: DSP LAB

butter (N,Wn,'s'),butter (N,Wn,'low','s'),butter (N,Wn,'high','s'),butter (N,Wn,'pass','s')and


butter (N,Wn,'stop','s')design analog Butterworth filters. In this case, Wn is in [rad/s] and it
can be greater than 1.0.

 buttord: Butterworth filter order selection.


[N, Wn] = 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 pass band and has at least Rs dB of
attenuation in the stop band. Wp and Ws are the pass band and stop band edge frequencies,
normalized from 0 to 1 (where 1 corresponds to pi radians/sample). For example,

Lowpass: Wp = .1, Ws = .2

Highpass: Wp = .2, Ws = .1

Bandpass: Wp = [.2 .7], Ws = [.1 .8]

Bandstop: Wp = [.1 .8], Ws = [.2 .7]

buttord: also returns Wn, the Butterworth natural frequency (or) the "3 dB frequency" to
be used with BUTTER to achieve the specifications.

[N, Wn] = buttord (Wp, Ws, Rp, Rs, 's') does the computation for an analog filter, in
which case Wp and Ws are in radians/second. When Rp is chosen as 3 dB, the Wn in
BUTTER is equal to Wp in BUTTORD.

 angle : Phase angle.


Theta=angle (H) returns the phase angles, in radians, of a matrix with complex elements.

 freqs : Laplace-transform (s-domain) frequency response.


H = freqs(B,A,W) returns the complex frequency response vector H of the filter B/A:

B(s) b (1)s nb-1 + b(2)s nb-2 + ... + b(nb)

H(s) = ---- = --------------------------------------------------

A(s) a(1)s na-1 + a(2)s na-2 + ... + a(na)

given the numerator and denominator coefficients in vectors B and A. The frequency
response is evaluated at the points specified in vector W (in rad/s). The magnitude and
phase can be graphed by calling freqs(B,A,W) with no output arguments.

 tf: Transfer function


SYS = tf(NUM,DEN) creates a continuous-time transfer function SYS with

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 35


III B.TECH - II SEM (R13) ECE: DSP LAB

numerator(s) NUM and denominator(s) DEN. The output SYS is a tf object.

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
% 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);

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 36


III B.TECH - II SEM (R13) ECE: DSP LAB

semilogx(f,p);
xlabel('Frequency');
ylabel('Phase');
title('Phase response of Butterworth LPF');

SOURCE CODE:2
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');
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 : ');

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 37


III B.TECH - II SEM (R13) ECE: DSP LAB

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];

%Band stop Filtering


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

%plotting magnitude and phase response


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

Command Windows :

Using Low pass filter

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 38


III B.TECH - II SEM (R13) ECE: DSP LAB

Using High pass filter

Using Band pass filter

Using Band stop filter

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 39


III B.TECH - II SEM (R13) ECE: DSP LAB

OUTPUTS:

Using Low pass filter

Using High pass filter

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 40


III B.TECH - II SEM (R13) ECE: DSP LAB

Using Band pass filter

Using Band stop filter

RESULT:

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 41


III B.TECH - II SEM (R13) ECE: DSP LAB

Exp.No. 7 B
Exc.No. DESIGN OF CHEBYSHEV FILTERS
Dt.

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.

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

is the ripple parameter in pass band

CN(x) is the Nth order Chebyshev polynomial defined as

CN(x) =

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.

LIBRARY FUNCTIONS:

 cheb1ord: Chebyshev Type I filter order selection.

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 42


III B.TECH - II SEM (R13) ECE: DSP LAB

[N, Wn] = 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 pass band and has at least Rs
dB of attenuation in the stop band. Wp and Ws are the pass band and stop band edge
frequencies, normalized from 0 to 1 (where 1 corresponds to pi radians/sample). For
example,

Lowpass: Wp = .1, Ws = .2

Highpass: Wp = .2, Ws = .1

Bandpass: Wp = [.2 .7], Ws = [.1 .8]

Bandstop: Wp = [.1 .8], Ws = [.2 .7]

cheb1ord also returns Wn, the Chebyshev natural frequency to use with cheby1 to achieve
the specifications.

[N, Wn] = cheb1ord (Wp, Ws, Rp, Rs, 's') does the computation for an analog filter, in
which case Wp and Ws are in radians/second.

 cheby1 Chebyshev Type I digital and analog filter design.


[B,A] = cheby1 (N,R,Wn) designs an Nth order Low pass digital Chebyshev filter with R
decibels of peak-to-peak ripple in the pass band. cheby1 returns the filter coefficient
vectors B (numerator) and A (denominator) of length N+1. The cut-off frequency Wn must
be in the range 0.0 < Wn < 1.0, with 1.0 corresponding to half the sample rate. Use R=0.5
as a starting point, if you are unsure about choosing R.

cheby1 (N,R,Wn,'s'), cheby1 (N,R,Wn,'low','s'), cheby1 (N,R,Wn,'high','s'), cheby1


(N,R,Wn,'pass','s') and cheby1 (N,R,Wn,'stop','s') design analog Chebyshev Type I filters.
In this case, Wn is in [rad/s] and it can be greater than 1.0.

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.

CHEBYSHEV FILTERS :

Source code:1

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 43


III B.TECH - II SEM (R13) ECE: DSP LAB

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;
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;

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 44


III B.TECH - II SEM (R13) ECE: DSP LAB

%% 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];

%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);

Command Window :1(LPF)

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 45


III B.TECH - II SEM (R13) ECE: DSP LAB

Output:

Command Window :2(HPF)

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 46


III B.TECH - II SEM (R13) ECE: DSP LAB

Output:

Command Window :3(BPF)

Output:

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 47


III B.TECH - II SEM (R13) ECE: DSP LAB

Command Window :4(BSF)

Output:

RESULT:

Exp.No. 8

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 48


III B.TECH - II SEM (R13) ECE: DSP LAB

Exc.No.
DESIGN OF IIR FILTERS
Dt.

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:
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

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

H(Z) =

This transformation maps the jΩ axis (from Ω = -∞ to +∞) repeatedly around the unit circle (exp
( jw), from w=-π to π ) by

2  
 tan 
T 2

BILINEAR TRANSFORMATION:
DESIGN STEPS:

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 49


III B.TECH - II SEM (R13) ECE: DSP LAB

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

3. Substitute 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

LIBRARY FUNCTIONS:
 Impinvar: Impulse Invariant method for analog-to-digital filter conversion [bz,az] =
impinvar(b,a,fs) creates a digital filter with numerator and denominator coefficients bz and
az, respectively, whose impulse response is equal to the impulse response of the analog
filter with coefficients b and a, scaled by 1/fs. If you leave out the argument fs (or) specify
fs as an empty vector [ ], it takes the default value of 1 Hz.

 Bilinear: Bilinear transformation method for analog-to-digital filter conversion. The bilinear
transformation is a mathematical mapping of variables. In digital filtering, it is a standard
method of mapping the s or analog plane into the z or digital plane. It transforms analog
filters, designed using classical filter design

ALGORITHM/PROCEDURE:

1. Calculate the attenuation in dB for the given design parameters


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 ');

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 50


III B.TECH - II SEM (R13) ECE: DSP LAB

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] = 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;

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 51


III B.TECH - II SEM (R13) ECE: DSP LAB

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)
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');
ylabel('Phase');
title('Phase Response of IIR Filter using Bilinear Transformation Method');

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 52


III B.TECH - II SEM (R13) ECE: DSP LAB

/ 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);

% 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);

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 53


III B.TECH - II SEM (R13) ECE: DSP LAB

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
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');

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 54


III B.TECH - II SEM (R13) ECE: DSP LAB

% 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');

/ Butterworth Lowpass Impulse invariant method


Command window:

Output:

/ Butterworth Lowpass Bilinear Transformation Method

Command Window :

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 55


III B.TECH - II SEM (R13) ECE: DSP LAB

Output:

/ Chebyshev Lowpass Impulse invariant method

Command Window:

Output:

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 56


III B.TECH - II SEM (R13) ECE: DSP LAB

/Chebyshev Lowpass Bilinear Transformation Method

Command Window:

Output:

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 57


III B.TECH - II SEM (R13) ECE: DSP LAB

RESULT:

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 58


III B.TECH - II SEM (R13) ECE: DSP LAB

Exp.No. 1
Exc.No.
GENERATION OF RANDOM SIGNALS
Dt.

AIM:- To generate a sine wave and square wave using C6713 simulator

EQUIPMENT:-
1. Operating System - Windows XP
2. Software - CC STUDIO 3
3. DSK 6713 DSP Trainer kit.
4. USB Cable
5. Power supply

PROCEDURE:
1. Open Code Composer Studio, make sure the DSP kit is turned on.
2. To open project:
Project  open  rollnumber.pjt
3. To create a source file:
File  new  type the code ( save and give File name/ Eg: lineconv.c)
4. To add source files to project:
Project  add files to project  lineconv.c
5. To add rts6700.lib (Library file):
Project  add files to project  rts6700.lib
Library files: rts6700.lib(path: c:\cc studio\c6000\cgtools\lib\rts6700)
Note: select object & library in type of files
6. To add hello.cmd file (Linker command file):
Project  add files to project  hello.cmd
Linker command file:rts6700.lib(path:c:\cc studio\tutorial\dsk6713\hello1\hello)
Note: select Linker command in type of files
7. To compile source file: project  compile
8. To rebuild all: project  rebuild all
Which will create the final.out executable file (Eg: rollnumber.out)
9. To load the program in DSP chip:
File  load program  rollnumber.out
10. To run the program:
Debug  Run
11. To view output graphically:
Select view  graph  time/frequency

PROGRAM: (a)

#include <stdio.h>
#include <math.h>
float a[500];

void main()

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 59


III B.TECH - II SEM (R13) ECE: DSP LAB

{
int i=0;
for(i=0;i<500;i++)
{
a[i]=sin(2*3.14*10000*i);
}
}

PROGRAM: (b)

#include <stdio.h>
#include <math.h>
int a[1000];
void main()
{
int i,j=0;
int b=5;
for(i=0;i<10;i++)
{
for (j=0;j<=50;j++)
{
a[(50*i)+j]=b;
}
b=b*(-1) ;
}
}

Output:- Sine wave

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 60


III B.TECH - II SEM (R13) ECE: DSP LAB

Square wave:-

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 61


III B.TECH - II SEM (R13) ECE: DSP LAB

Result:-.

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 62


III B.TECH - II SEM (R13) ECE: DSP LAB

Exp.No. 2
Exc.No. LINEAR CONVOLUTION

Dt.

AIM: To verify Linear Convolution Using DSK 6713 Trainer kit

EQUIPMENTS:-

1. Operating System - Windows XP


2. Software - CC STUDIO 3
3. DSK 6713 DSP Trainer kit.
4. USB Cable
5. Power supply

PROCEDURE:
1. Open Code Composer Studio, make sure the DSP kit is turned on.
2. To open project:
Project  open  rollnumber.pjt
3. To create a source file:
File  new  type the code ( save and give File name/ Eg: lineconv.c)
4. To add source files to project:
Project  add files to project  lineconv.c
5. To add rts6700.lib (Library file):
Project  add files to project  rts6700.lib
Library files: rts6700.lib(path: c:\cc studio\c6000\cgtools\lib\rts6700)
Note: select object & library in type of files
6. To add hello.cmd file (Linker command file):
Project  add files to project  hello.cmd
Linker command file:rts6700.lib(path:c:\cc studio\tutorial\dsk6713\hello1\hello)
Note: select Linker command in type of files
7. To compile source file: project  compile
8. To rebuild all: project  rebuild all
Which will create the final.out executable file (Eg: rollnumber.out)
9. To load the program in DSP chip:
File  load program  rollnumber.out
10. To run the program:
Debug  Run
11. To view output graphically:
Select view  graph  time/frequency
PROGRAM:

// Linear convolution program in c language using CC Studio


#include<stdio.h>
int x[15],h[15],y[15];

main()

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 63


III B.TECH - II SEM (R13) ECE: DSP LAB

{
int i,j,m,n;
printf("\n enter value for m");
scanf("%d",&m);
printf("\n enter value for n");
scanf("%d",&n);
printf("Enter values for i/p x(n):\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf("Enter Values for i/p h(n) \n");
for(i=0;i<n; i++)
scanf("%d",&h[i]);
// padding of zeros
for(i=m;i<=m+n-1;i++)
x[i]=0;
for(i=n;i<=m+n-1;i++)
h[i]=0;
/* convolution operation */
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
{
y[i]=y[i]+(x[j]*h[i-j]);
}
}
//displaying the o/p
for(i=0;i<m+n-1;i++)
printf("\n The Value of output y[%d]=%d",i,y[i]);
}

Output:-
enter value for m 4
enter value for n 4
Enter values for i/p 1234
Enter Values for n 1234
The Value of output y[0]=1
The Value of output y[1]=4
The Value of output y[2]=10
The Value of output y[3]=20
The Value of output y[4]=25
The Value of output y[5]=24
The Value of output y[6]=16

RESULT:

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 64


III B.TECH - II SEM (R13) ECE: DSP LAB

Exp.No. 3
Exc.No. FIR FILTER DESIGN

Dt.

AIM: To verify FIR filter using CCS Studio.

EQUIPMENTS:-

1. Operating System - Windows XP


2. Software - CC STUDIO 3
3. DSK 6713 DSP Trainer kit.
4. USB Cable
5. Power supply

PROGRAM:

#include<stdio.h>

#include<math.h>

#define pi 3.1415

int n,N,c;

float wr[64],wt[64];

void main()

printf("\n enter no. of samples,N= :");

scanf("%d",&N);

printf("\n enter choice of window function\n 1.rect \n 2. triang \n c= :");

scanf("%d",&c);

printf("\n elements of window function are:");

switch(c)

case 1:

for(n=0;n<=N-1;n++)

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 65


III B.TECH - II SEM (R13) ECE: DSP LAB

wr[n]=1;

printf(" \n wr[%d]=%f",n,wr[n]);

break;

case 2:

for(n=0;n<=N-1;n++)

wt[n]=1-(2*(float)n/(N-1));

printf("\n wt[%d]=%f",n,wt[n]);

break;

PROCEDURE:
1. Open Code Composer Studio, make sure the DSP kit is turned on.
2. To open project:
Project  open  rollnumber.pjt
3. To create a source file:
File  new  type the code ( save and give File name/ Eg: lineconv.c)
4. To add source files to project:
Project  add files to project  lineconv.c
5. To add rts6700.lib (Library file):
Project  add files to project  rts6700.lib
Library files: rts6700.lib(path: c:\cc studio\c6000\cgtools\lib\rts6700)
Note: select object & library in type of files
6. To add hello.cmd file (Linker command file):
Project  add files to project  hello.cmd
Linker command file:rts6700.lib(path:c:\cc studio\tutorial\dsk6713\hello1\hello)
Note: select Linker command in type of files
7. To compile source file: project  compile
8. To rebuild all: project  rebuild all
Which will create the final.out executable file (Eg: rollnumber.out)
9. To load the program in DSP chip:
File  load program  rollnumber.out
10. To run the program:
Debug  Run
11. To view output graphically:
Select view  graph  time/frequency

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 66


III B.TECH - II SEM (R13) ECE: DSP LAB

OUTPUT:

RESULT:

Exp.No. 4 IIR FILTER DESIGN


Exc.No.

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 67


III B.TECH - II SEM (R13) ECE: DSP LAB

Dt.

AIM: To verify IIR filter using CCS Studio.

EQUIPMENTS:-

1. Operating System - Windows XP


2. Software - CC STUDIO 3
3. DSK 6713 DSP Trainer kit.
4. USB Cable
5. Power supply

PROGRAM:

//iirfilters

#include<stdio.h>

#include<math.h>

int i,w,wc,c,N;

float H[100];

float mul(float, int);

void main()

printf("\n enter order of filter ");

scanf("%d",&N);

printf("\n enter the cutoff freq ");

scanf("%d",&wc);

printf("\n enter the choice for IIR filter 1. LPF 2.HPF ");

scanf("%d",&c);

switch(c)

case 1:

for(w=0;w<100;w++)

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 68


III B.TECH - II SEM (R13) ECE: DSP LAB

H[w]=1/sqrt(1+mul((w/(float)wc),2*N));

printf("H[%d]=%f\n",w,H[w]);

break;

case 2:

for(w=0;w<=100;w++)

H[w]=1/sqrt(1+mul((float)wc/w,2*N));

printf("H[%d]=%f\n",w,H[w]);

break;

float mul(float a,int x)

for(i=0;i<x-1;i++)

a*=a;

return(a);

PROCEDURE:
1. Open Code Composer Studio, make sure the DSP kit is turned on.
2. To open project:
Project  open  rollnumber.pjt
3. To create a source file:
File  new  type the code ( save and give File name/ Eg: lineconv.c)
4. To add source files to project:
Project  add files to project  lineconv.c
5. To add rts6700.lib (Library file):
Project  add files to project  rts6700.lib
Library files: rts6700.lib(path: c:\cc studio\c6000\cgtools\lib\rts6700)
Note: select object & library in type of files
6. To add hello.cmd file (Linker command file):
Project  add files to project  hello.cmd
Linker command file:rts6700.lib(path:c:\cc studio\tutorial\dsk6713\hello1\hello)
Note: select Linker command in type of files

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 69


III B.TECH - II SEM (R13) ECE: DSP LAB

7. To compile source file: project  compile


8. To rebuild all: project  rebuild all
Which will create the final.out executable file (Eg: rollnumber.out)
9. To load the program in DSP chip:
File  load program  rollnumber.out
10. To run the program:
Debug  Run
11. To view output graphically:
Select view  graph  time/frequency

OUTPUT:

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 70


III B.TECH - II SEM (R13) ECE: DSP LAB

RESULT:

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 71


III B.TECH - II SEM (R13) ECE: DSP LAB

APPENDIX A
MATLAB

A.1 Introduction
MATLAB is a high-performance language for technical computing. It integrates
computation, visualization, and programming in an easy-to-use environment where problems and
solutions are expressed in familiar mathematical notation. MATLAB stands for matrix laboratory,
and was written originally to provide easy access to matrix software developed by LINPACK
(linear system package) and EISPACK (Eigen system package) projects. MATLAB is therefore
built on a foundation of sophisticated matrix software in which the basic element is array that does
not require pre dimensioning which to solve many technical computing problems, especially those
with matrix and vector formulations, in a fraction of time.

MATLAB features a family of applications specific solutions called toolboxes. Very


important to most users of MATLAB, toolboxes allow learning and applying specialized
technology. These are comprehensive collections of MATLAB functions (M-files) that extend the
MATLAB environment to solve particular classes of problems. Areas in which toolboxes are
available include signal processing, control system, neural networks, fuzzy logic, wavelets,
simulation and many others.

Typical uses of MATLAB include: Math and computation, Algorithm development, Data
acquisition, Modeling, simulation, prototyping, Data analysis, exploration, visualization, Scientific
and engineering graphics, Application development, including graphical user interface building.
A.2 Basic Building Blocks of MATLAB
The basic building block of MATLAB is MATRIX. The fundamental data type is the array.
Vectors, scalars, real matrices and complex matrix are handled as specific class of this basic data
type. The built in functions are optimized for vector operations. No dimension statements are
required for vectors or arrays.

A.2.1 MATLAB Window


The MATLAB works based on five windows: Command window, Workspace window,
Current directory window, Command history window, Editor Window, Graphics window and
Online-help window.

A.2.1.1 Command Window


The command window is where the user types MATLAB commands and expressions at the
prompt (>>) and where the output of those commands is displayed. It is opened when the
application program is launched. All commands including user-written programs are typed in this
window at MATLAB prompt for execution.

A.2.1.2 Work Space Window


MATLAB defines the workspace as the set of variables that the user creates in a work
session. The workspace browser shows these variables and some information about them. Double

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 72


III B.TECH - II SEM (R13) ECE: DSP LAB

clicking on a variable in the workspace browser launches the Array Editor, which can be used to
obtain information.

A.2.1.3 Current Directory Window


The current Directory tab shows the contents of the current directory, whose path is shown
in the current directory window. For example, in the windows operating system the path might be
as follows: C:\MATLAB\Work, indicating that directory “work” is a subdirectory of the main
directory “MATLAB”; which is installed in drive C. Clicking on the arrow in the current directory

window shows a list of recently used paths. MATLAB uses a search path to find M-files
and other MATLAB related files. Any file run in MATLAB must reside in the current directory or
in a directory that is on search path.

A.2.1.4 Command History Window


The Command History Window contains a record of the commands a user has entered in
the command window, including both current and previous MATLAB sessions. Previously entered
MATLAB commands can be selected and re-executed from the command history window by right
clicking on a command or sequence of commands. This is useful to select various options in
addition to executing the commands and is useful feature when experimenting with various
commands in a work session.

A.2.1.5 Editor Window


The MATLAB editor is both a text editor specialized for creating M-files and a graphical
MATLAB debugger. The editor can appear in a window by itself, or it can be a sub window in the
desktop. In this window one can write, edit, create and save programs in files called M-files.

MATLAB editor window has numerous pull-down menus for tasks such as saving, viewing,
and debugging files. Because it performs some simple checks and also uses color to differentiate
between various elements of code, this text editor is recommended as the tool of choice for writing
and editing M-functions.

A.2.1.6 Graphics or Figure Window


The output of all graphic commands typed in the command window is seen in this window.

A.2.1.7 Online Help Window


MATLAB provides online help for all it’s built in functions and programming language
constructs. The principal way to get help online is to use the MATLAB help browser, opened as a
separate window either by clicking on the question mark symbol (?) on the desktop toolbar, or by
typing help browser at the prompt in the command window. The help Browser is a web browser
integrated into the MATLAB desktop that displays a Hypertext Markup Language (HTML)
documents. The Help Browser consists of two panes, the help navigator pane, used to find
information, and the display pane, used to view the information. Self-explanatory tabs other than
navigator pane are used to perform a search.

A.3 MATLAB Files

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 73


III B.TECH - II SEM (R13) ECE: DSP LAB

MATLAB has three types of files for storing information. They are: M-files and MAT-files.

A.3.1 M-Files
These are standard ASCII text file with ‘m’ extension to the file name and creating own
matrices using M-files, which are text files containing MATLAB code. MATLAB editor or another
text editor is used to create a file containing the same statements which are typed at the MATLAB
command line and save the file under a name that ends in .m. There are two types of M-files:

1. Script Files
It is an M-file with a set of MATLAB commands in it and is executed by typing name of
file on the command line. These files work on global variables currently present in that
environment.

2. Function Files

A function file is also an M-file except that the variables in a function file are all local. This
type of files begins with a function definition line.

A.3.2 MAT-Files
These are binary data files with .mat extension to the file that are created by MATLAB
when the data is saved. The data written in a special format that only MATLAB can read. These are
located into MATLAB with ‘load’ command.

A.4 the MATLAB System:


The MATLAB system consists of five main parts:
A.4.1 Development Environment:
This is the set of tools and facilities that help you use MATLAB functions and files. Many
of these tools are graphical user interfaces. It includes the MATLAB desktop and Command
Window, a command history, an editor and debugger, and browsers for viewing help, the
workspace, files, and the search path.

A.4.2 the MATLAB Mathematical Function:


This is a vast collection of computational algorithms ranging from elementary functions like
sum, sine, cosine, and complex arithmetic, to more sophisticated functions like matrix inverse,
matrix eigen values, Bessel functions, and fast Fourier transforms.

A.4.3 the MATLAB Language:


This is a high-level matrix/array language with control flow statements, functions, data
structures, input/output, and object-oriented programming features. It allows both "programming in
the small" to rapidly create quick and dirty throw-away programs, and "programming in the large"
to create complete large and complex application programs.

A.4.4 Graphics:
MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as
annotating and printing these graphs. It includes high-level functions for two-dimensional and
three-dimensional data visualization, image processing, animation, and presentation graphics. It

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 74


III B.TECH - II SEM (R13) ECE: DSP LAB

also includes low-level functions that allow you to fully customize the appearance of graphics as
well as to build complete graphical user interfaces on your MATLAB applications.

A.4.5 the MATLAB Application Program Interface (API):

This is a library that allows you to write C and FORTRAN programs that interact with
MATLAB. It includes facilities for calling routines from MATLAB (dynamic linking), calling
MATLAB as a computational engine, and for reading and writing MAT-files.

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 75


III B.TECH - II SEM (R13) ECE: DSP LAB

APPENDIX-B

MATLAB COMMANDS

clc:

Clear Command Window

GUI Alternatives

As an alternative to the clc function, select Edit > Clear Command Window in the
MATLAB desktop.

Syntax

clc

Description

clc clears all input and output from the Command Window display, giving you a
"clean screen."

clear:

Remove items from workspace, freeing up system memory

Graphical Interface

As an alternative to the clear function, use Edit > Clear Workspace in the MATLAB®
desktop.

Syntax

clear

clear name

clear name1 name2 name3 ...

Description

clear removes all variables from the workspace. This frees up system memory.

clear name removes just the M-file or MEX-file function or variable name from the
workspace. You can use wildcards (*) to remove items selectively. For example, clear my*
removes any variables whose names begin with the string my. It removes debugging
breakpoints in M-files and reinitializes persistent variables, since the breakpoints for a
function and persistent variables are cleared whenever the M-file is changed or cleared. If
name is global, it is removed from the current workspace, but left accessible to any
functions declaring it global. If name has been locked by mlock, it remains in memory.

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 76


III B.TECH - II SEM (R13) ECE: DSP LAB

close:

Remove specified figure

Syntax

close

close(h)

close name

close all

Description

close deletes the current figure or the specified figure(s). It optionally returns the
status of the close operation.

close deletes the current figure (equivalent to close(gcf)).

close(h) deletes the figure identified by h. If h is a vector or matrix, clse deletes all
figures identified by h.

sin:

Sine of argument in radians

Syntax

Y = sin(X)

Description

The sin function operates element-wise on arrays. The function's domains and
ranges include complex values. All angles are in radians.

Y = sin(X) returns the circular sine of the elements of X.

pi :

Ratio of circle's circumference to its diameter, p

Syntax

pi

Description

pi returns the floating-point number nearest the value of p. The expressions


4*atan(1) and imag(log(-1)) provide the same value.
Examples

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 77


III B.TECH - II SEM (R13) ECE: DSP LAB

The expression sin(pi) is not exactly zero because pi is not exactly p.

sin(pi)

ans = 1.2246e-16

xlabel, ylabel, zlabel :

Label x-, y-, and z-axis

GUI Alternative

To control the presence and appearance of axis labels on a graph, use the Property
Editor, one of the plotting tools . For details, see The Property Editor in the MATLAB®
Graphics documentation.

Syntax

xlabel('string')

xlabel(fname)

xlabel(...,'PropertyName',PropertyValue,...)

xlabel(axes_handle,...)

Description

Each axes graphics object can have one label for the x-, y-, and z-axis. The label
appears beneath its respective axis in a two-dimensional plot and to the side or beneath the
axis in a three-dimensional plot.

grid:

Grid lines for 2-D and 3-D plots

GUI Alternative

To control the presence and appearance of grid lines on a graph, use the Property
Editor, one of the plotting tools . For details, see The Property Editor in the MATLAB®
Graphics documentation.

Syntax

grid on

grid off

grid

Description

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 78


III B.TECH - II SEM (R13) ECE: DSP LAB

The grid function turns the current axes' grid lines on and off.

grid on adds major grid lines to the current axes.

grid off removes major and minor grid lines from the current axes.

grid toggles the major grid visibility state.

grid(axes handle,...) uses the axes specified by axes handle instead of the current
axes.

tic, toc :

Measure performance using stopwatch timer

Synopsis

tic any statementstoc

t = toc

Description

tic starts a stopwatch timer.

toc prints the elapsed time since tic was used.

t = toc returns the elapsed time in t.

Remarks

The tic and toc functions work together to measure elapsed time. tic saves the
current time that toc uses later to measure the elapsed time. The sequence of commands

Tic

operations

toc

measures the amount of time the MATLAB® software takes to complete one or more
operations, and displays the time in seconds.

title:

Add title to current axes

GUI Alternative

To create or modify a plot's title from a GUI, use Insert Title from the figure menu.
Use the Property Editor, one of the plotting tools , to modify the position, font, and other
properties of a legend. For details, see The Property Editor in the MATLAB® Graphics
documentation.

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 79


III B.TECH - II SEM (R13) ECE: DSP LAB

Syntax

title('string')

title(fname)

title(...,'PropertyName',PropertyValue,...)

Description

Each axes graphics object can have one title. The title is located at the top and in the
center of the axes.

title('string') outputs the string at the top and in the center of the current axes.

title(fname) evaluates the function that returns a string and displays the string at the top and
in the center of the current axes.

Input :

Request user input

Syntax

user_entry = input('prompt')

user_entry = input('prompt', 's')

Description

The response to the input prompt can be any MATLAB expression, which is
evaluated using the variables in the current workspace.

user_entry = input('prompt') displays prompt as a prompt on the screen, waits for input from
the keyboard, and returns the value entered in user_entry.

user_entry = input('prompt', 's') returns the entered string as a text variable rather than as a
variable name or numerical value.

Remarks

If you press the Return key without entering anything, input returns an empty
matrix.

The text string for the prompt can contain one or more '\n' characters. The '\n' means to skip
to the next line. This allows the prompt string to span several lines. To display just a
backslash, use '\\'.

If you enter an invalid expression at the prompt, MATLAB displays the relevant error
message and then prompts you again to enter input.

legend :

Graph legend for lines and patches

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 80


III B.TECH - II SEM (R13) ECE: DSP LAB

GUI Alternatives

Add a legend to a selected axes on a graph with the Insert Legend tool on the figure
toolbar, or use Insert —> Legend from the figure menu. Use the Property Editor to modify
the position, font, and other properties of a legend. For details, see Using Plot Edit Mode in
the MATLAB® Graphics documentation.

Syntax

legend('string1','string2',...)

legend(h,'string1','string2',...)

legend(M)

legend(h,M)

legend(M,'parameter_name','parameter_value',...)

legend(h,M,'parameter_name','parameter_value',...)

legend(axes_handle,...)

legend('off'), legend(axes_handle,'off')

legend('toggle'), legend(axes_handle,'toggle')

Description

legend places a legend on various types of graphs (line plots, bar graphs, pie charts,
etc.). For each line plotted, the legend shows a sample of the line type, marker symbol, and
color beside the text label you specify. When plotting filled areas (patch or surface objects),
the legend contains a sample of the face color next to the text label.

The font size and font name for the legend strings match the axes FontSize and FontName
properties.

legend('string1','string2',...) displays a legend in the current axes using the specified


strings to label each set of data.

legend(h,'string1','string2',...) displays a legend on the plot containing the objects identified


by the handles in the vector h and uses the specified strings to label the corresponding
graphics object (line, barseries, etc.).

plot :

2-D line plot

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 81


III B.TECH - II SEM (R13) ECE: DSP LAB

GUI Alternatives

Use the Plot Selector to graph selected variables in the Workspace Browser and the
Plot Catalog, accessed from the Figure Palette. Directly manipulate graphs in plot edit
mode, and modify them using the Property Editor. For details, see Using Plot Edit Mode,
and The Figure Palette in the MATLAB® Graphics documentation, and also Creating
Graphics from the Workspace Browser in the MATLAB Desktop documentation.

Syntax

plot(Y)

plot(X1,Y1,...)

plot(X1,Y1,LineSpec,...)

plot(...,'PropertyName',PropertyValue,...)

Description

plot(Y) plots the columns of Y versus their index if Y is a real number. If Y is


complex, plot(Y) is equivalent to plot(real(Y),imag(Y)). In all other uses of plot, the
imaginary component is ignored.

plot(X1,Y1,...) plots all lines defined by Xn versus Yn pairs. If only Xn or Yn is a


matrix, the vector is plotted versus the rows or columns of the matrix, depending on
whether the vector's row or column dimension matches the matrix. If Xn is a scalar and Yn
is a vector, disconnected line objects are created and plotted as discrete points vertically at
Xn.

subplot :

GUI Alternatives

To add subplots to a figure, click one of the New Subplot icons in the Figure Palette,
and slide right to select an arrangement of subplots. For details, see Plotting Tools —
Interactive Plotting in the MATLAB® Graphics documentation.

Syntax

h = subplot(m,n,p) or subplot(mnp)

subplot(m,n,p,'replace')

subplot(m,n,P)

subplot(h)

Description

subplot divides the current figure into rectangular panes that are numbered rowwise.
Each pane contains an axes object. Subsequent plots are output to the current pane.

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 82


III B.TECH - II SEM (R13) ECE: DSP LAB

h = subplot(m,n,p) or subplot(mnp) breaks the figure window into an m-by-n matrix of


small axes, selects the pth axes object for the current plot, and returns the axes handle. The
axes are counted along the top row of the figure window, then the second row, etc. For
example,

stem :

Plot discrete sequence data

GUI Alternatives

To graph selected variables, use the Plot Selector in the Workspace Browser, or use
the Figure Palette Plot Catalog. Manipulate graphs in plot edit mode with the Property
Editor. For details, see Plotting Tools — Interactive Plotting in the MATLAB® Graphics
documentation and Creating Graphics from the Workspace Browser in the MATLAB
Desktop Tools documentation.

Syntax

stem(Y)

stem(X,Y)

stem(...,'fill')

Description

A two-dimensional stem plot displays data as lines extending from a baseline along
the x-axis. A circle (the default) or other marker whose y-position represents the data value
terminates each stem.

stem(Y) plots the data sequence Y as stems that extend from equally spaced and
automatically generated values along the x-axis. When Y is a matrix, stem plots all elements
in a row against the same x value.

stem(X,Y) plots X versus the columns of Y. X and Y must be vectors or matrices of


the same size. Additionally, X can be a row or a column vector and Y a matrix with
length(X) rows.

stem(...,'fill') specifies whether to color the circle at the end of the stem.

disp :

Display text or array

Syntax

disp(X)

Description

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 83


III B.TECH - II SEM (R13) ECE: DSP LAB

disp(X) displays an array, without printing the array name. If X contains a text
string, the string is displayed.

Another way to display an array on the screen is to type its name, but this prints a leading
"X=," which is not always desirable.

Note that disp does not display empty arrays.

fir1 :

Window-based finite impulse response filter design

Syntax

b = fir1(n,Wn)

b = fir1(n,Wn,'ftype')

b = fir1(n,Wn,window)

b = fir1(n,Wn,'ftype',window)

b = fir1(...,'normalization')

Description

fir1 implements the classical method of windowed linear-phase FIR digital filter
design [1]. It designs filters in standard lowpass, highpass, bandpass, and bandstop
configurations. By default the filter is normalized so that the magnitude response of the
filter at the center frequency of the passband is 0 dB.

b = fir1(n,Wn) returns row vector b containing the n+1 coefficients of an order n


lowpass FIR filter. This is a Hamming-window based, linear-phase filter with normalized
cutoff frequency Wn. The output filter coefficients, b, are ordered in descending powers of
z.

Wn is a number between 0 and 1, where 1 corresponds to the Nyquist frequency.

If Wn is a two-element vector, Wn = [w1 w2], fir1 returns a bandpass filter with passband
w1 < ?< w2.

fopen :

Open file, or obtain information about open files

Syntax

fid = fopen(filename)

fid = fopen(filename, permission)

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 84


III B.TECH - II SEM (R13) ECE: DSP LAB

fid = fopen(filename, permission_tmode)

Description

fid = fopen(filename) opens the file filename for read access. (On Windows®
systems, fopen opens files for binary read access.) The filename argument is a string
enclosed in single quotes. It can be a MATLABPATH relative partial pathname if the file is
opened for reading only.

A relative path is always searched for first with respect to the current directory. If it
is not found, and reading only is specified or implied, then fopen does an additional search
of the MATLABPATH.

fid is a scalar MATLAB® integer, called a file identifier. You use the fid as the first
argument to other file input/output routines. If fopen cannot open the file, it returns -1. Two
file identifiers are automatically available and need not be opened. They are fid=1 (standard
output) and fid=2 (standard error).

fid = fopen(filename, permission) opens the file filename in the specified permission.

winopen :

Open file in appropriate application (Windows®)

Syntax

winopen(filename)

Description

winopen(filename) opens filename in the appropriate Microsoft® Windows


application. The filename input is a string enclosed in single quotes. The winopen function
uses the appropriate Windows shell command, and performs the same action as if you
double-click the file in the Windows Explorer program. If filename is not in the current
directory, specify the absolute path for filename.

fprintf (serial):

Write text to device

Syntax

fprintf(obj,'cmd')

fprintf(obj,'format','cmd')

fprintf(obj,'cmd','mode')

fprintf(obj,'format','cmd','mode')

Arguments

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 85


III B.TECH - II SEM (R13) ECE: DSP LAB

obj

A serial port object.

'cmd'

The string written to the device.

'format'

C language conversion specification.

'mode'

Specifies whether data is written synchronously or asynchronously.

Description

fprintf(obj,'cmd') writes the string cmd to the device connected to obj. The default
format is %s\n. The write operation is synchronous and blocks the command line until
execution is complete.

fprintf(obj,'format','cmd') writes the string using the format specified by format.


format is a C language conversion specification. Conversion specifications involve the %
character and the conversion characters d, i, o, u, x, X, f, e, E, g, G, c, and s. Refer to the
sprintf file I/O format specifications or a C manual for more information.

fseek :

Set file position indicator

Syntax

status = fseek(fid, offset, origin)

Description

status = fseek(fid, offset, origin) repositions the file position indicator in the file with
the given fid to the byte with the specified offset relative to origin.

For a file having n bytes, the bytes are numbered from 0 to n-1. The position immediately
following the last byte is the end-of-file, or eof, position. You would seek to the eof position
if you wanted to add data to the end of a file.

This figure represents a file having 12 bytes, numbered 0 through 11. The first command
shown seeks to the ninth byte of data in the file. The second command seeks just past the
end of the file data, to the eof position.

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 86


III B.TECH - II SEM (R13) ECE: DSP LAB

fseek does not seek beyond the end of file eof position. If you attempt to seek beyond eof,
the MATLAB® software returns an error status.

Arguments

fid An integer file identifier obtained from fopen

offset A value that is interpreted as follows,

offset > 0 Move position indicator offset bytes toward the end of
the file.

offset = 0 Do not change position.

offset < 0 Move position indicator offset bytes toward the


beginning of the file.

origin A string whose legal values are

'bof' -1: Beginning of file

'cof' 0: Current position in file

'eof' 1: End of file

status A returned value that is 0 if the fseek operation is successful and -1 if


it fails. If an error occurs, use the function ferror to get more information.

boxcar :

boxcar Boxcar window.

boxcar still works but maybe removed in the future. Use

RECTWIN instead. Type help RECTWIN for details.

bartlett :

Bartlett window

Syntax

w = bartlett(L)

Description

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 87


III B.TECH - II SEM (R13) ECE: DSP LAB

w = bartlett(L) returns an L-point Bartlett window in the column vector w, where L must be
a positive integer. The coefficients of a Bartlett window are computed as follows:

The window length L = N+1

The Bartlett window is very similar to a triangular window as returned by the triang
function. The Bartlett window always ends with zeros at samples 1 and n, however, while
the triangular window is nonzero at those points. For L odd, the center L-2 points of
bartlett(L) are equivalent to triang(L-2).

kaiser :

Kaiser window

Syntax

w = kaiser(L,beta)

Description

w = kaiser(L,beta) returns an L-point Kaiser window in the column vector w. beta is


the Kaiser window ß parameter that affects the sidelobe attenuation of the Fourier transform
of the window. The default value for beta is 0.5.

To obtain a Kaiser window that designs an FIR filter with sidelobe attenuation of a dB, use
the following ß.

Increasing beta widens the main lobe and decreases the amplitude of the sidelobes (i.e.,
increases the attenuation).

freqs :

Frequency response of analog filters

Syntax

h = freqs(b,a,w)

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 88


III B.TECH - II SEM (R13) ECE: DSP LAB

[h,w] = freqs(b,a,n)

freqs

Description

freqs returns the complex frequency response H(j?) (Laplace transform) of an analog
filter

given the numerator and denominator coefficients in vectors b and a.

h = freqs(b,a,w) returns the complex frequency response of the analog filter


specified by coefficient vectors b and a. freqs evaluates the frequency response
along the imaginary axis in the complex plane at the angular frequencies in rad/sec
specified in real vector w, where w is a vector containing more than one frequency.

Syntax

[h,w] = freqz(ha)

[h,w] = freqz(ha,n)

freqz(ha)

[h,w] = freqz(hd)

[h,w] = freqz(hd,n)

freqz(hd)

Description

The next sections describe common freqz operation with adaptive, discrete-time, and
multirate filters. For more input options, refer to freqz in Signal Processing Toolbox
documentation.

Adaptive Filters

For adaptive filters, freqz returns the instantaneous frequency response based on the
current filter coefficients.

[h,w] = freqz(ha) returns the frequency response vector h and the corresponding
frequency vector w for the adaptive filter ha. When ha is a vector of adaptive filters, freqz
returns the matrix h. Each column of h corresponds to one filter in the vector ha.

[h,w] = freqz(ha,n) returns the frequency response vector h and the corresponding frequency
vector w for the adaptive filter ha. freqz uses the transfer function associated with the
adaptive filter to calculate the frequency response of the filter with the current coefficient
values. The vectors h and w are both of length n. The frequency vector w has values ranging
from 0 to p radians per sample. If you do not specify the integer n, or you specify it as the

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 89


III B.TECH - II SEM (R13) ECE: DSP LAB

empty vector [], the frequency response is calculated using the default value of 8192
samples for the FFT.

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 90


III B.TECH - II SEM (R13) ECE: DSP LAB

Discrete-Time Filters

[h,w] = freqz(hd) returns the frequency response vector h and the corresponding
frequency vector w for the discrete-time filter hd. When hd is a vector of discrete-time
filters, freqz returns the matrix h. Each column of h corresponds to one filter in the vector
hd.

fft :

Discrete Fourier transform

Syntax

Y = fft(X)

Y = fft(X,n)

Y = fft(X,[],dim)

Y = fft(X,n,dim)

Definition

The functions X = fft(x) and x = ifft(X) implement the transform and inverse
transform pair given for vectors of length

Description

Y = fft(X) returns the discrete Fourier transform (DFT) of vector X, computed with a fast
Fourier transform (FFT) algorithm.

If X is a matrix, fft returns the Fourier transform of each column of the matrix.

If X is a multidimensional array, fft operates on the first nonsingleton dimension.

log :

Natural logarithm

Syntax

Y = log(X)

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 91


III B.TECH - II SEM (R13) ECE: DSP LAB

Description

The log function operates element-wise on arrays. Its domain includes complex and
negative numbers, which may lead to unexpected results if used unintentionally.

Y = log(X) returns the natural logarithm of the elements of X. For complex or negative Z,

Z= x+y*I, the complex logarithm is returned.

log(z) = log(abs(z)) + i*atan2(y,x)

abs :

Absolute value and complex magnitude

Syntax

abs(X)

Description

abs(X) returns an array Y such that each element of Y is the absolute value of the
corresponding element of X.

If X is complex, abs(X) returns the complex modulus (magnitude), which is the


same as sqrt(real(X).^2 + imag(X).^2)

ECE DEPARTMENT, VISVODAYA TECHNICAL ACADEMY - KAVALI Page 92

You might also like