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

Experiment No. - 1: Aim: Software Used: MATLAB Theory

The experiment aims to plot the magnitude and phase spectra of a signal using Fourier transforms in MATLAB. The code defines an exponential signal, takes its FFT, and plots the magnitude spectrum, phase spectrum, and original time domain signal for comparison. Taking the FFT of a signal provides its frequency domain representation in terms of magnitude and phase across different frequencies.

Uploaded by

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

Experiment No. - 1: Aim: Software Used: MATLAB Theory

The experiment aims to plot the magnitude and phase spectra of a signal using Fourier transforms in MATLAB. The code defines an exponential signal, takes its FFT, and plots the magnitude spectrum, phase spectrum, and original time domain signal for comparison. Taking the FFT of a signal provides its frequency domain representation in terms of magnitude and phase across different frequencies.

Uploaded by

Kumar Rajeshwar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Experiment No.

– 1

Aim: Intro to MATLAB & its basic commands.


Software Used: MATLAB
Theory:
MATLAB is used for machine learning, signal processing,
image processing, computer vision, communications,
computational finance, control design, robotics, and
much more.
MATLAB platform is optimized for solving engineering
and scientific problems. The matrix-based MATLAB
language is the world’s most natural way to express
computational mathematics.
MATLAB code can be integrated with other languages,
enabling you to deploy algorithms and applications
within web, enterprise, and production systems.
MATLAB allows matrix manipulations, plotting of
functions and data, implementation of algorithms,
creation of user interfaces, and interfacing with
programs written in other languages.
Primary Commands:
Help: lists all primary help topics in the Command
Window. Each main help topic corresponds to a folder
name on the MATLAB search path.
Help name: displays the help text for the functionality
specified by name, such as a function, method, class,
toolbox or variable.
Plot: Draw a plot, see also figure, axis, subplot.
Print: Print the current plot (to a printer or postscript
file)
Subplot : Divide the plot window up into pieces, see
also plot, figure.
xlabel/ylabel: Add a label to the horizontal/vertical axis
of the current plot, see also title, text, gtext
OUTPUTS :-

Result:
The study of MATLAB and the various commands is
complete.
Experiment No. – 2
Aim: To plot unit step, unit impulse, ramp,exponential
functions & sinusoidal signals.
Software Used: MATLAB
Program:
%Generation of sine wave

t=1:0.01:5;
x=sin(2*pi*t);
subplot(3,2,1);
plot(t,x);
title('sine wave continuous');
xlabel('time');
ylabel('amplitude');

%Generation of sine wave


t=1:0.01:5;
x=sin(2*pi*t);
subplot(3,2,2);
stem(t,x);
title('sine wave discrete');
xlabel('time');
ylabel('amplitude');

%Generation of cos wave


t=0:0.01:5;
x=cos(2*pi*t);
subplot(3,2,3);
plot(t,x);
title('cos wave');
xlabel('time');
ylabel('amplitude');

%Generation of cos wave


t=0:0.01:5;
x=cos(2*pi*t);
subplot(3,2,4);
stem(t,x);
title('cos wave');
xlabel('time');
ylabel('amplitude');
%Generation of Ramp wave
N=input('Enter the value of N:');
n=0:N-1;
r=n;
subplot(3,2,5);
plot(n,r);
title('ramp signal');
xlabel('time');
ylabel('amplitude');

%Generation of Ramp wave


M=input('Enter the value of M:');
n=0:M-1;
r=n;
subplot(3,2,6);
stem(n,r);
title('ramp signal');
xlabel('time');
ylabel('amplitude');

%Generation of Exponential wave


N=input('Enter the value of N');
n=0:N-1;
a=input('Enter the value of a');
xn=a.^n;
subplot(2,2,1);
plot(n,xn);
title('exponential signal continuous');
xlabel('time');
ylabel('amplitude');

%Generation of Exponential wave


m=input('Enter the value of m');
n=0:m-1;
b=input('Enter the value of b');
xn=b.^n;
subplot(2,2,2);
stem(n,xn);
title('discrete exponential signal');
xlabel('time');
ylabel('amplitude');

%Generation of unit step function


t = (-1:0.01:5)';
unitstep = t>=0;
subplot(2,2,3);
plot(t,unitstep);
title('unit step function');
xlabel('time');
ylabel('amplitude');

%Generation of unit impulse


t = (-1:0.01:5)';
impulse = t==0;
subplot(2,2,4);
plot(t,impulse);
title('unit impulse function');
xlabel('time');
ylabel('amplitude');
OUTPUTS:-

Result:
Plotting of unit step, unit impulse, ramp, exponential
functions and sinusoidal signals using MATLAB software
is completed.
Experiment No. – 3
Aim: To plot Convolution of two functions.
Software Used: MATLAB
Theory:
Convolution of two functions mathematically is given
by: -
f(t)=x(t)*h(t)= ∫𝑥(𝜏)ℎ(𝑡−𝜏)𝑑𝜏∞−∞
Program:
%Definition of i/p sequence
x=input('Enter the value of x');
nx=0:1;
subplot(3,1,1);
stem(nx,x);
grid on;
title('Input Sequence');
xlabel('Time');
ylabel('Amplitude');
%Definition of impulse sequence h
h=input('Enter the value of h');
nh=0:2;
subplot(3,1,2);
stem(nh,h);
grid on;
title('Input impulse seq.');
xlabel('Time');
ylabel('Amplitude');

%Convolution of x & h
nyl=nx(1)+nh(1);
nyr=nx(length(x))+nh(length(h));
ny=nyl:nyr;
y=conv(x,h);
subplot(3,1,3);
stem(ny,y);
grid on;
title('output Sequence');
xlabel('Time');
ylabel('Amplitude');

