Experiment No. 1: Objective: Write A MATLAB Program To Generate An Exponential Sequence X (N) (A)
Experiment No. 1: Objective: Write A MATLAB Program To Generate An Exponential Sequence X (N) (A)
1
Objective: Write a MATLAB program to generate an exponential sequence X(n)=(a)n for
Theory:
An exponential sequence is a sequence of the form X(n)=( a)n in which the argument n occurs
as an exponent.
ii) For -1 <a <0 , the sequence value would acquire positive value for even value of n and negative
for odd value of n. At the same time value of n decreases as n increases.
iii ) For a < -1 , the sequence value would acquire positive value for even value of n and negative for
odd value of n. At the same time value of n decreases as n increases.
iv)For a > 1,the sequence value would be exponentially increasing as the value of n increases.
Source Code:
clc;
clear all;
close all;
n=1:15;
subplot(2,2,1);
stem(x1);
xlabel('n');
ylabel('x1');
title('Graph for 0<a1<1');
subplot(2,2,2);
stem(x2);
xlabel('n');
ylabel('x2');
title('Graph for -1<a2<0');
subplot(2,2,3);
stem(x3);
xlabel('n');
ylabel('x3');
title('Graph for a3<-1');
subplot(2,2,4);
stem(x4);
xlabel('n');
ylabel('x4');
title('Graph for a4>1');
Noise:
In signal processing, noise is a general term for unwanted (and, in general, unknown) modifications
that a signal may suffer during capture, storage, transmission, processing, or conversion.
Sometimes the word is also used to mean signals that are random (unpredictable) and carry no useful
information; even if they are not interfering with other signals or may have been introduced
intentionally, as in comfort noise.
For Example: We are generating noise with inbuilt function in MATLAB rand().
Downsampling:
In digital signal processing, decimation is the process of reducing the sampling rate of a signal. The
term downsampling usually refers to one step of the process, but sometimes the terms are used
interchangeably. Decimation is a specific case of sample rate conversion in a multi-rate digital signal
processing system. A system component that performs decimation is called a decimator.
clc;
close all;
clear all;
n=1:90;
%Random signal as noise
d=rand(1,90);
% signal+ Noise
x=s+d;
%Plot of signal
subplot(2,2,1);
stem(s);
xlabel('n');
ylabel('s');
title('Original Signal');
%Plot of Noise
subplot(2,2,2);
stem(d);
xlabel('n');
ylabel('d');
title('Noise Signal');
%Plot of Signal+Noise
subplot(2,2,3);
stem(x);
xlabel('n');
ylabel('x');
title('Distorted Signal');
Experiment No. 3
Objective: Generate Gaussian number with mean=20 and variance=40.Also plot the pdf of
generated number.
Software Used: MATLAB R2012a
Theory:
PDF:
Normal Distribution:
We will be implementing this with above function as we all as inbuilt MATLAB function
normpdf().
Source Code:
clc;
close all;
clear all;
mu=20;
var=40;
sd=sqrt(var);
%Generating random variable
x=normrnd(mu,sd,1,200);
subplot(3,1,1);
stem(x);
xlabel('n','fontweight','bold','fontsize',10);
ylabel('Random Variable','fontweight','bold','fontsize',10);
title('Random Variable Plot','fontweight','bold','fontsize',10);
Result:
We have generated random variable by taking specific values of mu and sigma. By using this
generated random variable we have generated Gaussian pdf which is as expected in inverted
bell shape graph.
PLOT
Observation:
We have verified Gaussian pdf function obtained by formula and inbuilt function in matlab
and graphs are identical. Please find above diagrams.
Experiment No. 4-i
Objective: Generate Gaussian number with mean=0 and variance=1.Plot the generated
number and calculate 3rd moment i.e Skewness using
𝑥𝑗 − 𝑢
1
Skew(X1, X2, ……Xn) = ∑𝑁
𝒋=𝟎 [ ─ ]^3
𝑁
Theory:
Skewness:
The skewness is defined as the third moment about the mean with the following equation,
The skewness describes the degree of asymmetry of a distribution. A symmetric distribution
has a skewness of zero, while an asymmetric distribution has a nonzero skewness. If more
extreme tail of the distribution is to the right of the mean, the skewness is positive; if the more
extreme tail is to the left of the mean, the skewness is negative. The skewness is illustrated in
Fig.
Source Code:
clc;
close all;
clear all;
mu=0;
var=1;
sd=sqrt(var);
N=1:300;
%Generating random variable
x=normrnd(mu,sd,1,300);
Result:
We have generated Gaussian pdf of random variables and calculated skewness value. Plot has
been printed to verify skewness value.
PLOT
Observation:
As per above graph we see that left tail is longer and hence skewness must be negative.
Calculated value of skewness from given function is negative and hence the experiment is
verified. Also using inbuilt function y = skewness(X) result is verified but value obtained
differs slightly as MATLAB has 2 interpretations for skewness function.
Experiment No. 4-ii
Generate Gaussian number with mean=0 and variance=1 and plot its lognormal distribution.
Source Code:
clc;
close all;
clear all;
mu=0;
var=1;
sd=sqrt(var);
N=1:300;
x=lognrnd(mu,sd,300);
subplot(2,1,1);
stem(x);
xlabel('No of samples','fontweight','bold','fontsize',10);
ylabel('Amplitude','fontweight','bold','fontsize',10);
title('Lognormal Number','fontweight','bold','fontsize',10);
Result:
PLOT
Theory:
Convolution is a mathematical operation used to express the relation between input and
output of an LTI system. It relates input, output and impulse response of an LTI system as
The input-output characteristic of linear time-invariant (LTI) systems, the most widely used
type of system in signal processing, is described entirely in terms of the impulse response of
the system. The impulse response is the output of the system due to an impulse input
signal. Given the input signal, the output of an LTI system is the convolution of the input
signal with the impulse response of the system. Hence, convolution plays a key role in
relating the input and output signals of an LTI system.
Source Code:
clc;
close all;
clear all;
m=length(x);
n=length(h);
c1=conv(x,h);
%Zero padding for unequal length sequence
h=[h,zeros(1,m)];
x=[x,zeros(1,n)];
% disp(h);
% disp(x);
for i=1:m+n-1
c(i)=0;
for j=1:m+n-1
if (j<=i)
c(i)=c(i)+(x(j)*h(i-j+1));
end
end
end
disp('Convolution of x(n) and h(n) is ');
disp(c);
%Plot of X(n)
subplot(2,2,1);
stem(x);
title('Input sequencce X(n)','fontweight','bold','fontsize',10);
xlabel('n','fontweight','bold','fontsize',10);
ylabel('X(n)','fontweight','bold','fontsize',10);
%Plot of H(n)
subplot(2,2,2);
stem(h);
title('Input sequencce H(n)','fontweight','bold','fontsize',10);
xlabel('n','fontweight','bold','fontsize',10);
ylabel('H(n)','fontweight','bold','fontsize',10);
%Plot of X(n)*H(n)
subplot(2,2,3);
stem(c);
title('Convolution of X(n) and H(n)','fontweight','bold','fontsize',10);
xlabel('n','fontweight','bold','fontsize',10);
ylabel('C(n)','fontweight','bold','fontsize',10);
Result:
We have taken 2 unequal length sequences and used padding for equating length of them.
Convolution uses 2 loops in which first loop is used for shifting and second loop is for
product of shifted signal and original signal.
PLOT
Observation:
Convolution of 2 input signals has been verified with inbuilt function as well and results are
identical.
Experiment No. 6
Objective: Generate Gaussian distributed numbers and uniformly distributed numbers and
find the correlation between them.
Theory:
A signal operation similar to signal convolution, but with completely different physical
meaning, is signal correlation. The signal correlation operation can be performed either with
one signal (autocorrelation) or between two different signals(crosscorrelation). Physically,
signal autocorrelation indicates how the signal energy (power) is distributed within the signal,
and as such is used to measure the signal power. Typical applications of signal autocorrelation
are in radar, sonar, satellite, and wireless communications systems. Devices that measure
signal power using signal correlation are known as signal correlators. There are also many
applications of signal crosscorrelation in signal processing systems, especially when the
signal is corrupted by another undesirable signal (noise) so that the signal estimation
(detection) from a noisy signal has to be performed. Signal crosscorrelation can be also
considered as a measure of similarity of two signals.
Given two discrete-time real signals (sequences) x[k] and y[k]. The autocorrelation and
croosscorrelation functions are respectively defined by
Source Code:
clc;
close all;
clear all;
mu=0;
var=1;
sd=sqrt(var);
%disp(h1);
for i=1:30
h(i)=h1(l-i+1);
end
for i=1:m+n-1
c(i)=0;
for j=1:m+n-1
if (j<=i)
c(i)=c(i)+(X(j)*H(i-j+1));
end
end
end
c1=xcorr(x,h1);
%Plot of X(n)
subplot(2,2,1);
stem(x);
title('Gaussian Distributed Numbers
x(n)','fontweight','bold','fontsize',10);
xlabel('n','fontweight','bold','fontsize',10);
ylabel('x(n)','fontweight','bold','fontsize',10);
%Plot of H(n)
subplot(2,2,2);
stem(h1);
title('Uniformly Distributed Numbers
h1(n)','fontweight','bold','fontsize',10);
xlabel('n','fontweight','bold','fontsize',10);
ylabel('h1(n)','fontweight','bold','fontsize',10);
%Corr of X(n)*H(n)
subplot(2,2,3);
stem(c);
title('Correlation of X(n) and H(n)','fontweight','bold','fontsize',10);
xlabel('n','fontweight','bold','fontsize',10);
ylabel('C(n)','fontweight','bold','fontsize',10);
PLOT
Observation:
Correlation of 2 input signals has been verified with inbuilt function as well and results are
identical. Plots are as shown above.
Experiment No. 7
Objective: Write a MATLAB program to perform circular convolution of two finite
unequal length sequence.
Theory:
Circular convolution is another way of finding the convolution sum of two input signals. It
resembles the linear convolution, except that the sample values of one of the input signals is
folded and right shifted before the convolution sum is found. Also note that circular
convolution could also be found by taking the DFT of the two input signals and finding the
product of the two frequency domain signals. The Inverse DFT of the product would give the
output of the signal in the time domain which is the circular convolution output. The two input
signals could have been of varying sample lengths. But we take the DFT of higher point,
which ever signals levels to. For eg. If one of the signal is of length 256 and the other spans
51 samples, then we could only take 256 point DFT. So the output of IDFT would be
containing 256 samples instead of 306 samples, which follows N1+N2 – 1 where N1 & N2
are the lengths 256 and 51 respectively of the two inputs. Thus the output which should have
been 306 samples long is fitted into 256 samples. The 256 points end up being a distorted
version of the correct signal. This process is called circular convolution. The circular
convolution of two sequences x[n],h[n] is a wrap-around of the sequences after a period of N
samples. So, the circular convolution is defined by
where (n′−n)N gives the remainder of n′−n divided by N. For example, (−1)N=N−1.This
means, if the index for x[(n′−n)N] would leave the range 0,…,N−1 to the left, it would wrap
around and come in from the right again. This means that the circular convolution is
periodic with length N.
Source Code:
clc;
close all;
clear all;
m=length(x);
n=length(h);
l=max(m,n);
subplot(2,1,1);
stem(c);
title('Circular Convolution of X(n)&H(n) using
formula','fontweight','bold','fontsize',10);
xlabel('n','fontweight','bold','fontsize',10);
ylabel('C(n)','fontweight','bold','fontsize',10);
subplot(2,1,2);
stem(c1);
title('Circular Con of X(n)&H(n) using inbuilt
function','fontweight','bold','fontsize',10);
xlabel('n','fontweight','bold','fontsize',10);
ylabel('C1(n)','fontweight','bold','fontsize',10);
Result:
Circular convolution of x(n) and h(n) is calculated by using two loops in which first loop is
for signal x(n) keeping it clockwise and second loop makes h(n) counter clockwise and then
shifts it by 1 and multiplies h(n),x(n) and adds it .Below is plot for circular convolution
using formula and inbuilt MATLAB function.
PLOT
Observation:
Circular convolution of x(n) and h(n) has been verified with formula and inbuilt function
and results are identical shown as above.
Experiment No. 8
Objective: Design a FIR low-pass filter with given specification and verify magnitude,
phase impulse response using FDA toolbox .Order=100,Window=Rectangular window, cut
off frequency in rad/sec=0.4.
Theory:
In signal processing, a finite impulse response (FIR) filter is a filter whose impulse
response (or response to any finite length input) is of finite duration, because it settles to
zero in finite time. The impulse response of an Nth-order discrete-time FIR filter lasts
exactly N + 1 samples (from first nonzero element through last nonzero element) before it
then settles to zero. FIR filters are employed in filtering problems where linear phase
characteristics within the pass band of the filter are required. To obtain an FIR filter which
approximates the original frequency response, the Fourier series expansion of the system
must be truncated, but the direct truncation of the series leads to Gibbs phenomenon, i.e., a
fixed percentage overshoot and ripple before and after an approximated discontinuity, which
in undesired. In order to avoid this, a time-limited weighting function called window is
used. Here we are implementing FIR filter using rectangular window.
Source Code:
clc;
clear all;
close all;
n=100;
w=rectwin(n+1);
b=fir1(n,0.4,'low',w);
freqz(b,1,512);
impz(b);
Result:
We have designed low pass filter with given specifications and magnitude and phase plot is
as shown in figure below.Result is verified with FDA tool also.
Plots for amplitude and phase response has been verified with fdatool .Impulse response is
also plotted and verified by using inbuilt function impz(b).
Experiment No. 9
Objective: Design a IIR low-pass Butterworth filter with following specification and verify
magnitude, phase, impulse response using FDA toolbox, Order Minimum, Pass Band
attenuation in DB : 3.6,Stop Band attenuation in DB : 36 , Pass Band Freq in Hz: 1500,Stop
Band Freq in Hz: 2000 , Sampling Freq in Hz: 6000
Theory:
The Butterworth filter is a type of signal processing filter designed to have a frequency
response as flat as possible in the passband. It is also referred to as a maximally flat
magnitude filter. Butterworth filters sacrifice rolloff steepness for monotonicity in the pass-
and stopbands. Unless the smoothness of the Butterworth filter is needed, an elliptic or
Chebyshev filter can generally provide steeper rolloff characteristics with a lower filter
order. We compute filter order n and 3DB down frequency with buttord function in matlab
and then butter function returns the filter coefficients in length n+1 row vectors b and a,
with coefficients in descending powers of z.
Source Code:
clc;
clear all;
close all;
wp=1500/6000;
ws=2000/6000;
[n,wn]=buttord(wp,ws,0.36,36);
[b,a]=butter(n,wn,'low');
freqz(b,a,512,512);
str = sprintf('Order of filter is %d and wn is %d ', n,wn);
disp(str);
wvtool(a);
Result:
We have designed butterworth low pass filter using matlab inbuilt functions buttord and
butter .Order of resulted filter is 17 and 3DB cut off frequency is 0.27 rad/sec. Also we used
wvtool(WindowVector) to plot time and frequency domain plots of filter coefficients
a.Impulse response is plotted using FDA Tool.
Command Window Output:
WVTOOL:
Impulse response using FDA Tool:
-8.4708 -1.3743
-38.8939 -3.534
-69.3169 -5.6936
Phase (radians)
Magnitude (dB)
-130.163 -10.0129
-160.5861 -12.1726
-191.0091 -14.3322
-16.4919
0 0.5 1 1.5 2 2.5
Frequency (kHz)
Observation:
Magnitude and phase response of designed filter is verified using FDA tool .Also wvtool is
used to check time and frequency domain coefficients of filter.
Experiment No. 10-1
Objective: Design the following circuit using Simulink Toolbox on MATLAB. Half Adder
and Full Adder
Theory:
Half Adder:
Full Adder:
Simulink Design:
HA:
FA:
Result:
First Half Adder is designed using XOR and AND gate .Full adder is designed using half
adder which contains 2 XOR ,2 AND and 1 OR gate .All gates used have 2 input and 1
output port. Input signals are generated from pulse generater using different amplitude and
different duty cycle. Input /Output signal graphs are as shown below.
Half Adder:
Full Adder:
Observation:
Half Adder and Full adder have been designed and result is verified by checking output at
scope. Pulse width and amplitude is varied to obtain different input signals keeping time
period same. Truth table of both FA,HA has been verified by checking graph.
Experiment No. 10-2
Objective: Design the following circuit using Simulink Toolbox on MATLAB. Half Wave
Rectifier and Full Wave Bridge Rectifier
Theory:
A rectifier is a circuit which converts the Alternating Current (AC) input power into a Direct
Current (DC) output power. The input power supply may be either a single-phase or a multi-
phase supply .The power diode in a half wave rectifier circuit passes just one half of each
complete sine wave of the AC supply in order to convert it into a DC supply. Then this type
of circuit is called a “half-wave” rectifier because it passes only half of the incoming AC
power supply as shown below.
Vmax
Vout =
π
A bridge rectifier is a type of full wave rectifier which uses four or more diodes in a bridge
circuit configuration to efficiently convert the Alternating Current (AC) into Direct Current
(DC) .The bridge rectifier is made up of four diodes namely D1, D2, D3, D4 and load resistor
RL. It allows electric current during both positive and negative half cycles of the input AC
signal.
Vmax
Vout =
2π
Simulink Design:
Observation:
Half wave rectifier and full wave bridge rectifier have been designed using Simulink and used
powergui to simulate the same. Waveforms have been observed using scope and result is
verified. Output voltage is verified using formula mentioned above.
Experiment No. 11
Objective: Design the following circuit using Simulink Toolbox on MATLAB. Amplitude
Modulation and demodulation, Frequency Modulation and demodulation
Theory:
Amplitude Demodulation
When demodulating a signal, two basic steps are there:
FM demodulators
There are a number of circuits that can be used to demodulate FM. Each type has its own
advantages and disadvantages, some being used when receivers used discrete components,
and others now that ICs are widely used.
Slope FM detector: This form of detector uses the slope of a tuned circuit to convert
the frequency variations into amplitude variations. As the frequency of the FM signal
varies, it changes its position on the slope of the tuned circuit, so the amplitude will
vary.
Ratio detector: This FM demodulator circuit was widely used with discrete
components, providing a good level of performance. It was characterised by the
transformer with three windings that was required
Foster-Seeley FM detector: Like the Ratio detector the Foster Seeley detector or
discriminator was used with discrete components, providing excellent performance
for the day in many FM radios.
PLL, Phase locked loop FM demodulator: FM demodulators using phase locked
loops, PLLs can provide high levels of performance. They do not require a costly
transformer and can easily be incorporated within FM radio ICs.
Quadrature FM demodulator: This form of FM demodulator is very convenient
for use within integrated circuits. It provides high levels of linearity, while not
requiring many external components.
Coincidence FM demodulator: This form of demodulator has many similarities to
the quadrature detector. It uses digital technology and replaces a mixer with a logic
NAND gate.
Simulink Design:
Amplitude Modulation
Modulator Demodulator
Frequency Modulation
Modulator
Demodulator
Demodulat
or
Fig 4: Frequency Modulation and Demodulation
Result:
Amplitude Modulation
Fig 5: Amplitude Modulation and Demodulation using Simulink
Frequency Modulation
Observation:
Theory:
Source Code:
clc;
clear all;
close all;
A=imread('C:\Users\user\Pictures\pic.png');
Y=imread('C:\Users\user\Pictures\pic2.jpg');
B=im2double(A);
R=B(:,:,1);
G=B(:,:,2);
B=B(:,:,3);
subplot(3,2,1),imshow(A);
title('Original Image','fontweight','bold','fontsize',10);
subplot(3,2,2),imshow(R);
title('Red component of image','fontweight','bold','fontsize',10);
subplot(3,2,3),imshow(G);
title('Green component of image','fontweight','bold','fontsize',10);
subplot(3,2,4),imshow(B);
title('Blue component of image','fontweight','bold','fontsize',10);
H=cat(3,R,G,B);
subplot(3,2,[5,6]),imshow(H);
title('Combine of RGB to original
image','fontweight','bold','fontsize',10);
Result:
Fig 1: Extraction of RGB component of an image and then combine back to get original image
Observation: We have observed that after converting image double precision, we obtained
Red component from slice 1,Blue from slice2 and Green from slice 3 of image and used cat
function to concatenate those 3 slices back to original image.
Experiment No. 13
Objective: Covert the RGB image into grey scale image and resize image to 512*512 pixels,
add and subtract another RGB image to original image calculate sizes of all the images.
Theory:
Source Code:
clc;
clear all;
close all;
img = imread('pic.png'); % Read image
Y = imread('pic2.jpg');
J= rgb2gray(img);
subplot(3,2,1),imshow(img);
title('Original image','fontweight','bold','fontsize',10);
subplot(3,2,2),imshow(J);
title('Grayscale image','fontweight','bold','fontsize',10);
Z = imadd(K,Y);
subplot(3,2,3),imshow(Z);
title('Addition of images','fontweight','bold','fontsize',10);
U=imsubtract(K,Y);
subplot(3,2,4),imshow(U);
title('Subtraction of images','fontweight','bold','fontsize',10);
subplot(3,2,[5,6]),imshow(Y);
title('Second images','fontweight','bold','fontsize',10);
Result:
Fig 2: Size of original image, after resizing, after adding 2images, after subtracting 2 images
Observation: We have converted image to grayscale using rgb2gray function. Also we added
and subtracted 2 images using imadd and imsubtract functions. Also we have calculated size
of each image using size function.
Experiment No. 14
Objective: Write a program to read a RGB image and perform the following operations on
the image. Calculate the discrete cosine transform of the image and then recover the original
image. Add Gaussian noise to grayscale image and then recover the original grayscale image.
Theory:
DCT:
A discrete cosine transform (DCT) expresses a finite sequence of data points in terms of a
sum of cosine functions oscillating at different frequencies. DCTs are important to numerous
applications in science and engineering, from lossy compression of audio (e.g. MP3)
and images (e.g. JPEG) (where small high-frequency components can be discarded),
to spectral methods for the numerical solution of partial differential equations. The use
of cosine rather than sine functions is critical for compression, since it turns out that fewer
cosine functions are needed to approximate a typical signal, whereas for differential equations
the cosines express a particular choice of boundary conditions. In particular, a DCT is
a Fourier-related transform similar to the discrete Fourier transform (DFT), but using
only real numbers.
Noise:
Salt-and-pepper noise known as impulse noise can be caused by sharp and sudden
disturbances in the image signal. It presents itself as sparsely occurring white and black pixels.
An effective noise reduction method for this type of noise is a median filter or
a morphological filter.
Principal sources of Gaussian noise in digital images arise during acquisition e.g. sensor
noise caused by poor illumination and/or high temperature, and/or transmission e.g. electronic
circuit noise. In digital image processing Gaussian noise can be reduced using a spatial filter,
though when smoothing an image, an undesirable outcome may result in the blurring of fine-
scaled image edges and details because they also correspond to blocked high frequencies.
Source Code:
clc;
clear all;
close all;
m=0;
v=0.01;
d=0.05;
img = imread('pic.png');
G = rgb2gray(img);
Q=im2double(G);
J = imnoise(Q,'gaussian',m,v);
S= imnoise(Q,'salt & pepper',d);
subplot(2,2,1),imshow(img);
title('Original image','fontweight','bold','fontsize',10);
subplot(2,2,2),imshow(G);
title('GrayScale image','fontweight','bold','fontsize',10);
subplot(2,2,3),imshow(J);
title('Gaussian noise+image','fontweight','bold','fontsize',10);
subplot(2,2,4),imshow(S);
title('Salt&Pepper noise+image','fontweight','bold','fontsize',10);
I = rgb2gray(img);
K = dct2(I);
subplot(1,2,1),imshow(K);
title('DCT of grayscale image','fontweight','bold','fontsize',10);
L = idct2(K);
subplot(1,2,2),imshow(L,[0 255]);
title('IDCT of grayscale image','fontweight','bold','fontsize',10);
h = fspecial('average', [3 3]);
filtimg = imfilter(J,h);
figure,imshow(filtimg);title('Gaussian Filtered image');
B = medfilt2(S);
figure,imshow(B);title('Salt&Pepper Filtered image');
Result:
Observation:We have calculated DCT of image and recovered original image back using
idct2 function. Also, we have used inbuilt function to add noise into image and recovered
image using spatial filter for Gaussian noise where hsize is kept as default .But as we increase
hsize more smooth picture is obtained. Median filter for salt and paper noise is used. Results
are as shown in above figure.
Experiment No. 15
Objective: Write a program to perform DFT and IDFT of signal and verify using inbuilt
MATLAB function.
Theory:
𝑁−1
−2∗𝑝𝑖∗𝑖∗𝑘∗𝑛
𝑋𝑘 = ∑ 𝑥𝑛 . 𝑒 𝑁
𝑛=0
for n=1:16
x(n)=n;
end
y=zeros(1,N);
for K=1:16
for m=1:16
y(K)=y(K)+x(m)*exp((-j)*2*pi*(m-1)*(K-1)/N);
end
end
Y = fft(x);
m = abs(y); % Magnitude
p = unwrap(angle(y));
t=0:N-1;
subplot(3,2,1)
stem(t,x)
ylabel ('Amplitude');
xlabel ('Time Index');
title('DFT with formula','fontweight','bold','fontsize',10)
t=0:N-1;
subplot(323);
stem(t,m);
ylabel ('Amplitude');
xlabel ('K');
t=0:N-1;
subplot(3,2,5);
stem(t,p);
ylabel ('phase');
xlabel ('K');
m1 = abs(Y);
p1 = unwrap(angle(Y));
t=0:N-1;
subplot(3,2,2)
stem(t,x)
ylabel ('Amplitude');
xlabel ('Time Index');
title('FFT with inbuilt function','fontweight','bold','fontsize',10)
t=0:N-1;
subplot(324);
stem(t,m1);
ylabel ('Amplitude');
xlabel ('K');
t=0:N-1;
subplot(3,2,6);
stem(t,p);
ylabel ('phase');
xlabel ('K');
%IDFT of signal
for h=1:16
for k=1:16
x(h)=(x(h)+y(k)*exp((j)*2*pi*(h-1)*(k-1)/N)/N);
end
end
t=0:N-1;
subplot(1,2,1);
stem(t,x/2);
ylabel ('Amplitude');
xlabel ('Time Index');
title('IDFT with formula','fontweight','bold','fontsize',10)
X = ifft(y);
t=0:N-1;
subplot(1,2,2);
stem(t,X);
ylabel ('Amplitude');
xlabel ('Time Index');
title('IFFT with inbuilt function','fontweight','bold','fontsize',10)
Result:
DFT: IDFT:
Fig 1: DFT of signal using formula and Fig 2: IDFT of signal using formula and IFFT
FFT function in MATLAB function in MATLAB
Observation:
DFT and IDFT of signal are calculated using formula method and same is verified using
MATLAB inbuilt function fft and ifft.
Experiment No. 16
Objective: Plot the pole-zero plot for following transfer functions .Use Z-plane for the same.
2𝑧 −1 + 9𝑧 −2 +18𝑧 −3 +48𝑧 −4
𝐻(𝑧) =
3𝑧 −1 + 3𝑧 −2 +25𝑧 −3 −12𝑧 −4
5𝑧 −1 − 9𝑧 −2 +16𝑧 −3 −14𝑧 −4
𝐻(𝑧) = −1
𝑧 − 2𝑧 −2 +10𝑧 −3 +64𝑧 −5
Also calculate the impulse response for following transfer function.
Theory:
Stability
Causal system / anticausal system
Region of convergence (ROC)
Minimum phase / non minimum phase
A pole-zero plot shows the location in the complex plane of the poles and zeros of the transfer
function of a dynamic system, such as a controller, compensator, sensor, equalizer, filter or
communications channel. By convention, the poles of the system are indicated in the plot by
an X while the zeros are indicated by a circle or O.
A pole-zero plot can represent either a continuous-time (CT) or a discrete-time (DT) system.
For a CT system, the plane in which the poles and zeros appear is the s plane of the Laplace
transform. In this context, the parameter s represents the complex angular frequency, which
is the domain of the CT transfer function. For a DT system, the plane is the z plane,
where z represents the domain of the Z-transform.
Impulse Response:
In signal processing, the impulse response, or impulse response function (IRF), of a dynamic
system is its output when presented with a brief input signal, called an impulse. The impulse
response describes the reaction of the system as a function of time (or possibly as a function
of some other independent variable that parameterizes the dynamic behavior of the system).
Source Code:
clc;
clear all;
close all;
z=[2 9 18 48];
p=[3 3 25 -12];
subplot(2,2,1);
zplane(z,p);
grid
title('4th-Order Digital Filter')
z1=[5 -9 16 -14];
p1=[1 -2 10 0 64]
subplot(2,2,2);
zplane(z1,p1);
grid
title('5th-Order Digital Filter')
subplot(2,2,[3 4]);
impz(z2,p2);
grid
title('Impulse Response of system')
Result:
Observation:
Pole-zero plot of both the transfer function is as shown above.Both the systems are unstable
as poles lies outside of unit circle.
Impulse response of given transfer function is plotted as shown above which shows higher
amplitude at higher number of samples.