Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Lab Report
A.Y. 2017-2021
Submitted by:
Abhishek Goyal (2017Btechece003)
Department of ECE
Institute of Engineering and Technology (IET)
JK Lakshmipat University Jaipur
Introduction
What is MATLAB?
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. Typical
uses include:
MATLAB is an interactive system whose basic data element is an array that does
not require dimensioning. This allows you to solve many technical computing
problems, especially those with matrix and vector formulations, in a fraction of the
time it would take to write a program in a scalar noninteractive language such as C
or Fortran.
The name MATLAB stands for matrix laboratory. MATLAB was originally written
to provide easy access to matrix software developed by the LINPACK and
EISPACK projects, which together represent the state-of-the-art in software for
matrix computation.
MATLAB has evolved over a period of years with input from many users. In
university environments, it is the standard instructional tool for introductory and
advanced courses in mathematics, engineering, and science. In industry, MATLAB
is the tool of choice for high-productivity research, development, and analysis.
MATLAB features a family of application-specific solutions called toolboxes. Very
important to most users of MATLAB, toolboxes allow you
to learn and apply specialized technology. Toolboxes 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 systems, neural networks, fuzzy logic, wavelets,
simulation, and many others.
The MATLAB System
The MATLAB system consists of five main parts:
This is the set of tools and facilities that you work with as the MATLAB user or
programmer. It includes facilities for managing the variables in your workspace and
importing and exporting data. It also includes tools for developing, managing,
debugging, and profiling M-files, MATLAB's applications.
Handle Graphics.
This is the MATLAB graphics system. It includes high-level commands for two-
dimensional and three-dimensional data visualization, image processing, animation,
and presentation graphics. It also includes low-level commands that allow you to
fully customize the appearance of graphics as well as to build complete Graphical
User Interfaces on your MATLAB applications.
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.
Content
4. Adding and subtracting two given signals. (Continuous as well as Discrete signals)
6. To generate and analyse random sequences with arbitrary distributions, means and
10. To design and simulate IIR Butterworth/Chebyshev digital filters (Low Pass/High
Pass)
Experiment :01
AIM: -
Apparatus: -
(i)MATLAB Software
(ii) PC
Algorithm: -
Program: -
clear all;
close all;
clc;
N=15;
n=-N:1:N;
y=[zeros(1,N),ones(1,1),zeros(1,N)];
subplot(2,1,1);
plot(n,y);
ylabel('amplitude');
xlabel('time--->');
title('continuous unit impulse
signal');
display(y);
subplot(2,1,2);
stem(n,y);
ylabel('amplitude');
xlabel('number of samples--->');
title('discrete unit impulse signal');
display(y);
Unit Step Signal:
clear all;
close all;
clc;
N=20;
n=0:1:N-1;
y=ones(1,N);
subplot(2,1,1);
plot(n,y);
ylabel('amplitude');
xlabel('time--->');
title('continuous unit step signal');
display(y);
subplot(2,1,2);
stem(n,y);
ylabel('amplitude');
xlabel('number of samples--->');
title('discrete unit step signal');
display(y);
Periodic Waveforms:
fs = 10000;
t = 0:1/fs:1.5;
x1 = sawtooth(2*pi*50*t);
x2 = square(2*pi*50*t);
subplot(2,1,1)
plot(t,x1)
axis([0 0.2 -1.2 1.2])
xlabel('Time (sec)')
ylabel('Amplitude')
title('Sawtooth Periodic Wave')
subplot(2,1,2)
plot(t,x2)
axis([0 0.2 -1.2 1.2])
xlabel('Time (sec)')
ylabel('Amplitude')
title('Square Periodic Wave')
Aperiodic Waveforms:
fs = 10000;
t = -1:1/fs:1;
x1 = tripuls(t,20e-3);
x2 = rectpuls(t,20e-3);
subplot(2,1,1)
plot(t,x1)
axis([-0.1 0.1 -0.2 1.2])
xlabel('Time (sec)')
ylabel('Amplitude')
title('Triangular Aperiodic
Pulse')
subplot(2,1,2)
plot(t,x2)
axis([-0.1 0.1 -0.2 1.2])
xlabel('Time (sec)')
ylabel('Amplitude')
title('Rectangular Aperiodic
Pulse')
omega = 377;
t = (0:0.01:(6*pi))/omega;
v = 5.6576*cos(omega*t+44.9945)
v1 = 10*cos(omega*t)
figure
h = plot(t,v,t,v1)
legend(h,{'v','v1'})
RESULT:
The basic sequences of Unit impulse, Unit step, Periodic, Aperiodic Sine Sequence & Cosine
Sequence are generated using MATLAB Programs.
Experiment :02
AIM: -
Apparatus: -
(i)MATLAB Software
(ii) PC
Algorithm: -
1) Generate the signals using corresponding general formula.
2) Plot the graph.
Program: -
1. Exponential Signal: -
Source Code:-
Graphs:-
2. Ramp Signal: -
Source Code:-
Output:-
Result:-
The basic sequences of Ramp Signal and Exponential Signal in MATLAB Programs.
Experiment :03
AIM: -
Apparatus: -
(i)MATLAB Software
(ii) PC
Algorithm: -
1) Generate the signals using corresponding general formula.
2) Plot the graph.
Program: -
clc;
clear all;
%define analog signal for comparison
t=-100:01:100;
fm=0.02;
x=cos(2*pi*t*fm);
subplot(2,2,1);
plot(t,x);
xlabel('time in sec');
ylabel('x(t)');
title('continuous time signal');
%simulate condition for undersamplingi.e.,fs1<2*fm
fs1=0.02;
n=-2:2;
x1=cos(2*pi*fm*n/fs1);
subplot(2,2,2);
stem(n,x1);
hold on
subplot(2,2,2);
plot(n,x1,':');
title('discrete time signal x(n) with fs<2fm');
xlabel('n');
ylabel('x(n)');
%condition for Nyquist plot
fs2=0.04;
n1=-4:4;
x2=cos(2*pi*fm*n1/fs2);
subplot(2,2,3);
stem(n1,x2);
hold on
subplot(2,2,3);
plot(n1,x2,':');
title('discrete time signal x(n) with fs>2fm');
xlabel('n');
ylabel('x(n)');
%condition for oversampling
n2=-50:50;
fs3=0.5;
x3=cos(2*pi*fm*n2/fs3);
subplot(2,2,4);
stem(n2,x3);
hold on
subplot(2,2,4);
plot(n2,x3,':');
xlabel('n');
ylabel('x(n)');
title('discrete time signal x(n) with fs=2fm');
Graphs:
Result:-
The basic sequences of Sampling Theorem in MATLAB Programs.
Experiment :04
AIM: -
Adding and subtracting two given signals. (Continuous as well as Discrete signals)
Apparatus: -
(i)MATLAB Software
(ii) PC
Algorithm: -
1) Generate the signals using corresponding general formula.
2) Plot the graph.
Program: -
1. Addition of Signals: -
Source Code:-
n=input('Enter the Duration of signal=');
t=0:1:n-1;
A=t+2;
b=t;
c=A+b;
subplot(2,2,1);
plot(t,c);
xlabel('Signal 1');
ylabel('Signal 2');
title('Addition of two signal');
subplot(2,2,2);
stem(t,c);
xlabel('Signal 1');
ylabel('Signal 2');
title('Addition Of Signals');
Output:
Enter the Duration of signal= 6
Graphs:-
1. Subtraction of Signals: -
Source Code:-
n=input('Enter the Duration of signal=');
t=0:1:n-1;
A=t+2;
b=t;
c=A-b;
subplot(2,2,1);
plot(t,c);
xlabel('Signal 1');
ylabel('Signal 2');
title('Subtraction of two signal');
subplot(2,2,2);
stem(t,c);
xlabel('Signal 1');
ylabel('Signal 2');
title('Subtraction Of Signals');
Output:
Output:
Enter the Duration of signal= 8
Graphs:-
Result:-
The basic sequences of Adding and subtracting two given signals. (Continuous as well as
Discrete signals) in MATLAB Programs.
Experiment :05
AIM: -
Apparatus: -
(i)MATLAB Software
(ii) PC
Algorithm: -
Program: -
Linear Convolution:
clc;
clear all;
close all;
x=input('Enter the input sequence x[n]= ');
lx=input('Enter the starting time index of x[n] =');
h=input('Enter the impulse response h[n]= ');
lh=input('Enter the starting time index of h[n] =');
y=conv(x,h);
n=lx+lh:length(y)+lx+lh-1;
stem(n,y);
ylabel('amplitude');
xlabel('time index');
title('Linear convolution output');
Output:
x3=zeros(1,N);
for m=0:N-1
x3(m+1)=0;
for n=0:N-1
j=mod(m-n,N);
x3(m+1)=x3(m+1)+x4(n+1).*x5(j+1);
end
end
subplot(4,1,1)
stem(x1);
title('First Input Sequence');
xlabel('Samples');
ylabel('Amplitude');
subplot(4,1,2)
stem(x2);
title('Second Input Sequence');
xlabel('Samples');
ylabel('Amplitude');
subplot(4,1,3)
stem(x3);
title('Circular Convolution Using Operator');
xlabel('Samples');
ylabel('Amplitude');
%In built function
y=cconv(x1,x2,N);
subplot(4,1,4)
stem(y);
title('Circular Convolution using Function');
xlabel('Samples');
ylabel('Amplitude');
Output:
Result:
Output waveform is observed by using MATLAB for Convolution
Experiment :06
AIM: -
To generate and analyse random sequences with arbitrary distributions, means and
• Rayleigh distribution
Apparatus: -
(i)MATLAB Software
(ii) PC
Algorithm: -
Program: -
Rayleigh distribution:
clc;
close all;
clear all;
sig=1; %RMS value of received voltage signal
r = 0:0.1:10; %the range of value of 'r'
pdf=(r/sig.^2) .* exp(-r.^2/2*(sig.^2)); % the Rayleigh PDF
figure;
plot(r,pdf,'b') %Plotting the Rayleigh PDF
title('Rayleigh PDF Plot');
xlabel('r');
ylabel('p(r)');
cdf=1-exp(-r.^2/(2*1)); % the Rayleigh CDF
figure;
plot(r,cdf,'b') %Plotting the Rayleigh PDF
title('Rayleigh CDF Plot');
xlabel('r');
ylabel('P(r)');
mean=1.2533*sig; %mean of the Rayleigh distribution
varr=0.4292*(sig^2); %variance of the Rayleigh distribution
median=1.177*sig; %median of the Rayleigh PDF
Output:
pd = makedist('Normal')
x = -3:.1:3;
p = cdf(pd,x);
plot(x,p)
Output:-
Gaussian distribution (Mx, σx2):
x = 0:0.1:10;
y = gaussmf(x,[2 5]);
plot(x,y)
xlabel('gaussmf, P=[2 5]')
Output:
Result:
Output waveform is observed by using MATLAB for all of the Distribution.
Experiment :07
AIM: -
Apparatus: -
(i)MATLAB Software
(ii) PC
Algorithm: -
Program: -
clear all;
N=8;
m=8;
a=input('Enter the input sequence');
n=0:1:N-1;
subplot(2,2,1);
stem(n,a);
xlabel('Time Indexn');
ylabel('Amplitude');
title('Sequence');
x=fft(a,m);
k=0:1:N-1;
subplot(2,2,2);
stem(k,abs(x));
ylabel('magnitude');
xlabel('Frequency Index K');
title('Magnitude of the DFT sample');
subplot(2,2,3);
stem(k,angle(x));
xlabel('Frequency Index K');
ylabel('Phase');
title('Phase of DFT sample');
ylabel('Convolution');
Output:
Result:-
AIM: -
Apparatus: -
(i)MATLAB Software
(ii) PC
Algorithm: -
Program: -
clc;
clear all;
close all;
t=0: .2:10;
x1=(4/pi)*sin(t);
subplot(2,2,1);
plot(t,x1);
title('4/pi sint');
x2=(4/pi)*1/3*sin(3*t);
xa=x1+x2;
subplot(2,2,2);
plot(t,xa);
title('(4/pi)sint+(4/3pi)sin3t');
x3=(4/pi)*1/5*sin(5*t);
xb=x1+x2+x3;
subplot(2,2,3);
plot(t,xb);
title('(4/pi)sint+(4/3pi)sin3t+(4/5pi)sin5t');
x4=4/pi*1/7*sin(7*t);
xc=x1+x2+x3+x4;
subplot(2,2,4);
plot(t,xc);
title('(4/pi)sint+(4/3pi)sin3t+(4/5pi)sin5t+(4/7pi)sin7t');
Graphs:-
Results:-
AIM: -
Apparatus: -
(i)MATLAB Software
(ii) PC
Algorithm: -
Program: -
clc;
clear all;
close all;
b = [1, 4]; %Numerator coefficients
A = [1, -5]; %Denominator coefficients
w = -2*pi: pi/256: 2*pi;
[h] = freqz(b, A, w);
subplot(2, 1, 1), plot(w, abs(h));
xlabel('Frequency \omega'), ylabel('Magnitude'); grid
subplot(2, 1, 2), plot(w, angle(h));
xlabel('Frequency \omega'), ylabel('Phase - Radians'); grid
Graphs:
Result:
The basic sequences of Compute Frequency response of Analog filters in MATLAB
Programs.
Experiment :10
Aim: -
To Design and generate IIR Butterworth/ Chebyshev LP/HP Filter using MATLAB
Apparatus Required: -
(i)MATLAB Software
(ii) PC
Theory:
The Digital Filter Design problem involves the determination of a set of filter
coefficients to meet a set of design specifications. These specifications typically
consist of the width of the passband and the corresponding gain, the width of the
stopband(s) and the attenuation therein; the band edge frequencies (which give an
indication of the transition band) and the peak ripple tolerable in the passband and
stopband(s).
Filter Types:
Butterworth Filters
Butterworth filters are causal in nature and of various orders, the lowest order
being the best (shortest) in the time domain, and the higher orders being better in the
frequency domain. Butterworth or maximally flat filters have a monotonic amplitude
frequency response which is maximally flat at zero frequency response and the
amplitude frequency response decreases logarithmically with increasing frequency.
Chebyshev Filters
Chebyshev filters are equiripple in either the passband or stopband. Hence the
magnitude response oscillates between the permitted minimum and maximum values
in the band a number of times depending upon the order of filters. There are two types
of Chebyshev filters. The Chebyshev I filter is equiripple in passband and monotonic in
the stopband, whereas Chebyshev II is just the opposite.
Algorithm:
1) Enter the pass band ripple (rp) and stop band ripple (rs).
2) Enter the pass band frequency (wp) and stop band frequency (ws).
3) Get the sampling frequency (fs)
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;%normalized pass band frequency
w2=2*ws/fs;%normalized stop band frequency
[n,wn]=buttord(w1,w2,rp,rs);
% Find the order n and cutofffrequency
ch=input('give type of filter 1:LPF,2:HPF');
switch ch
case 1
disp('Frequency response of Butterworth IIR LPF is:');
[b,a]=butter(n,wn); % Find the filter coefficient of LPF
[H,w]=freqz(b,a,512,fs);% to get the transfer functionof the filter
mag=20*log10(abs(H));
phase=angle(H);
subplot(211);
plot(w,mag);grid on;
ylabel('--> Magnitude in dB');
xlabel('--> Normalized frequency in Hz');
title('Magnitude Response of the desired ButterworhLPF');
subplot(212);
plot(w,phase);grid on;
ylabel('--> Phase in radians');
xlabel('--> Normalized frequency in Hz');
title('Phase Response of the desired Butterworh LPF');
case 2
disp('Frequency response of IIR Butterworth HPF is:');
[b,a]=butter(n,wn,'high'); % Find the filter coefficients
of HPF
[H,w]=freqz(b,a,512,fs);% to get the transfer function
of the filter
mag=20*log10(abs(H));
phase=angle(H);
subplot(211);
plot(w,mag);grid on;
ylabel('--> Magnitude in dB');
xlabel('--> Normalized frequency in Hz');
title('Magnitude Response of the desired Butterworth');
subplot(212);
plot(w,phase);grid on;
ylabel('--> Phase in radians');
xlabel('--> Normalized frequency in Hz');
title('Phase Response of the desired Butterworth HPF');
end
Results:
Result:
By this experiment we have studied the LP/HP IIR digital filter designing.