Outputs:-
Result:
Study of convolution of two functions using MATLAB is
finished successfully.
Experiment No. – 4
Aim: To plot auto correlation and cross correlation of two
sequences..

Software Used: MATLAB


Theory:
Cross Correlation: In signal processing, cross-correlation is a measure of
similarity of two series as a function of the displacement of one relative to the
other. This is also known as a sliding dot product or sliding inner-product. It is
commonly used for searching a long signal for a shorter, known feature. It has
applications in pattern recognition, single particle analysis, electron
tomography, averaging, cryptanalysis, and neurophysiology

Auto Correlation: Autocorrelation, also known as serial correlation, is the


correlation of a signal with a delayed copy of itself as a function of delay.
Informally, it is the similarity between observations as a function of the time lag
between them. The analysis of autocorrelation is a mathematical tool for
finding repeating patterns, such as the presence of a periodic signal obscured by
noise, or identifying the missing fundamental frequency in a signal implied by its
harmonic frequencies. It is often used in signal processing for analyzing
functions or series of values, such as time domain signals. Unit root processes,
trend stationary processes, autoregressive processes, and moving average
processes are specific forms of processes with autocorrelation.
Program:
clear all ;
close all ;
clc;
%definition of x
x=[1 2 3 4];
subplot(4,1,1);
stem(x);
xlabel('time');
ylabel('amplitude');
title('Definition of x');
%definition of h
h=[4 3 2 1];
subplot(4,1,2);
stem(h);
title('Definition of h');
xlabel('time');
ylabel('amplitude');
%autocorrelation of x&x
y=xcorr(x,x);
subplot(4,1,3);
stem(y);
title('Autocorrelation');
xlabel('time');
ylabel('amplitude');
%crosscorrelation of x&h
y=xcorr(x,h);
subplot(4,1,4);
stem(y);
title('Crosscorrelation');
xlabel('time');
ylabel('amplitude');
Output:

Result:
Study of auto correlation and cross correlation of two
sequences using MATLAB is finished successfully.
Experiment No. – 5
Aim: Find out the Z transform of a signal.
Software Used: MATLAB
Theory:-
The Z-transform can be defined as either a one-sided or two-sided transform.

Bilateral Z-transform
The bilateral or two-sided Z-transform of a discrete-time signal x[n] is the formal power series X(z)
defined as
Program:
clc;
clear all;
n=0:.1:100;
r=input('enter the r :');
w=pi/4;
y1=r.^(-n);
y2=cos(w*n);
y=y1.*y2;
if (r <1)
subplot(3,1,1);
plot(n,y1);
xlabel('Sample No');
ylabel('amplitude');
title('r^-^n when r<1');
elseif(r==1)
subplot(3,1,1);
plot(n,y1);
xlabel('Sample No');
ylabel('amplitude');
title('r^-^n when r=1');
else
subplot(3,1,1);
plot(n,y1);
xlabel('Sample No');
ylabel('amplitude');
title('r^-^n when r>1');
end
subplot(3,1,2);
plot(n,y2);
xlabel('Sample No');
ylabel('amplitude');
title('cos(wt) when w=pi/4');
subplot(3,1,3);
plot (n,y);
xlabel(' ');
ylabel('amplitude');
title('Real part of z^-^n=r^-^n *cos(wn)');

Output:-
CASE 1: enter the r :0.9
CASE 2 :- enter the r :1

CASE 3:- enter the r :1.1


Experiment No. – 6
Aim: Evaluate the DTFS coefficients of a signal and plot them
Software Used: MATLAB
Code:-
clc;

clear all;
N=17;
n=0:1:5;
x=cos(6*pi*n/N + pi/3);
subplot(2,1,1);
stem(n,x); %Plot discrete function
y= fft(x); %Fourier series function
subplot(2,1,2);
stem(n,real(y));

OUTPUT:-
Experiment No. – 7
Aim: . Plot the spectra of ideally sampled signal w.r.t. sampling of
Discrete time signals.
Software Used: MATLAB
Code:-
clc;
clear;
f = 2000;
T = 1/f;
tmin = 0;
tmax = 5*T; % Plot 5 cycles
dt1 = 1/10000;
dt2 = 1/3000;
t1 = tmin:dt1:tmax;
t2 = tmin:dt2:tmax;
x1 = sin(2*pi*f*t1);
x2 = sin(2*pi*f*t2);
subplot(2,1,1);
stem(t1,x1);
subplot(2,1,2);
stem(t2,x2);

OUTPUT:-
Experiment No. – 8
Aim: Plot the magnitude and phase spectra of a signal using Fourier transforms
Software Used: MATLAB
Code:-
clc;
clear;
close all;
A=2;
a=4;
fs=1000; % Sampling frequency
t=0:1/fs:1; %Time
x=A*exp(-a.*t); %Signal
plot(t,x); %Plotting the time domain signal
xlabel('t');
ylabel('x(t)');
title('Time domain Signal')
N=length(x);
N1=2^nextpow2(N);
X=fft(x,N1);
X=X(1:N1/2); %Discard Half of Points
X_mag=abs(X); %Magnitude Spectrum
X_phase=phase(X); %Phase Spectrum
f=fs*(0:N1/2-1)/N1; %Frequency axis
figure
plot(f,(X_mag/N1)); %Plotting the Magnitude Spectrum after Normalization
xlabel('Frequency (Hz)');
ylabel('Magnitude Spectrum');
title('Magnitude Spectrum vs f');
figure
plot(f,X_phase); %Plotting the frequency domain
xlabel('Frequency (Hz)');
ylabel('Phase Spectrum');
title('Phase Spectrum vs f');

OUTPUT:-

You might also like

pFad - Phonifier reborn

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

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


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy