Experiment No :- 01
Experiment Name :- Plotting a Sine Wave in MATLAB
Objective :
To generate and plot a sine wave using MATLAB and understand the effect of amplitude,
frequency, and phase shift on the waveform.
Theory :
The mathematical equation for a sine wave is:
𝑦(𝑡) = 𝐴𝑠𝑖𝑛(2𝜋𝑓𝑛 + 𝜙)
where :
A = Amplitude
f = Frequency (Hz)
ϕ = Phase shift (radians)
n= Time (seconds)
MATLAB Code :
clc;
clear all;
close all;
n = 0:20;
A = 1;
f = 0.1;
phi = 0;
y = A * sin(2*pi*f*n + phi);
stem(n, y)
ylim([-2 2])
xlabel('Time (s)')
ylabel('Amplitude')
title('Sine Wave')
grid on
Results :
Experiment No :- 02
Experiment Name :- Plotting a Cosine Wave in MATLAB
Objective :
To generate and plot a sine wave using MATLAB and understand the effect of amplitude,
frequency, and phase shift on the waveform.
Theory :
A cosine wave is mathematically defined as:
𝑦(𝑡) = 𝐴𝑐𝑜𝑠(2𝜋𝑓n + 𝜙)
where :
A = Amplitude,f = Frequency (Hz),ϕ = Phase shift (radians),n= Time (seconds).
Cosine waves are periodic and have the same shape as sine waves but are shifted in phase
by π/2 radians (90 degrees)
MATLAB Code :
clc;
clear all;
close all;
n = 0:20;
A = 1;
f = 0.1;
phi = 0;
y = A * cos(2*pi*f*n + phi);
stem(n, y)
ylim([-2 2])
xlabel('Time (s)')
ylabel('Amplitude')
title('cos Wave')
grid on;
Results :
Experiment No :- 03
Experiment Name :- Plotting a Sawtooth Wave in MATLAB
Objective :
To generate and plot a sawtooth wave in MATLAB and analyze its behavior with varying
frequency and amplitude.
Theory :
A sawtooth wave is a type of non-sinusoidal waveform that rises (or falls) linearly and then
sharply drops (or rises) at regular intervals. It's commonly used in signal processing and
waveform [Link] sawtooth wave can be generated in MATLAB using the sawtooth()
function : 𝑦(𝑡) = 𝐴 ⋅ 𝑠𝑎𝑤𝑡𝑜𝑜𝑡ℎ(2𝜋𝑓n + 𝜙).
where :
A = Amplitude,f = Frequency (Hz),ϕ = Phase shift (radians),n= Time (seconds).
MATLAB Code :
clc;
clear all;
close all;
n = 0:20;
A = 1;
f = 0.1;
phi = 0;
y = A * sawtooth(2*pi*f*n + phi);
stem(n, y)
ylim([-2 2])
xlabel('Time (s)')
ylabel('Amplitude')
title('sawtooth wave')
grid on;
Results :
Experiment No :- 04
Experiment Name :- Plotting a Square Wave in MATLAB
Objective :
To generate and plot a square wave in MATLAB and observe the effects of amplitude,
frequency, and duty cycle.
Theory :
A square wave is a periodic waveform that alternates between a high and a low value with
equal or specified time intervals. It's used in digital electronics, pulse generators, and signal
[Link] standard square wave equation: 𝑦(𝑡) = 𝐴 ⋅ 𝑠𝑞𝑢𝑎𝑟𝑒(2𝜋𝑓𝑛 + 𝜙).
where :
A = Amplitude,f = Frequency (Hz),ϕ = Phase shift (radians),n = Time (seconds).
MATLAB Code :
clc;
clear all;
close all;
n = 0:20;
A = 1;
f = 0.1;
phi = 0;
y = A * square(2*pi*f*n + phi);
stem(n, y)
ylim([-2 2])
xlabel('Time (s)')
ylabel('Amplitude')
title('square wave')
grid on
Result :
Experiment No :- 05
Experiment Name :- Verification of the Trigonometric Identity 𝑠𝑖𝑛2 𝜃 + 𝑐𝑜𝑠 2 𝜃 = 1
Objective :
To verify the trigonometric identity 𝑠𝑖𝑛2 𝜃 + 𝑐𝑜𝑠 2 𝜃 = 1 by plotting it in MATLAB.
Theory :
The Pythagorean identity states that for any angle θ: 𝑠𝑖𝑛2 𝜃 + 𝑐𝑜𝑠 2 𝜃 = [Link] fundamental
trigonometric relationship holds true for all real values of θ\thetaθ. By plotting the sum of
squares of sine and cosine over an interval, we can visually confirm this identity.
MATLAB CODE :
clc;
clear all;
close all;
n = 0:1:50;
theta = n * 0.1;
y = sin(theta).^2 + cos(theta).^2;
plot(theta, y)
ylim([-1 2])
xlabel('\theta (radians)')
ylabel('sin^2(\theta) + cos^2(\theta)')
title('Verification of sin^2\theta + cos^2\theta = 1')
grid on
Result :
Experiment No : 06
Experiment Name : Plotting and Analysis of sin(θ)×cos(θ) in MATLAB.
Objective :
To compute and plot the function sin(θ)×cos(θ) in MATLAB and observe its behavior over
the interval 0≤θ≤2π.
Theory :
The function is the product of sine and cosine functions: y(θ)=sin(θ)×cos(θ)
This product results in a waveform with a period of π\piπ, oscillating between positive and
negative values, and zeros at multiples of π/2\pi/2π/2.
MATLAB CODE :
clc;
clear all;
close all;
n = 0:1:50;
theta = n * 0.1;
y = sin(theta) .* cos(theta);
stem(n, y)
xlabel('n (sample index)')
ylabel('sin(\theta) \times cos(\theta)')
title('Discrete Sequence: sin(\theta) \times cos(\theta)')
grid on
Result :
Experiment No : 07
Experiment Name : Plotting and Analysis of sin(θ)−cos(θ) in MATLAB.
Objective :
To compute and plot the function sin(θ)−cos(θ) in MATLAB and analyze its waveform
over the range 0≤θ≤2π.
Theory :
The function is defined as: y(θ)=sin(θ)−cos(θ)
It is the difference between sine and cosine waveforms. This results in a shifted sine wave,
which can be represented using the trigonometric identity:
𝑠𝑖𝑛(𝜃) − 𝑐𝑜𝑠(𝜃) = √
The amplitude of the resulting waveform is √ and the phase is shifted by π/4 radians.
MATLAB CODE :
clc;
clear all;
close all;
n = 0:1:50;
theta = n * 0.1;
y = sin(theta) - cos(theta);
stem(theta, y)
xlabel('\theta (radians)')
ylabel('sin(\theta) - cos(\theta)')
title('Plot of sin(\theta) - cos(\theta)')
grid on;
Result :
Experiment No : 08
𝑠𝑖𝑛 2(𝜃)
Experiment Name : Plotting and Analysis of in MATLAB.
𝑐𝑜𝑠2 (𝜃)
Objective :
𝑠𝑖𝑛 2 (𝜃)
To compute and plot the function 𝑐𝑜𝑠2 (𝜃) in MATLAB and observe its behavior over 0≤θ≤2π.
Theory :
𝑠𝑖𝑛 2(𝜃)
The given function is: y(𝜃) = 𝑐𝑜𝑠2 (𝜃) .
Using the trigonometric identity:
𝑠𝑖𝑛 2(𝜃)
= 𝑡𝑎𝑛2 (𝜃)
𝑐𝑜𝑠2 (𝜃)
The function represents the square of the tangent function, which is periodic with period π
and has vertical asymptotes where cos(θ)=0.
MATLAB CODE :
clc;
clear all;
close all;
n = 0:1:50;
theta = n*0.009 ;
y = (sin(theta).^2) ./ (cos(theta).^2);
stem(theta, y)
xlabel('\theta (radians)')
ylabel('sin^2(\theta) / cos^2(\theta)')
title('Plot of sin^2(\theta) / cos^2(\theta)')
grid on;
xlim([0 1]);
Result :
Experiment No : 09
Experiment Name : Convolution of Discrete-Time Signals in MATLAB.
Objective :
To perform the convolution of two discrete-time signals x(n) and h(n using MATLAB, plot
them, and observe the resulting output y(n).
Theory :
In discrete-time signal processing, convolution is a mathematical operation used to
determine the output of a Linear Time-Invariant (LTI) system when the input and the
system's impulse response are [Link] convolution sum is given by:
𝑦(𝑛) = (𝑥 ∗ ℎ)𝑛 = 𝛴𝑥(𝑘)ℎ(𝑛 − 𝑘)
Where
x(n) → Input signal
h(n) → Impulse response of the system
y(n) → Output signal
In this experiment:
x(n)=u(n+10)−u(n−5) → A rectangular pulse from n=−10 to n=4
h(n)=2^n⋅u(n) → A right-sided exponential sequence starting at n=0.
MATLAB’s conv() function performs linear convolution.
MATLAB CODE :
clc;
clear all;
close all;
n=-15:15;
u = @(n) n >= 0;
x_n=u(n+10)-u(n-5);
h_n=(2.^n).*u(n);
min_xn=min(n);
max_xn=max(n);
min_nh=min(n);
max_nh=max(n);
n_y=min_xn+min_nh:max_xn+max_nh;
y_n=conv(x_n,h_n);
subplot(3,1,1)
stem(n,x_n);
title("x(n)=u(n+10)-u(n-5)");
axis([min(n)-1 max(n)+1 min(x_n)-1 max(x_n)+1]);
grid on;
subplot(3,1,2)
stem(n,h_n);
axis([min(n)-1 max(n)+1 min(h_n)-1 max(h_n)+1]);
title("h(n)=2^n*u(n)");
grid on;
subplot(3,1,3);
stem(n_y,y_n)
axis([min(n_y)-1 max(n_y)+1 min(y_n)-1 max(y_n)+1]);
title("y(n)=x(n)*h(n)")
grid on;
Result :
Experiment No : 10
Experiment Name : Convolution of Two Discrete-Time Signals in MATLAB.
Objective :
To compute and visualize the convolution of a finite-duration discrete signal x(n) and an
exponential signal h(n) using MATLAB.
Theory :
In discrete-time signal processing, convolution is a mathematical operation used to
determine the output of a Linear Time-Invariant (LTI) system when the input and the
system's impulse response are [Link] convolution sum is given by:
𝑦(𝑛) = (𝑥 ∗ ℎ)𝑛 = 𝛴𝑥(𝑘)ℎ(𝑛 − 𝑘)
Where
x(n) → Input signal
h(n) → Impulse response of the system
y(n) → Output signal
In this experiment:
x(n) is a rectangular pulse with value 1 from n=0 to n=5 and zero otherwise.
h(n)=e^−n⋅u(n+10) is a left-shifted decaying exponential that starts from n=−10 due to the
unit step function u(n+10)
MATLAB’s conv() function performs linear convolution.
MATLAB CODE :
clc;
clear all;
close all;
u = @(n) n >= 0;
n=-10:10;
x_n=[];
for i=1:length(n)
if(n(i)>=0 && n(i)<=5)
x_n(i)=1;
else
x_n(i)=0;
end
end
h_n=exp(-(n)).*u(n+10)
min_xn=min(n);
max_xn=max(n);
min_nh=min(n);
max_nh=max(n);
n_y=min_xn+min_nh:max_xn+max_nh;
y_n=conv(x_n,h_n);
subplot(3,1,1)
stem(n,x_n);
title("x(n)");
axis([min(n)-1 max(n)+1 min(x_n)-1 max(x_n)+1]);
grid on;
subplot(3,1,2)
stem(n,h_n);
axis([min(n)-1 max(n)+1 min(h_n)-1 max(h_n)+1]);
title("h(n)");
grid on;
subplot(3,1,3);
stem(n_y,y_n)
axis([min(n_y)-1 max(n_y)+1 min(y_n)-1 max(y_n)+1]);
title("y(n)=x(n)*h(n)")
grid on;
Result :
Experiment No : 11
Experiment Name : Convolution of an Exponential Signal with a Delayed Step Signal
in MATLAB
Objective :
To perform and visualize the convolution between a decaying exponential signal x(n) and a
delayed unit step signal h(n) using MATLAB.
Theory :
In discrete-time signal processing, convolution is a mathematical operation used to
determine the output of a Linear Time-Invariant (LTI) system when the input and the
system's impulse response are [Link] convolution sum is given by:
𝑦(𝑛) = (𝑥 ∗ ℎ)𝑛 = 𝛴𝑥(𝑘)ℎ(𝑛 − 𝑘)
Where
x(n) → Input signal
h(n) → Impulse response of the system
y(n) → Output signal
Signals used in this experiment:
Input signal : 𝑥(𝑛) = 𝑒 −2𝑛 . 𝑢(𝑛)
A right-sided exponentially decaying signal starting at n=0.
Impulse response : ℎ(𝑛) = 𝑢(𝑛 − 10)
A delayed unit step starting at n=10
The convolution result y(n)y(n)y(n) is obtained using MATLAB’s built-in conv() function.
MATLAB CODE :
clc;
clear all;
close all;
u = @(n) n >= 0;
n=-10:10;
x_n=exp(-2.*n).*u(n)
h_n=u(n-10)
min_xn=min(n);
max_xn=max(n);
min_nh=min(n);
max_nh=max(n);
n_y=min_xn+min_nh:max_xn+max_nh;
y_n=conv(x_n,h_n);
subplot(3,1,1)
stem(n,x_n);
title("x(n)");
axis([min(n)-1 max(n)+1 min(x_n)-1 max(x_n)+1]);
grid on;
subplot(3,1,2)
stem(n,h_n);
axis([min(n)-1 max(n)+1 min(h_n)-1 max(h_n)+1]);
title("h(n)");
grid on;
subplot(3,1,3);
stem(n_y,y_n)
axis([min(n_y)-1 max(n_y)+1 min(y_n)-1 max(y_n)+1]);
title("y(n)=x(n)*h(n)")
grid on;
Result :
Experiment No : 12
Experiment Name : Magnitude and Phase Spectrum of a Discrete Fourier Transform
(DFT) using MATLAB.
Objective :
To generate a cosine wave, compute its Discrete Fourier Transform (DFT) using MATLAB,
and plot both the magnitude and phase spectra.
Theory :
The inverse discrete Fourier transform (IDFT) is a mathematical operation that is used to
convert a digital signal represented in the frequency domain into the time domain. Therefore,
the inverse discrete Fourier transform is simply a reverse operation of the discrete Fourier
transform (DFT). The inverse discrete Fourier transform is mainly used to recover the
original signal from the frequency domain signal. Mathematically, the inverse discrete
Fourier transform is calculated by using the following standard equation:
1 2𝜋
𝑋(𝑛) = 𝛴𝑥(𝑘). 𝑒 −𝑗 𝑁 𝑘𝑛
𝑁
Hence, the Discrete Fourier Transform (DFT) and Inverse Discrete Fourier Transform (IDFT)
are two correlated mathematical operations widely used in the field of engineering and
technology for signal processing, image processing, filtering, noise reduction, and to perform
many other tasks.
MATLAB CODE :
clc;clear all;close all;
fs = 500; % Sampling frequency of the signal in Hz
T = 1/fs; % Sampling period of the signal in seconds
N = 500; % Length of the signal
t = (0:N-1)*T; % Time vector
f = 50; % Frequency of the input signal in Hz
x = cos(2*pi*f*t); % A cosine signal wave
X = fft(x);
% Create a frequency axis
F = fs*(0:(N/2))/N;
% Plot the magnitude spectrum of DFT
MS = 2*abs(X(1:N/2 + 1))/N; % Calculating the magnitude spectrum
figure;
plot(F, MS);
title('Magnitude Spectrum of DFT');
xlabel('Frequency (in Hz)');
ylabel('Magnitude');
% Plot the Phase Spectrum of DFT
PS = angle(X(1:N/2 + 1)); % Calculating the phase spectrum
figure;
plot(F, PS);
title('Phase Spectrum of DFT');
xlabel('Frequency (in Hz)');
ylabel('Phase');
Result :
Experiment No : 13
Experiment Name : Magnitude and Phase Spectrum of a Random Sequence using
Discrete Fourier Transform (DFT) in MATLAB.
Objective :
To generate a random sequence, compute its Discrete Fourier Transform (DFT) using
MATLAB, and plot both the magnitude and phase spectra.
Theory :
The inverse discrete Fourier transform (IDFT) is a mathematical operation that is used to
convert a digital signal represented in the frequency domain into the time domain. Therefore,
the inverse discrete Fourier transform is simply a reverse operation of the discrete Fourier
transform (DFT). The inverse discrete Fourier transform is mainly used to recover the
original signal from the frequency domain signal. Mathematically, the inverse discrete
Fourier transform is calculated by using the following standard equation:
1 2𝜋
𝑋(𝑛) = 𝛴𝑥(𝑘). 𝑒 −𝑗 𝑁 𝑘𝑛
𝑁
Hence, the Discrete Fourier Transform (DFT) and Inverse Discrete Fourier Transform (IDFT)
are two correlated mathematical operations widely used in the field of engineering and
technology for signal processing, image processing, filtering, noise reduction, and to perform
many other tasks.
MATLAB CODE :
clc;clear all; close all ;
N = 200; % Length of the input sequence
x = randn(1, N);
% Calculate the DFT of the sequence x
X = fft(x);
% Create the frequency
F = (0:N-1) / N;
% Plot the magnitude spectrum of the DFT
MS = abs(X); % Calculating the magnitude spectrum
figure;
stem(F, MS);
title('Magnitude Spectrum of DFT');
xlabel('Frequency');
ylabel('Magnitude');
% Plot the phase spectrum of DFT
PS = angle(X); % Calculating the phase spectrum
figure;
stem(F, PS);
title('Phase Spectrum of DFT');
xlabel('Frequency');
ylabel('Phase');
Result :
Experiment No : 14
Experiment Name : Reconstruction of Time-Domain Signal from Frequency-Domain
Data using Inverse Discrete Fourier Transform (IDFT) in MATLAB.
Objective :
To reconstruct a time-domain signal from a given frequency-domain sequence using the
Inverse Discrete Fourier Transform (IDFT) and analyze its real and imaginary parts.
Theory :
The Inverse Discrete Fourier Transform (IDFT) converts a frequency-domain sequence X[k]
back to its corresponding time-domain sequence x[n]. It is defined as:
1 2𝜋
𝑋(𝑛) = 𝛴𝑥(𝑘). 𝑒 𝑗 𝑁 𝑘𝑛
𝑁
Where:
X[k] = frequency-domain sequence
N = number of samples
x[n] = reconstructed time-domain sequence
The IDFT can be efficiently computed using the Inverse Fast Fourier Transform (IFFT) in
MATLAB.
If the frequency-domain data X[k] contains complex random values, then the time-domain
signal will also have both real and imaginary components.
MATLAB CODE :
clc;clear all ; close all ;
N = 200; % Length of the sequence
X = randn(1, N) + 1i * randn(1, N); % Random sequence in frequency domain
% Calculate the inverse discrete Fourier transform
x = ifft(X); % Reconstructing the original sequence
% Creating a time axis
t = 0 : N-1;
% Plot the real part of the reconstructed sequence in time domain
subplot(2, 1, 1);
stem(t, real(x)); % Plotting the real part of sequence
title('Real Part of Reconstructed Signal');
xlabel('Time');
ylabel('Amplitude');
% Plot the imaginary part of the reconstructed sequence in time domain
subplot(2, 1, 2);
stem(t, imag(x)); % Plotting the imaginary part of sequence
title('Imaginary Part of Reconstructed Signal');
xlabel('Time');
ylabel('Amplitude');
Result :
Experiment No : 15
Experiment Name : z-Transform in Matlab.
Objective :
a) To realize the significance of z-transform
b) To determine the z-transform and inverse z-transform of discrete time signal and systems
in MATLAB
c)To find the pole-zero plot and impulse response of the DT system.
Significance of 𝒛 −2
The z-transform of a discrete-time signal x(n) is defined as the power series
𝑋(𝑧) = 𝛴𝑥(𝑛)𝑧 −𝑛 .
Where z is a complex variable. The relation is sometimes called the direct z-transform
because it transforms the time-domain signal x(n) into its complex-plane representation X(z).
𝑧 = 𝑟𝑒 𝑗𝑤
𝑧 −𝑛 = 𝑟 −𝑛 𝑒 −𝑗𝑤𝑛
−𝑛
𝑟 [𝑐𝑜𝑠(𝑤𝑛) − 𝑗𝑠𝑖𝑛(𝑤𝑛)]
MATLAB CODE :
Plot of 𝑟^−𝑛 𝑐𝑜𝑠(𝜔𝑛) when r>1 and 𝜔 = 𝜋/4 per samples
clc;clear all;close all;
n=0:.1:100;
r=1.1;
w=pi/4;
y1=r.^(-n);
y2=cos(w*n);
y=y1.*y2;
subplot(3,1,1);
plot(n,y1);
xlabel('Sample No');
ylabel('amplitude');
title('r^-^n when r>1');
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)');
Result :
Plot of 𝑟^−𝑛 𝑐𝑜𝑠(𝜔𝑛) when r<1 and 𝜔 = 𝜋/4 per samples
clc;clear all;close all;
n=0:.1:100;
r=0.9;
w=pi/4;
y1=r.^(-n);
y2=cos(w*n);
y=y1.*y2;
subplot(3,1,1);
plot(n,y1);
xlabel('Sample No');
ylabel('amplitude');
title('r^-^n when r<1');
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)');
Result :
Plot of 𝑟^−𝑛 𝑐𝑜𝑠(𝜔𝑛) when r=1 and 𝜔 = 𝜋/4 per samples
MATLAB CODE :
clc;clear all;close all;
n=0:.1:100;
r=1;
w=pi/4;
y1=r.^(-n);
y2=cos(w*n);
y=y1.*y2;
subplot(3,1,1);
plot(n,y1);
xlabel('Sample No');
ylabel('amplitude');
title('r^-^n when r=1');
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)');
Result :
Finding z-transform of a function :
Example 1 :
>> syms a n f;
>> f=a^n
f=
a^n
>> ztrans(f)
ans =
-z/(a - z)
Example 2 :
>> syms n
>> x=1/4^n
x=
1/4^n
>> xz=ztrans(x)
xz =
z/(z - 1/4)
Example 3 :
>> syms w n
>> x=sin(w*n)
x=
sin(n*w)
>> xz=ztrans(x)
xz =
(z*sin(w))/(z^2 - 2*cos(w)*z + 1)
Finding inverse z-transform of a function :
Example 1 :
>> syms z
>> x=2*z/(2*z-1);
>> xn=iztrans(x)
xn =
(1/2)^n
Z-Plane and Impulse response :
MATLAB CODE :
clc;clear all;close all;
function []=zplane_impulseResponse(Num,Den)
figure('Name','Z-Plane','position',[179 83 560 420]);
zplane(Num,Den);
set(gca,'Color',[0.89 0.99 0.85]); % gca(get current axes handle), [RGB Triplet ]
title('Poles and Zeros');
figure('Name','Impulse response','position',[751 83 560 420]);
impz(Num,Den);
set(gca,'Color',[0.89 0.92 0.92]);
title('Impulse Response')
end;
System with complex conjugate poles :
𝑧 𝑧
𝐻(𝑧) = =
𝑧2 − 0.707𝑧 + 0.2499 (𝑧 − (0.3535 + 𝑗0.3535))(𝑧 − (0.3535 − 𝑗0.3535))
zplane_impulseResponse([1 0], [1 -0.707 .2499])
System with complex conjugate poles in unit circle :
𝑧
𝐻(𝑧) =
𝑧 2 − 1.4144𝑧 + 1
zplane_impulseResponse([1],[1 -1.4144 1]);
System with complex conjugate poles outside of unit circle :
zplane_impulseResponse([1,0],[1 -2.02 1.14])