Svu Dsp-Lab - Manual-2
Svu Dsp-Lab - Manual-2
⮚ Compute circular convolution, linear convolution and the discrete Fourier transform
⮚ Analyze and implement digital systems using the DFT and the Fast Fourier Transform (FFT).
Course Outcomes:
LIST OF EXPERIMENTS:
10. Perform the conversion of analog filter into digital filter using the following methods
a) Impulse Invariant method
b) Bilinear Transformation method
MATLAB
TOOL BOX
Signal Processing Image Processing
Statistics Neural Network Control Systems Communication
MATLAB Windows:
MATLAB works with through three basic windows
Command Window : This is the main window .it is characterized by MATLAB command
prompt >> when you launch the application program MATLAB puts you in this window all
commands including those for user-written programs ,are typed in this window at the MATLAB
prompt
Graphics window: the output of all graphics commands typed in the command window are
flushed to the graphics or figure window, a separate gray window with white background color
the user can create as many windows as the system memory will allow
Edit window: This is where you write edit, create and save your own programs in files called M
files.
INPUT-OUTPUT:
MATLAB supports interactive computation taking the input from the screen and flushing,
the output to the screen. In addition it can read input files and write output files.
Data Type: the fundamental data –type in MATLAB is the array. It encompasses several distinct
data objects- integers, real numbers, matrices, character strings, structures and cells. There is no
need to declare variables as real or complex, MATLAB automatically sets the variable to be
real.
1. T = 0: 1:10
This instruction indicates a vector T which as initial value 0 and final value 10 with an
increment of 1
Therefore T = [0 1 2 3 4 5 6 7 8 9 10]
2. F= 20: 1: 100
Therefore F = [20 21 22 23 24 ……… 100]
3. T= 0:1/pi: 1
Therefore T= [0, 0.3183, 0.6366, 0.9549]
4. zeros (1, 3)
The above instruction creates a vector of one row and three columns whose values are zero Output=
[0 0 0]
5. ones (5,2)
The above instruction creates a vector of five rows and two columns
Output= 11
11
11
11
11
6. zeros (2, 4)
Output= 0 0 00
0 0 00
7. a = [ 1 2 3] , b = [4 5 6]
9. plot (t,x)
10. stem(t,x)
If x(n) = [0 1 2 3];This instruction will display a figure window as shown
11. Subplot: This function divides the figure window into rows and columns Subplot (2 2 1) divides
the figure window into 2 rows and 2 columns 1 represent number of the figure
13. Fliplr:
Syntax: B =fliplr(A)
Description :B=fliplr(A) returns A with columns flipped in the left-right direction, that is,
about a vertical axis. If A is a row vector, then fliplr(A) returns a vector of the same length with
the order of its elements reversed. If A is a column vector, then fliplr(A) simply returns A.
14. Conv:
Syntax: w =conv(u,v)
15. Impz:
Syntax: [h,t] =impz(b,a,n)
Description:[h,t] = impz(b,a,n) computes the impulse response of the filter with numerator
coefficients b and denominator coefficients a and computes n samples of the impulse response
when n is an integer (t = [0:n-1]'). If n is a vector of integers,impz computes the impulse response
at those integer locations, starting the response computation from 0 (and t = n or t = [0 n]).If,
instead of n, you include the empty vector for the second argument, the number of samples is
Department of ECE, SVUCE8
computed automatically by default.
16. Disp:
Syntax: disp(X)
Description: 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.
17. xlabel:
Syntax : xlabel('string')
Description : xlabel('string') labels the x-axis of the current axes.
18. Ylabel :
Syntax : ylabel('string')
Description :ylabel ('string') labels the y-axis of the current axes.
19. Title :
Syntax :title('string')
Description :title('string') outputs the string at the top and in the center of the current axes.
AIM:
RESULT:
Thus the programs for discrete time signals/sequences were executed
successfully using MATLAB and the results were plotted.
Ex. No: 1b
AIM:
GENERATION OF DISCRETE TIME
SIGNALS
To generate a discrete time signal sequence (Unit step, Unit ramp, Sine, Cosine,
Exponential, Unit impulse) using MATLAB function.
TOOLS REQUIRED:
6. If any error occurs in the program correct the error and run it again
AIM :
To compute DFT and IDFT of a sequence without using the inbuilt functions and to plot
magnitude and phase spectrum.
TOOLS REQUIRED:
OUTPUT:
Enter the sequence x(n)=[ 1 1 0 0 ]
DFT sequence is x(k) =[2,1-j,0,1+j]
Magnitude of x(k) =[2,√2,0,√2]
Phase of DFT=[0 , -0.7854 , -1.571 , 0.7854]
Magnitude of IDFT=[4 , 4 , 0 , 0]
Phase of IDFT=[0 , 0 , 1.938 , 0.9273]
RESULT:
Thus, the program for the DFT and IDFT of a sequence without using the inbuilt functions was
executed successfully using MATLAB and the results were plotted.
Exp. No. 3a
AIM:
To implement the Decimation –in Time FFT of a sequence using DIT-FFT method
TOOLS REQUIRED:
clear all;
close all;
x=input('enter x[n]:');
N=length(x);
levels=nextpow2(N);
xn=[x,zeros(1,(2^levels)-
N)]; x=bitrevorder(xn)
N=length(xn);
tw=cos(2*pi*(1/N)*(0:N/2-1))-j*sin(2*pi*(1/N)*(0:N/2-1));
for level=1:levels;
L=2^level;
twlvl=tw(1:N/L:N/2);
for k=0:L:N-L;
for n=0:L/2-1;
A=x(n+k+1);
B=x(n+k+(L/2)+1)*twlvl(n+1);
x(n+k+1)=A+B;
x(n+k+(L/2)+1)=A-B;
end
end
x
end
XK=x
n=0:N-1;
subplot(2,2,1);
stem(n,xn);
title('x(n)');
xlabel('n');
ylabel('Amplitude');
subplot(2,2,2);
stem(n,real(XK));
title('Real part of X(K)');
xlabel('n');
ylabel('Amplitude');
subplot(2,2,3);
stem(n,imag(XK));
title('Imag part of X(K)');
xlabel('n');
ylabel('Amplitude');
OUTPUT:
enter x[n]:[1 2 3 4 4 3 2 1]
XK =
20.0000-5.8284-2.4142i 0 -0.1716-0.4142i 0 -0.1716 +0.4142i
0 -5.8284 +2.4142i
RESULT:
Thus, the program for the DFT and IDFT of a sequence without using the inbuilt functions
was executed successfully using MATLAB and the results were plotted.
Exp. No. 3b
AIM:
To implement the Decimation –in Frequency FFT of a sequence using DIT-FFT method
TOOLS REQUIRED:
PROGRAM:
Clc;
Clear
all;
Close
all;
DECIMATION IN FREQUENCY [DIF] ALGORITHM
function q=dif(x)
S=log2(N); %stages
for stage=S:-
1:1 a=1;
stage n=0;
&&b<=N) l=(n).*(2^(S+1-stage))./2;
e=exp((-1i)*2*pi*l/(16)); %Twiddle
factor y=j(a)+j(b);
z=(j(a)-j(b)).*e; % Butterfly
structure j(a)=y;
j(b)=z;
a=a+1; % Increment a,b and n
b=b+1;
n=n+1;
a=a+2^(stage-1);
b=b+2^(stage-1);
n=0;
end
end
if(stage~=1)
if(rem(a,2^(stage-1))==1)
a=a+2^(stage-1);
b=b+2^(stage-1);
n=0;
end
end
end
end
disp(j);
q=j;
end
RESULT:
Thus, the program for the DFT and IDFT of a sequence without using the inbuilt functions was
executed successfully using MATLAB and the results were plotted.
Exp. No. 4a
AIM:
To compute linear convolution of two given sequences using inbuilt MATLAB functions FFT and
IFFT for DFT and IDFT.
TOOLS REQUIRED:
PROGRAM:
clc;
clear all;
close all;
xn=input(‘enter the first sequence x(n)=’);
hn=input(‘enter the second sequence h(n)=’);
N=length(xn)+length(hn)-1;
Xk=fft(xn,N);
Hk=fft(hn,N);
Yk=Xk*Hk;
yn=ifft(Yk,N);
disp(‘linear convolution of x(n) and h(n)=’);
disp(yn);
subplot(2,2,1);
stem(xn);
xlabel(‘n’);
ylabel(‘x(n)’);
title(‘plot of x(n)’);
subplot(2,2,2);
stem(hn);
xlabel(‘n’);
ylabel(‘h(n)’);
title(‘plot of h(n)’);
subplot(2,2,3);
xlabel(‘n’);
ylabel(‘y(n)’);
title(‘convolution output’);
yv=conv(xn,hn);
disp(‘convolution in time domain=’);
disp(yv);
subplot(2,2,4);
stem(yv);
xlabel(‘n’);
ylabel(‘yv(n)’);
title(‘verified convolution output’);
OUTPUT:
RESULT:
Linear convolution of two given sequences was found using DFT and
IDFT in MATLAB and the result was verified.
Exp. No. 4b
AIM:
To compute circularr convolution of two given sequences using inbuilt MATLAB functions FFT
and IFFT for DFT and IDFT.
TOOLS REQUIRED:
PROGRAM:
clc;
clear all;
close all;
xn=input(‘enter the first sequence x(n)=’);
hn=input(‘enter the second sequence h(n)=’);
N=max(length(xn),length(hn));
Xk=fft(xn,N);
Hk=fft(hn,N);
Yk=Xk.*Hk;
yn=ifft(Yk,N);
disp(‘circular convolution of x(n) and h(n)=’);
disp(yn);
subplot(2,2,1);
stem(xn);
xlabel(‘n’);
ylabel(‘x(n)’);
title(‘plot of x(n)’);
subplot(2,2,2);
stem(hn);
xlabel(‘n’);
ylabel(‘h(n)’);
title(‘plot of h(n)’);
subplot(2,2,3);
stem(yn);
xlabel(‘n’);
ylabel(‘y(n)’);
title(‘circular convolution output’);
OUTPUT:
enter the first sequence x(n)= [5 6 7]
Enter the second sequence h(n)= [4 3 2]
Circular convolution of x(n) and h(n)= [53 53 56]
RESULT:
Thus, the Circular convolution of two given sequences was found using DFT and IDFT in
MATLAB.
Ex. No: 5
TOOLS REQUIRED:
6. If any error occurs in the program correct the error and run it again
INPUT:
type length of DFT=32 type
sampling period=64
type the sinusoidal freq=11
RESULT:
Thus the Spectrum Analysis of the signal using DFT was obtained using MATLAB.
Ex. No: 6
DESIGN OF BUTTERWORTH IIR FILTER (LOW PASS, HIGH PASS)
AIM :
To write a MATLAB program for designing butterworth IIR Filter for low pass and high pass
circuits.
TOOLS REQUIRED:
6. If any error occurs in the program correct the error and run it again
PROGRAM :
clc
clear all;
close all;
rp=input('Enter pass band ripple:');
rs=input('Enter stop band ripple:');
fp=input('Enter pass band freq:');
fs=input('Enter stop band freq:');
f=input('Enter range of freq:');
wp=2*(fp/f);
ws=2*(fs/f);
[n,wn]=buttord (wp,ws,rp,rs);
[b,a]=butter(n,wn,'high'); [b,a]=butter(n,wn, 'low');
[h,w]=freqz(b,a);
subplot(2,1,1); plot(w/pi,20* log(abs(h)));
grid;
xlabel('nf');
ylabel('mag');
title('mag response');
subplot(2,1,2);
plot(w/pi,angle(h));
grid;
xlabel('nf');
ylabel('angle');
title('phase response');
INPUT :
Enter pass band ripple : 05
Enter stop band ripple : 30
Enter pass band freq : 340
Enter stop band freq : 725
Enter range of freq : 4530
RESULT :
Thus, the design of butterworth LPF and HPF using MATLAB was observed for the above
parameters.
Ex. No: 8
DESIGN OF FIR FILTERS
AIM :
To write and simulate a MATLAB program for designing FIR filters i.e., low pass, high pass and
band pass Filters.
TOOLS REQUIRED:
6. If any error occurs in the program correct the error and run it again
PROGRAM :
clc;
close all;
clear all;
f=input('Enter frequency range:');
fs=input('Enter sampling range:');
n=input('Enter order of filter:');
w=f/(fs/2);
b=fir1(n,w, 'low');
freqz(b,1,128,fs);
figure;
w=f/(fs/2);
b=fir1(n,w,'high');
freqz(b,1,128,fs);
figure;
b=fir1(n, [f/(fs/2) (f+600)/(fs/2)], 'bandpass');
freqz(b,1,128,fs);
INPUT:
Enter frequency range: 1500
Enter sampling range: 9300
Enter order of filter: 63
RESULT :
Thus, a MATLAB program for designing FIR filters i.e., low pass, high pass and band pass Filters
was simulated and results were observed for the above parameters.
Ex. No: 9
DESIGN FIR LPF USING DIFFERENT WINDOW TECHNIQUES
AIM :
To write and simulate a MATLAB program for designing FIR filters i.e., low pass Filter using
various window techniques.
TOOLS REQUIRED:
PROCEDURE:
1. Start the MATLAB program.
6. If any error occurs in the program correct the error and run it again
PROGRAM :
clc;
close all;
clear all;
n=input("Enter order of filter:");
fp=input("Enter pass band freq:" );
fa=input("Enter stop band freq:");
f=input("Enter range of freq:");
wp=2*(fp/f);
wa=2*(fa/f);
wn=[wp,wa];
window=boxcar(n+1);
window=bartlett(n+1);
window=hamming(n+1);
window=hanning(n+1);
window=kaiser(n+1);
b=fir1(n,wn,window);
[H,w]=freqz(b,1);
subplot(2,1,1);
plot(w/pi,20*log(abs(H)));
xlabel('nf');
ylabel('mag in db');
title('mag response');
subplot(2,1,2);
plot(w/pi,angle(H));
xlabel('nf');
ylabel('angle');
title("phase response")
INPUT:
Thus, a MATLAB program for designing FIR low pass filter using various window techniques was
simulated and results were observed.
Ex. No: 10
DESIGN OF CHEBYSHEV’S TYPE I AND TYPE II FILTERS
AIM :
To write and simulate a MATLAB program for designing Chebyshev’s type I and type II filters
i.e., low pass, high Filters.
TOOLS REQUIRED:
6. If any error occurs in the program correct the error and run it again
PROGRAM :
clc;
clear all;
close all;
format long;
rp=input(“Enter pass band ripple:”);
rs = input (“Enter stop band ripple:”);
wp = input (“Enter pass band freq:”);
ws = input (“Enter stop band freq:”);
fs = input (“Enter sampling freq:”);
w1 = 2*(wp/fs);
w2 = 2*(ws/fs);
c = input (‘Select any type’);
switch c
case 1
[n,wn] = cheb1ord (w1,w2,rp,rs,’s’);
[b,a] = cheby1(n,wn,rp,’low’,’s’);
case 2
[n,wn] = cheb1ord (w1,w2,rp,rs,’s’);
[b,a] = cheby1(n,wn,rp,’high’,’s’);
case 3
[n,wn] = cheb2ord (w1,w2,rp,rs,’s’);
[b,a] = cheby2(n,wn,rp,’s’);
case 4
[n,wn] = cheb2ord (w1,w2,rp,rs,’s’);
[b,a] = cheby2(n,wn,rp,’high’,’s’);
end
w = 0: 0.01: pi;
[h,om] = freqs(b,a,w);
m = 20*log 10(abs(h));
an = angle(h);
subplot (2,1,1);
plot (om/pi, m);
grid;
xlabel (‘nf’);
ylabel (‘mag’);
title (‘Magnitude Response’);
subplot (2,1,2);
plot (om/pi, an);
grid;
xlabel (‘nf’);
ylabel (‘angle’);
title (‘phase response’);
INPUT:
Enter pass band ripple: 8
Enter stop band ripple: 30
Enter pass band freq: 389
Enter stop band freq: 732
Enter sampling freq: 4656
Select any type: 1,2,3,4
RESULT:
Thus, a MATLAB program for designing of Chebyshev type-I and type-II filters (low pass, high)
was simulated and results were observed.
CONVERSION OF ANALOG FILTERS INTO DIGITAL FILTERS USING IMPULSE INVARIANT METHOD
AIM :
To write and simulate a matlab program for conversion of analog filters into digital filters using
impulse invariant method
.
TOOLS REQUIRED:
PROGRAM :
clc;
clear all;
close all;
b=[-1,6];
a=[1,-2, -8];
f=5;
[bz,az]=impinvar(b,a,f)
freqz(bz,az,f)
OUTPUT :
bz = -0.2000 0.5488
az = 1.0000 -2.8959 1.4918
RESULT:
Thus, a MATLAB program for conversion of analog filters into digital filters using impulse
invariant method was simulated and results were observed for above parameters.
AIM :
To write and simulate a matlab program for conversion of analog filters into digital filters using
bilinear transformation method.
.
TOOLS REQUIRED:
6. If any error occurs in the program correct the error and run it again
PROGRAM :
clc;
clear all;
close all;
b=[-1 ,5];
a=[2,-4, -7];
f=6;
[bz,az]=bilinear(b,a,f)
freqz(bz,az,f)
OUTPUT :
bz = -0.0300 0.0429 0.0730
AIM :
To write and simulate a matlab program for computation of interpolation and decimation of a sequence
.
.
TOOLS REQUIRED: m
p
M
u
a
t
t
e
r
l
a PROCEDURE:
f 4. Save in current
directory
t
w 5. Compile and Run the
program
a
6. If any error occurs in
r the program correct
e the error and run it
again
RESULT:
Thus, a MATLAB program for computation
of interpolation and decimation of a sequence
was simulated and results were observed for
above parameters.