young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
Signals And Systems Lab Manual, R18 Batch
1. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 1SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
SHADAN COLLEGE OF ENGINEERING AND
TECHNOLOGY
DEPARTMENT OF
ELECTRONICS AND COMMUNICATION ENGINEERING
SIGNALS AND SYSTEMS
LAB MANUAL
Proposed By: Amairullah Khan Lodhi
Associate Professor, ECE Department
2. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 2SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
DEPARTMENT OF
ELECTRONICS AND COMMUNICATION ENGINEERING
SIGNALS AND SYSTEMS LAB
LIST OF EXPERIMENTS PAGE NO.
1. Frequency Spectrum of continuous signal 10
2. Frequency Spectrum of Impulse signal (Time bounded signals) 12
3. Frequency Response Analysis using any software 15
4. Frequency Response Analysis for Transfer Function 20
(Preferably Transformer)
5. Write a program to generate discrete sequences 26
i. Unit step
ii. Unit impulse
iii. Ramp
iv. Periodic sinusoidal sequences
(Plot all the sequences) 27
6. Find the Fourier Transform of a square pulse
(Plot its Amplitude and Phase spectrum)
7. Write a program to convolve two discrete time sequences
(plot all the sequences) Verify the result by analytical calculations 30
8. Write a program to find the trigonometric Fourier series coefficients of
a rectangular periodic signal Reconstruct the signal by combining the Fourier
series coefficients with appropriate weightings.
9. Write a program to find the trigonometric Fourier series coefficients of 35
a rectangular periodic signal plot the discrete signal of spectrum.
10. Generate a discrete Time sequence by sampling continuous Time signal 38
show that with sampling rate less than Nyquist rate aliasing occurs while
reconstructing the signal.
11. Write a program to find the magnitude and phase response of first order low 43
pass high pass filter plot the response in logarithmic scale
3. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 3SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
12. Write a program to find the response of a Low pass & High Pass filter when 45
a speech signal is pass through these filters
4. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 4SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
INTRODUCTION TO MATLAB
MATLAB is a software package for high performance numerical computation and
visualization provides an interactive environment with hundreds of built in functions for technical
computation, graphics and animation. The MATLAB name stands for MATrix Laboratory.
At its core ,MATLAB is essentially a set (a “toolbox”) of routines (called “m files” or “mex
files”) that sit on your computer and a window that allows you to create new variables with names
(e.g. voltage and time) and process those variables with any of those routines (e.g. plot voltage
against time, find the largest voltage, etc).
5. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 5SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
It also allows you to put a list of your processing requests together in a file and save that
combined list with a name so that you can run all of those commands in the same order at some
later time. Furthermore, it allows you to run such lists of commands such that you pass in data
and/or get data back out (i.e. the list of commands is like a function in most programming
languages). Once you save a function, it becomes part of your toolbox (i.e. it now looks to you as
if it were part of the basic toolbox that you started with). For those with computer programming
backgrounds: Note that MATLAB runs as an interpretive language (like the old BASIC). That is,
it does not need to be compiled. It simply reads through each line of the function, executes it, and
then goes on to the next line. (In practice, a form of compilation occurs when you first run a
function, so that it can run faster the next time you run it.)
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, charcter strings, structures and cells.There
6. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 6SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
is no need to declare variables as real or complex, MATLAB automatically sets the variable to be
real.
Dimensioning: Dimensioning is automatic in MATLAB. No dimension statements are
required for vectors or arrays .we can find the dimensions of an existing matrix or a vector with
the size and length commands.
Where to work in MATLAB? All programs and commands can be entered either in the
a)Command window b) As an M file using Matlab editor Note: Save all M files in the folder
'work' in the current directory. Otherwise you have to locate the file during compiling. Typing
quit in the command prompt>> quit, will close MATLAB Matlab Development Environment. For
any clarification regarding plot etc, which are built in functions type help topic i.e. help plot.
Basic Instructions in Mat lab
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)
zero
The above instruction creates a vector of one row and three columns whose values are
Output= [0 0 0]
5. zeros( 2,4)
7. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 7SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
Output = 0 0 0 0
6. ones (5,2)
The above instruction creates a vector of five rows and two columns
Output = 1 1 1 1 1 1 1 1 1 1 7.
a = [ 1 2 3]
b = [4 5 6]
a.*b = [4 10 18]
8 . if C= [2 2 2]
b.*C results in [8 10 12]
9. plot (t, x)
If x = [6 7 8 9]
t = [1 2 3 4]
This instruction will display a figure window which indicates the plot of x versus t
10. stem (t,x) :- This instruction will display a figure window as shown
8. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 7SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
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
Subplot (3 1 2) divides the figure window into 3 rows and 1 column 2 represent number of the
figure.
12. Conv Syntax: w = conv(u,v) Description: w = conv(u,v) convolves vectors u and v.
Algebraically, convolution is the same operation as multiplying the polynomials whose
coefficients are the elements of u and v.
13.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.
9. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 8SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
14.xlabel Syntax: xlabel('string') Description: xlabel('string') labels the x-axis of the current axes.
15.. ylabel Syntax : ylabel('string')
Description: ylabel('string') labels the y-axis of the current axes.
16.Title Syntax : title('string') Description: title('string') outputs the string at the top and in the
center of the current axes.
17. Grid on Syntax : grid on Description: grid on adds major grid lines to the current axes.
18. 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-D arrays, the FFT operation
operates on the first non-singleton dimension. FFT(X,N) is the N-point FFT, padded with zeros if
X has less than N points and truncated if it has more.
19. ABS Absolute value. ABS(X) is the absolute value of the elements of X. When X is complex,
ABS(X) is the complex modulus (magnitude) of the elements of X.
20. ANGLE Phase angle. ANGLE(H) returns the phase angles, in radians, of a matrix with
complex elements.
21.INTERP Resample data at a higher rate using lowpass interpolation.
Y = INTERP(X,L) resamples the sequence in vector X at L times the original sample rate. The
resulting resampled vector Y is L times longer, LENGTH(Y) = L*LENGTH(X).
22. DECIMATE Resample data at a lower rate after lowpass filtering.
10. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 9SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
Y = DECIMATE(X,M) resamples the sequence in vector X at 1/M times the original sample
rate. The resulting resampled vector Y is M times shorter, i.e., LENGTH(Y) =
CEIL(LENGTH(X)/M). By default, DECIMATE filters the data with an 8th order.
11. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 10SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
1. FrequencySpectrum of continuous Signal
AIM: - To generate basic signals like unit impulse , ramp, exponential.
Tools required: Matlab tools,
Matlab version:R2009b,
Operating system: Windows XP.
PROGRAM:-
clc;
clear all;
close all;
% Impulse Sequence
t=-2:1:2;
y1=[zeros(1,2) 1 zeros(1,2)];
subplot(2,2,1);
stem(t,y1);grid;
title('impulse response');
xlabel('no of samples');
ylabel('--> amplitude');
% Exponential Sequence
n = input('enter length of the exponential sequence');
t =0:1:n;
a=input('enter "a" value:');
y2=exp(a*t);
subplot(2,2,2);
stem(t,y2);
grid;
title('exponential sequence');
xlabel('no of samples:n-->');
ylabel('--> amplitude');
% Step Sequence
s=input('enter the length of the step sequence:');
12. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 11SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
t=-s:1:s;
y3=[zeros(1,s) ones(1,1) ones(1,s)];
13. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 12SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
subplot(2,2,3);
stem(t,y3);
title('step response');
xlabel('no of samples:n-->');
ylabel('--> amplitude');
% Ramp Sequence
X=input('enter the length of the ramp sequence:');
t=0:X;
subplot(2,2,4);
stem(t,t);
title('ramp response');
xlabel('no of samples:n-->');
ylabel('--> amplitude');
OUTPUT :-
14. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 13SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
RESULT : Basic signals like unit impulse, ramp, exponential are generated.
15. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 14SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
2. Frequency Spectrum of Impulse signal (Time bounded signals)
AIM: To find the DFT of a sequence.
Tools required: Matlab tools, Matlab version:R2009b, Operating system: Windows XP.
PROGRAM:
clc;
clear all;
close all;
a=input('enter the sequence:');
N=length(a);
disp(' the length of the sequence is:');N
for k=1:N
y(k) = 0;
for2
y(k)=y(k)+a(i)*exp((-2*pi*j/N)*((i-1)*(k-1)));
end ;
end;
k=1:N
disp('the result is');y
figure(1);
subplot(211);
stem(k,abs(y(k)));
grid;
xlabel('sample values n')
ylabel('amplitude');
title('magnitude response of dft of the given sequence');
subplot(212);
stem(angle(y(k))*180/pi);
grid;
xlabel('sample values n')
ylabel('phase');
16. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 15SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
title('phase response of dft of the given sequence');
17. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 16SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
y(k)=y(k)+a(i)*exp((-2*pi*j/N)*((i-1)*(k-1)));
end ;
end;
k=1:N
disp('the result is');y
figure(1);
subplot(211);
stem(k,abs(y(k)));
grid;
xlabel('sample values n')
ylabel('amplitude');
title('magnitude response of dft of the given sequence');
subplot(212);
stem(angle(y(k))*180/pi);
grid;
xlabel('sample values n')
ylabel('phase');
title('phase response of dft of the given sequence');
OUTPUTS:
enter the sequence:[1 2 3 4]
the length of the sequence is:
N =
4
k =
1 2 3 4
DFT of given sequence is:
y =
10.0000 -2.0000 + 2.0000i -2.0000 - 0.0000i -2.0000 - 2.0000i
18. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 17SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
WAVEFORMS:
RESULT:
Hence DFT of the given sequence is computed.
19. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 18SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
3.Frequency Response using Any Software
AIM: To find the IDFT of a sequence
Tools required: Matlab tools, Matlab version:R2009b, Operating system: Windows XP.
PROGRAM:
clc;
clear all;
close all;
a=input('enter the sequence:');
N=length(a);
disp('the length of the seq is');N
for n=1:N
y(n)=0;
for k=1:N
y(n)=y(n)+a(k)*exp((2*pi*j*(k-1)*(n-1))/N);
end;
end;
n=1:N
y1=1/N*y(n);
disp('the result is');y1
figure(1);
stem(n,y1);
grid;
xlabel('sample values n-->');
ylabel('amplitude-->');
title('magnitude response of the IDFT of a given DFT');
20. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 19SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
OUTPUTS:
enter the sequence:[1 0 1 0]
the length of the seq is
N =
4
n =
1 2 3 4
IDFT of INPUT sequence is:
y1 =
0.5000 0 + 0.0000i 0.5000 - 0.0000i 0 + 0.0000i
WAVEFORMS:
RESULT:
Hence IDFT of the given sequence is computed.
21. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 20SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
4. Frequency Response Analysis for any Transfer Function
Aim :- To find the impulse response of the following difference equation
y(n)-y(n-1)+0.9y(n-2)= x(n)
Tools required: Matlab tools, Matlab version:R2009b, Operating system: Windows XP.
Program:
clc;
clear all;
close all;
disp('difference eqyation of a digital system');
N= input('desired impulse response length=');
b=input('coefficients of x[n]terms=');
a=input('coefficients of y[n]terms=');
h=impz(b,a,N);
disp('impulse response of the system is h=');
disp(h);
n=0:1:N-1;
figure(1);
stem(n,h);
xlabel('time index');
ylabel('h[n]');
title('impulse response');
figure(2);
zplane(b,a);
xlabel('real part');
ylabel('imaginary part');
title('poles and zeros of h[z] in z-plane');
22. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 21SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
OUTPUT:
difference equation of a digital system
desired impulse response length=10
coefficients of x[n]terms=[1]
coefficients of y[n]terms=[1 -1 0.9]
impulse response of the system is h=
1.0000
1.0000
0.1000
-0.8000
-0.8900
-0.1700
0.6310
0.7840
0.2161
-0.4895
WAVEFORM:
23. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 22SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
RESULT:
is computed.
Hence Impulse response of a system given in Difference equation form
24. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 23SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
. 4. Frequency Response Analysis for Transfer Function
(Preferably Transformer)
Tools required: Matlab tools, Matlab version:R2009b, Operating system: Windows XP.
Program:
clc;
clear all;
close all;
b=[1 4];
a=[1 -5];
w=-2*pi:pi/256:2*pi;
[h]=freqz(b,a,w);
subplot(2,1,1);
plot(w,abs(h));
xlabel('frequency');
ylabel('magnitude');
grid;
subplot(2,1,2);
plot(w,angle(h));
xlabel('frequency');
ylabel('phase');
grid;
25. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 24SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
OUTPUT:-
RESULT:
is computed.
Hence Frequency response of a system given in Difference equation form
26. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 25SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
5. Write a program to generate discrete sequences
i. Unit step ,Unit impulse ,Ramp, Periodic sinusoidal sequences
Aim :- To find the FFT of a Given Sequence.
Tools required: Matlab tools, Matlab version:R2009b, Operating system: Windows XP.
Program:
clc;
close all;
clear all;
xn= input('Enter the input sequence'); % input sequence
L=length(xn);
N=input('Enter Lenth/Size of DFT:');
% checking for the length of the DFT
if (N<L)
error('N must be >=L');
end
xn=[xn zeros(1,N-L)]; % appending zeros
Xk=fft(xn,N)
k=0:1:N-1;
Subplot(2,1,1);
stem(k,abs(Xk));
xlabel('k');
ylabel('Magnitude |X(K)|');
subplot (2,1,2);
stem(k,angle(Xk));
xlabel ('k');ylabel('angle of (x(k))');
title('phase');
27. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 26SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
OUTPUT:
Enter the input sequence[0 1 2 3]
Enter Lenth/Size of DFT:4
6.0000 -2.0000 + 2.0000i -2.0000 -2.0000 - 2.0000i
RESULT:
Hence FFT of a given sequence is computed.
28. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 27SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
6. Find the Fourier Transform of a square pulse
(Plot its Amplitude and Phase spectrum)
Aim :- To find the FFT of a Given Sequence.
Tools required: Matlab tools, Matlab version:R2009b, Operating system: Windows XP.
Program:
clc;
close all;
clear all;
xk= input('Enter the input sequence'); % input sequence
N=input('Enter Lenth/Size of DFT:');
xn=ifft(xk,N);
disp('the ifft of input sequence is xn');
disp('xn');
n=0:1:N-1;
stem(n,xn);
xlabel('time');
ylabel('amplitude');
title('time domain representation of sequence xn');
OUTPUT:
Enter the input sequence
[6.0000 -2.0000 + 2.0000i -2.0000 -2.0000 - 2.0000i]
Enter Length/Size of DFT:4
0 1 2 3
29. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 28SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
RESULT:
Hence IFFT of a given sequence is computed.
30. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 29SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
5.(a) POWER SPECTRUM DENSITY USING PERIODOGRAM
AIM :- To compute the PSD of given signals periodogram.
Tools required: Matlab tools, Matlab version:R2009b, Operating system: Windows XP.
PROGRAM :-
clc;
clear all;
close all;
Fs=1000;
t=0:1/Fs:0.3
x=cos(2*pi*t*200)+0.1*randn(size(t));
periodogram(x,[],'twosided',512,Fs);
WAVE FORMS :-
RESULT:
Hence the PSD in computed using periodogram and plot the graph.
31. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 30SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
7. Write a program to convolve two discrete time sequences
(plot all the sequences) Verify the result
by analytical calculations
AIM: To compute the Power Spectral Density of given signal using Square magnitude and Auto
correlation
Tools required: Matlab tools, Matlab version:R2009b, Operating system: Windows XP.
PROGRAM:
clc;
clear all;
close all;
f1=input('enter the frequency of first sequence in Hz:');
f2=input('enter the frequency of second sequence in Hz:');
fs=input('enter the sample frequency in Hz:');
t=0:1/fs:1;
x=2*sin(2*pi*f1*t)+3*sin(2*pi*f2*t)+rand(size(t));
px1=abs(fft(x).^2);
px2=abs(fft(xcorr(x),length(t)));
subplot(2,1,1);
plot(t*fs,10*log10(px1)); %square magnitude
grid;
xlabel('freq in Hz');
ylabel('magnitude in db');
title('PSD using square magnitude method');
subplot(2,1,2);
plot(t*fs,10*log10(px2)); %autocorrelation
grid;
xlabel('freq in Hz');
ylabel('magnitude in db');
title('PSD using autocorrelation method');
32. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 31SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
INPUTS:
enter the frequency of first sequence in Hz:200
enter the frequency of second sequence in Hz:400
enter the sample frequency in Hz:1000
WAVE FORMS:
RESULT:
Hence PSD is estimated using Square magnitude and autocorrelation.
33. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 32SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
8. Write a program to find the trigonometric Fourier series coefficients of
a rectangularperiodic signalReconstructthe signalby combining the
Fourier series coefficients with appropriate weightings.
Aim :- To Design FIR LP Filter using Rectangular/Triangular/kaiser Windowing Technique.
Apparatus Used:- System with MATLAB 7.8 R2009a.
Algorithm:-
1) Enter the pass band ripple (rp) and stop band ripple (rs).
2) Enter the pass band frequency (fp) and stop band frequency (fs).
3) Get the sampling frequency (f), beta value.
4) Calculate the analog pass band edge frequencies, w1 and w2. w1 = 2*fp/f w2 = 2*fs/f.
5) Calculate the numerator and denominator.
6) Use an If condition and ask the user to choose either Rectangular Window or Triangular
window or Kaiser Window.
7) Use rectwin, triang, Kaiser Commands.
8) Calculate the magnitude of the frequency response in decibels (dB m=20*log10(abs(h)).
9) Plot the magnitude response [magnitude in dB Vs normalized frequency (om/pi)]
10) Give relevant names to x and y axes and give an appropriate title for the plot.
11) Plot all the responses in a single figure window.[Make use of subplot]
Procedure:-
1) Open MATLAB
2) Open new M-file
3) Type the program
4) Save in current directory
5) Compile and Run the program
6) For the output see command window Figure window
Program:-
%FIR Filter design window techniques
clc;
clear all;
close all;
rp=input('enter passband ripple');
rs=input('enter the stopband ripple');
34. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 33SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
fp=input('enter passband freq');
fs=input('enter stopband freq');
f=input('enter sampling freq ');
beta=input('enter beta value„);
35. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 34SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
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,beta);
disp('kaiser window filter response');
end
%LPF b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
plot(o/pi,m);
title('LPF');
ylabel('Gain in dB-->');
xlabel('(a) Normalized frequency-->');
Output:-
enter passband ripple 0.02
enter the stopband ripple 0.01
enter passband freq 1000
enter stopband freq 1500
enter sampling freq 10000
36. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 35SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
enter beta value
enter your choice of window function 1. rectangular 2. triangular 3.kaiser:
1
Rectangular window filter response
37. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 36SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
enter your choice of window function 1. rectangular 2. triangular 3.kaiser:
2
triangular window filter response
enter beta value 5
enter your choice of window function 1. rectangular 2. triangular 3.kaiser:
38. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 37SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
3
kaiser window filter response
Result:- Thus FIR LP Filter is designed for Rectangular/triangular/kaiser windowing techniques
using MATLAB.
39. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 38SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
9. Write a program to find the trigonometric Fourier series coefficients of
a rectangular periodic signal plot the discrete signal of spectrum.
Aim :- To Design FIR HP Filter using Rectangular/Triangular/kaiser Windowing Technique.
Apparatus Used:- System with MATLAB 7.8 (R2009a).
Algorithm:-
1. Enter the pass band ripple (rp) and stop band ripple (rs).
2. Enter the pass band frequency (fp) and stop band frequency (fs).
3. Get the sampling frequency (f), beta value.
4. Calculate the analog pass band edge frequencies, w1 and w2. w1 = 2*fp/f w2 = 2*fs/f
5. Calculate the numerator and denominator
6. Use an If condition and ask the user to choose either Rectangular Window or Triangular
window or Kaiser Window.
7. Use rectwin,triang,kaiser commands
8. Calculate the magnitude of the frequency response in decibels (dB m=20*log10(abs(h))
9. Plot the magnitude response [magnitude in dB Vs normalized frequency (om/pi)]
10. Give relevant names to x and y axes and give an appropriate title for the plot.
11. Plot all the responses in a single figure window.[Make use of subplot]
Procedure:-
1. Open MATLAB
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. For the output see command window Figure window.
Program:-
%FIR Filter design window techniques
clc;
clear all;
close all;
rp=input('enter passband ripple');
rs=input('enter the stopband ripple');
40. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 39SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
fp=input('enter passband freq');
fs=input('enter stopband freq');
41. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 40SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
f=input('enter sampling freq ');
beta=input('enter beta value');
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,beta);
disp('kaiser window filter response');
end
%HPF b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
plot(o/pi,m);
title('HPF');
ylabel('Gain in dB-->');
xlabel('(b) Normalized frequency-->');
Output:-
enter passband ripple 0.02
enter the stopband ripple 0.01
enter passband freq 1000
enter stopband freq 1500
enter sampling freq 10000
enter beta value
42. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 41SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
enter your choice of window function 1. rectangular 2. triangular 3.kaiser:
1
Rectangular window filter response
enter your choice of window function 1. rectangular 2. triangular 3.kaiser:
2
triangular window filter response
43. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 42SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
enter beta value 5
enter your choice of window function 1. rectangular 2. triangular 3.kaiser:
3
kaiser window filter response
Result:- Thus FIR HP Filter is designed for Rectangular/triangular/kaiser windowing techniques
using MATLAB.
44. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 43SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
10. Generate a discrete Time sequence by sampling continuous Time signal
show that with sampling rate less than Nyquist rate aliasing occurs while
reconstructing the signal.
Aim: -To Design and generate IIR Butterworth Analog LP Filter using MATLAB
Apparatus Required:- System with MATLAB 7.8 R2009a.
Algorithm:-
1. Enter the pass band ripple (rp) and stop band ripple (rs).
2. Enter the pass band frequency (fp) and stop band frequency (fs).
3. Get the sampling frequency (f).
4. Calculate the analog pass band edge frequencies, w1 and w2. w1 = 2*fp/f w2 = 2*fs/f
5. Calculate the order and 3dB cutoff frequency of the analog filter. [Make use of the
following function] [n,wn]=buttord(w1,w2,rp,rs,‟s‟)
6. Design an nth order analog lowpass Butter worth filter using the following statement.
[b,a]=butter(n,wn,‟s‟)
7. Find the complex frequency response of the filter by using „freqs( )‟ function
[h,om]=freqs(b,a,w) where, w = 0:.01:pi This function returns complex frequency
response vector „h‟ and frequency vector „om‟ in radians/samples of the filter.
8. Calculate the magnitude of the frequency response in decibels (dB m=20*log10(abs(h))
9. Plot the magnitude response [magnitude in dB Vs normalized frequency (om/pi)]
10. Calculate the phase response using an = angle(h)
11. Plot the phase response [phase in radians Vs normalized frequency (om/pi)]
12. Give relevant names to x and y axes and give an appropriate title for the plot.
13. Plot all the responses in a single figure window.[Make use of subplot]
Procedure:-
1. Open MATLAB
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
45. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 44SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
6. For the output see command window Figure window
46. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 45SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
Program:-
% IIR filters
clc;
clear all;
close all;
warning off;
disp('enter the IIR filter design specifications');
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
wp=input('enter the passband freq');
ws=input('enter the stopband freq');
fs=input('enter the sampling freq');
w1=2*wp/fs;w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs,'s');
% Find the order n and cutt off frequency disp('Frequency response of IIR HPF is:');
[b,a]=butter(n,wn,'low','s');
% Find the filter co-efficients of LPF w=0:.01:pi;
[h,om]=freqs(b,a,w);
% Plot the frequency response m=20*log10(abs(h));
subplot(2,1,1);
plot(om/pi,m);
title('magnitude response of IIR Low Pass filter is:');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
an=angle(h);
subplot(2,1,2);
plot(om/pi,an);
title('phase response of IIR Low Pass filter is:');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->');
47. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 40SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
Output:- enter the IIR filter design specifications
enter the passband ripple0.15
enter the stopband ripple60
enter the passband freq1500
enter the stopband freq3000
enter the sampling freq7000
Frequency response of IIR LPF is:
Result:- Thus IIR Low Pass Filter is designed using MATLAB.
48. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 41SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
11. Write a program to find the magnitude and phase response of first order
low pass & high pass filter plot the response in logarithmic scale
Aim: -To Design and generate IIR Butterworth Analog HP Filter using MATLAB
Apparatus Required:- System with MATLAB 7.8 R2009a.
Algorithm:-
1. Enter the pass band ripple (rp) and stop band ripple (rs).
2. Enter the pass band frequency (fp) and stop band frequency (fs).
3. Get the sampling frequency (f).
4. Calculate the analog pass band edge frequencies, w1 and w2. w1 = 2*fp/f w2 = 2*fs/f
5. Calculate the order and 3dB cutoff frequency of the analog filter. [Make use of the
following function] [n,wn]=buttord(w1,w2,rp,rs,‟s‟)
6. Design an nth order analog high pass Butter worth filter using the following statement.
[b,a]=butter(n,wn,‟high‟,‟s‟)
7. Find the complex frequency response of the filter by using „freqs( )‟ function
[h,om]=freqs(b,a,w) where, w = 0:.01:pi This function returns complex frequency
response vector „h‟ and frequency vector „om‟ in radians/samples of the filter.
8. Calculate the magnitude of the frequency response in decibels (dB m=20*log10(abs(h))
9. Plot the magnitude response [magnitude in dB Vs normalized frequency (om/pi)]
10. Calculate the phase response using an = angle(h)
11. Plot the phase response [phase in radians Vs normalized frequency (om/pi)]
12. Give relevant names to x and y axes and give an appropriate title for the plot.
13. Plot all the responses in a single figure window.[Make use of subplot]
49. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 42SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
Procedure:-
1. Open MATLAB
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. For the output see command window Figure window
50. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 43SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
Program:-
% IIR filters
clc;
clear all;
close all;
warning off;
disp('enter the IIR filter design specifications');
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
wp=input('enter the passband freq');
ws=input('enter the stopband freq');
fs=input('enter the sampling freq');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs,'s');
% Find the order n and cutt off frequency disp('Frequency response of IIR HPF is:');
[b,a]=butter(n,wn,'high','s');
% Find the filter co-efficients of HPF w=0:.01:pi;
[h,om]=freqs(b,a,w);
% Plot the frequency response m=20*log10(abs(h));
subplot(2,1,1);
plot(om/pi,m);
title('magnitude response of IIR High Pass filter is:');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
an=angle(h);
subplot(2,1,2);
plot(om/pi,an);
title('phase response of IIR High Pass filter is:');
xlabel('(b) Normalized freq. -->');
51. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 44SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
ylabel('Phase in radians-->');
Output:-
enter the IIR filter design specifications
enter the passband ripple0.15
enter the stopband ripple60
enter the passband freq1500
enter the stopband freq3000
enter the sampling freq7000
Frequency response of IIR HPF is:
Result:- Thus IIR High Pass Filter is designed using MATLAB.
52. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 45SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
12. Write a program to find the response of a Low pass & High Pass filter
when a speechsignalis pass through these filters
Aim: Implementation of Decimation Process Using “decimate” key word.
Tools required: Matlab tools,
Matlab version:R2009b,
Operating system: Windows XP
Program:
clc;
close all;
clear all;
M = input('enter Down-sampling factor , M = ');
N = input('enter number of samples, N = ');
n = 0:N-1;
x = sin(2*pi*n/50) + sin(2*pi*n/20);
y = decimate(x,M);
subplot(2,1,1);
stem(n,x(1:N));
title('Input Sequence');
xlabel('Time index n');
ylabel('Amplitude');
subplot(2,1,2);
m = 0:(N/M)-1;
stem(m,y(1:N/M));
title('Output Sequence');
xlabel('Time index n');
ylabel('Amplitude');
OUTPUT:
enter Down-sampling factor , M = 2
enter number of samples, N = 50
53. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 46SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY
54. DEPARTMENT OF ECE SIGNALS & SYSTEMS LAB
Page 47SHADAN COLLEGE OF ENGINEERING& TECHNOLOGY