Professional Documents
Culture Documents
Submitted by
NIKHIL RANJAN
A2305120017
6ECE1
Submitted to
Ms. Anupama Bhan
Assistant Professor
To study various
Mandatory representations of digital
5. 5. 31/01/2023 7/02/2023 1
Experiment systems and determine
system stability
SOFTWARE/HARDWARE REQUIRED:
Octave Online
THEORY:
In electrical engineering, the fundamental quantity of representing some information is called a
signal. It does not matter what the information is i-e: Analog or digital information. In
mathematics, a signal is a function that conveys some information. In fact any quantity
measurable through time over space or any higher dimension can be taken as a signal. A signal
could be of any dimension and could be of any form.
CODE
clc; clear all;
% time axis
n = -25:25;
% unit impulse
delta = n==0;
figure;
subplot(1,2,1);
plot(n,delta,'linewidth',1.5);
title ("continuous delta");
xlabel ("time");
ylabel ("Amplitude");
subplot(1,2,2);
stem(n,delta,'markersize',2);
title ("discrete delta");
xlabel ("n");
ylabel ("Amplitude");
%unit step
step = n>=0;
figure;
subplot(1,2,1);
plot(n,step);
title ("continuous step");
xlabel ("time");
ylabel ("Amplitude");
subplot(1,2,2);
stem(n,step);
title ("discrete step");
xlabel ("n");
ylabel ("Amplitude");
%ramp
ramp = n.*step;
figure;
subplot(1,2,1);
plot(n,ramp);
title ("continuous ramp");
xlabel ("time");
ylabel ("Amplitude");
subplot(1,2,2);
stem(n,ramp);
title ("discrete ramp");
xlabel ("n");
ylabel ("Amplitude");
% sinusoidal
a = 0.4;
t = 0:0.1:6;
sig=4*sin(2*pi*a*t);
figure;
plot(sig);
title("Sinusoidal Signal");
xlabel('Time');
ylabel('Amplitude');
figure;
stem(sig);
title("Sinusoidal Signal");
xlabel('Time');
ylabel('Amplitude');
% Exponential
X = -10:10;
res = exp(X);
figure;
plot(X,res);
title("Continuos Exponential");
xlabel('Time');
ylabel('Amplitude');
figure;
stem(X,res);
title("Discrete Exponential");
xlabel('Time');
ylabel('Amplitude');
OBSERVATIONS
CONCLUSION
Hence we plotted different types of signals in Continuous and Discrete form using MATLAB.
SOFTWARE/HARDWARE REQUIRED:
Octave Online
THEORY:
Sampling: sampling is the reduction of a continuous-time signal to a discrete-time signal. A
common example is the conversion of a sound wave (a continuous signal) to a sequence of
samples (a discrete-time signal).
Sampling Rate:Sampling frequency is the reciprocal of the sampling period. This sampling
frequency can be simply called as Sampling rate.The sampling rate denotes the number of
samples taken per second, or for a finite set of values.To discretize the signals, the gap between
the samples should be fixed. That gap can be termed as a sampling period Ts
Sampling Frequency, FS = 1/TS
Where,TS = Sampling Time
FS = Sampling Frequency or Sampling Rate
Nyquist Rate:If the sampling frequency (Fs) equals twice the input signal frequency (Fm), then
such a condition is called the Nyquist Criteria for sampling. When sampling frequency equals
twice the input signal frequency is known as “Nyquist rate”.
Fs=2Fm
Fs ≥ 2Fm
If the sampling frequency (Fs) is less than twice the input signal frequency, such criteria called
an Aliasing effect.
Fs<2Fm
Fig 4. Sampling-output-waveforms
Sampling at different Sampling Frequencies
Critical Sampling:A sampling is termed as a critical or perfect sampling when the sampling
frequency (FS) is equal to the twice of the input/message signal (Fm). The relation of
critical/perfect sampling is given as follows:
Fs= 2Fm
Under Sampling: Under sampling is a technique where one samples a bandpass-filtered signal at
a sample rate below its Nyquist rate (twice the upper cut-off frequency), but is still able to
reconstruct the signal.
In simple terms A sampling is termed to be an under sampling when the sampling frequency (FS)
is less than the twice of the input/message signal (Fm). The relation of an under sampling is
given as follows:
Fs< 2Fm
CODE
clc;
clear all;
close all;
A = 1; f0=9;
x = @(t) A.*cos(2*pi*f0.*t);
%% Critical Sampling
fs1 = 2*f0; %Sampling rate
t1 = 0:1/fs1:1; %time axis
sig1 = x(t1);
figure;
ezplot(x,[0 1]);
hold on;
stem(t1,sig1);
hold off;
ylabel('cos(2 \pi 5t)')
title('Critical Sampling, fs=10Hz')
%% Under Sampling
fs2 =f0; %Sampling rate
t2 = 0:1/fs2:1; %time axis
sig2 = x(t2);
figure;
ezplot(x,[0 1]);
hold on;
stem(t2,sig2);
hold off;
ylabel('cos(2 \pi 5t)')
title('Under Sampling, fs=5Hz')
%% Over Sampling
fs3 = 10*f0; %Sampling rate
t3 = 0:1/fs3:1; %time axis
sig3 = x(t3);
figure;
ezplot(x,[0 1]);
hold on;
stem(t3,sig3);
hold off;
ylabel('cos(2 \pi 5t)')
title('Over Sampling, fs=50Hz')
%% Over Sampling
fs4 = 74; %Sampling rate
t4 = 0:1/fs4:1; %time axis
sig4 = x(t4);
figure;
ezplot(x,[0 1]);
hold on;
stem(t4,sig4);
hold off;
ylabel('cos(2 \pi 5t)')
title('Over Sampling, fs=74Hz')
OBSERVATIONS
Fig 8. Criticial Sampling
CONCLUSION
Hence we studied the effect of sampling at different sampling frequencies on MATLAB.
EXPERIMENT 3
AIM
To perform linear and circular convolution.
SOFTWARE/HARDWARE REQUIRED:
Octave Online
THEORY:
Convolution:
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
Y(t) = X(t) ∗ H(t)
Where Y(t) = Output of LTI system
X(t) = Input of LTI system
H(t) = Impulse Response of LTI system
Discrete Convolution: Given the impulse response of a discrete-time LTI system ℎ[𝑛], its
response to any general input 𝑥[𝑛] is given as
Linear Convolution:
Linear convolution is a mathematical operation done to calculate the output of any Linear-Time
Invariant (LTI) system given its input and impulse response. It is represent as:
Circular Convolution:
Circular convolution is essentially the same process as linear convolution. Just like linear
convolution, it involves the operation of folding a sequence, shifting it, multiplying it with
another sequence, and summing the resulting.
However, in circular convolution, the signals are all periodic. Thus, the shifting can be thought
of as actually being a rotation. Since the values keep repeating because of the periodicity. Hence,
it is known as circular convolution.
%%
Ny=Ng+Nh-1;
y2a= cconv(g,h,Ny)
figure;
subplot(3,2,1);
stem(0: Ng-1,g); grid on;
xlabel('Discrete Time,n');
ylabel('g[n]');
xlim([-0.5 4.5])
subplot(3,2,2);
stem(0: Nh-1,h); grid on;
xlabel('Discrete Time,n');
ylabel('h[n]');
xlim([-0.5 4.5])
subplot(3,2,3);
stem(0:(Ng+Nh-1)-1,y1); grid on;
xlabel('Discrete Time,n');
ylabel('linear conv, y1[n]');
xlim([-0.5 4.5])
subplot(3,2,4);
stem(0:N-1,y2); grid on;
xlabel('Discrete Time,n');
ylabel('Circular conv, y2[n]')
xlim([-0.5 4.5])
subplot(3,2,5);
stem(0:Ny-1,y2a); grid on;
xlabel('Discrete Time,n');
ylabel('Circular conv, y2a[n]')
xlim([-0.5 4.5])
OUTPUT
y1 =
5 16 27 38 24
y2 =
29 16 27 38
y2a =
5 16 27 38 24
Fig 3. Linear and Circular Convolution in OCTAVE Online
CONCLUSION
Hence we performed linear and circular convolution on MATLAB.
SOFTWARE/HARDWARE REQUIRED:
Octave Online
THEORY:
Fourier Transform- The Fourier Transform is a mathematical technique that transforms a
function of time, x(t), to a function of frequency, X(jω).
Discrete Fourier Transform - In mathematics, the discrete Fourier transform (DFT) converts
a finite sequence of equally spaced samples of a function into a same-length sequence of
equally spaced samples of the discrete-time Fourier transform (DTFT), which is a complex-
valued function of frequency. The interval at which the DTFT is sampled is the reciprocal of
the duration of the input sequence.
The discrete Fourier transform transforms a sequence of N complex numbers {XN} = x0,
x1,…, xN-1 into another sequence of complex numbers, {X[k]} = X0, X1,..., XN-1 which
is defined by:
Inverse Discrete Fourier Transform – An inverse DFT is a Fourier series, using the DTFT
samples as coefficients of complex sinusoids at the corresponding DTFT frequencies. It has the
same sample-values as the original input sequence. The inverse DFT (IDFT) transforms NN
discrete-frequency samples to the same number of discrete- times.
CODE
clc;
clear all;
%short sequence
x= [1;1;1;1]
%4 point DFT and iDFT
N=4;
x_fft=fft(x,N)
x_fft= ifft(x_fft,N)
%Generate sinusoid
T=2;
f0=5; %Fundamental Freq= 5 cycles per sec
fs=50; %sampling rate-50 samples per second
t = 0:1/fs:T-1/fs;
y=cos(2*pi*f0.*t);
Ny=128; %take value greater than 100 to recover the sig
y_fft= fft(y,Ny);
%freq axis
f = 0:fs/Ny:fs-fs/Ny;
figure;
subplot(2,1,1);
stem(t,y,'markersize',1);
xlabel('Time,s');
ylabel('cosine');
subplot(2,1,2);
stem(f,abs(y_fft),'markersize',1);
xlabel('Freq,Hz');
ylabel('|y[k]|');
OUTPUT
x =
1
1
1
1
x_fft =
4
0
0
0
x_fft =
1
1
1
1
x_8fft =
4.0000 + 0i
1.0000 - 2.4142i
0 + 0i
1.0000 - 0.4142i
0 + 0i
1.0000 + 0.4142i
0 - 0i
1.0000 + 2.4142i
x_8fft =
1.0000
1.0000
1.0000
1.0000
0
0
0.0000
0
Fig 3. Discrete Fourier Transform (DFT) and its inverse on OCTAVE Online
CONCLUSION
Hence we performed Discrete Fourier Transform (DFT) and its inverse on MATLAB.
SOFTWARE/HARDWARE REQUIRED:
Octave Online
THEORY:
Transfer Function:
A transfer function (or system function) is a frequency domain representation of a dynamical
system. They are used for linear time-invariant systems. Nonlinear or time-varying systems need
different analysis techniques.
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. More generally,
an impulse response is the reaction of any dynamic system in response to some external change.
CODE
clc;
clear all;
close all;
%system 1
%denomcoeff
b= [0.21 0.41 0.21]
%num Coeff
a= [1 -0.37 0.19]
%freq response
figure;
freqz(b,a)
%Impulse response
figure;
impz(b,a)
%pole-zero plot
[zer1,pol1]= tf2zp(b,a)
%zeroes=2,pole=2
figure;
zplane(zer1,pol1)
%system 2
zer2= zer1;
pol2= pol1 + 1;
%transfer func
[b2,a2]= zp2tf(zer2,pol2,1)
figure;
zplane(zer2,pol2);
%Frequency Response
figure;
freqz(b2,a2)
OUTPUT
b =
a =
-0.9762 + 0.2169i
-0.9762 - 0.2169i
pol1 =
0.1850 + 0.3947i
0.1850 - 0.3947i
b2 =
a2 =
CONCLUSION
Hence we studied various representations of digital systems and determine system stability on
MATLAB
SOFTWARE/HARDWARE REQUIRED:
Octave Online
THEORY:
FIR Filter-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. It is
a filter structure that can be used to implement almost any sort of frequency response digitally.
Mathematically FIR can be represented in these equations:
b) High pass filter- The type of filter that allows the high-frequency signals to pass without
any attenuation in its amplitude & blocks (rejects) any low-frequency signal is called
high pass filter.
c) Band pass filter:The band pass filter allows signals falling within a certain frequency
band set up between two points to pass through while blocking both the lower and higher
frequencies either side of this frequency band.
d) Band stop filter:The band stop filter blocks signals falling within a certain frequency
band set up between two points while allowing both the lower and higher frequencies
either side of this frequency band.
FIR filter using rectangular window method- FIR filters can be obtained using
truncation(estimation for the number without doing any rounding) of IIR response with suitable
window functions.
Fig 2.
Some of the Commands used in the Code:
fir: It is used for Window-based FIR filter design and designs a lowpass, highpass,
bandpass, bandstop, or multiband filter, depending on the value of ftype and the number
of elements of Wn.
Syntax- b = fir1(n,Wn,ftype)
CODE
clc;
clear all;
close all;
N=40;%order
Fs= 8000; % sampling freq
win= rectwin(N+1);
%%Low-Pass filter
fc=1000; % Cutofffreq(Hz)
bLPF=fir1(N,2*fc/Fs,'low',win);
%impulse response
figure;impz(bLPF,1);
%Frequency response
figure;freqz(bLPF,1);
%% band-stop filter
fc1=1000;
fc2=2000;
bBSF=fir1(N,[2*fc1/Fs 2*fc2/Fs],'stop',win);
%impulse response
figure;impz(bBSF,1);
%Frequency response
figure;freqz(bBSF,1);
%% High-pass filter
fc3=1000; % Cutofffreq(Hz)
bHPF=fir1(N,2*fc3/Fs,'high',win);
%impulse response
figure;impz(bHPF,1);
%Frequency response
figure;freqz(bHPF,1);
OUTPUT
CONCLUSION
Hence we studied FIR Filter design using rectangular window method: Lowpass, Highpass,
Bandpass and Bandstop filters on MATLAB
SOFTWARE/HARDWARE REQUIRED:
Octave Online
THEORY:
FIR Filters – 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. This is in contrast to infinite impulse response (IIR) filters, which may have internal
feedback and may continue to respond indefinitely (usually decaying).
Order of filter N
Filter length M=N+1
Window Functions:
Rectangular Window
Abrupt truncation
Hamming and Hann window have tapering towards edges
Hence truncation is less abrupt
narrower transition band
less attenuation in stop band
CODE
clc; clear all;
N = 40; % order
Fc = 1000; % Cutofffreq (HZ)
Fs = 8000; % Sampling freq (HZ)
%% Compare windows
win1 = rectwin(N+1);
win2 = hamming(N+1);
win3 = hann(N+1);
figure;
hold on;
stem(0:N,win1,'markersize',2);
stem(0:N,win2,'markersize',2);
stem(0:N,win3,'markersize',2);
hold off;
legend('Rectangular','Hamming','Hann');
xlabel('Discrete Time,n');
ylabel('window function');
%% Low-pass filter
b1 = fir1(N,2*Fc/Fs,'low',win1);
b2 = fir1(N,2*Fc/Fs,'low',win2);
b3 = fir1(N,2*Fc/Fs,'low',win3);
[h1,w1] = freqz(b1,1,1024,Fs);
[h2,w2] = freqz(b2,1,1024,Fs);
[h3,w3] = freqz(b3,1,1024,Fs);
figure;
hold on;
plot(w1, 20*log10(abs(h1)));
plot(w2, 20*log10(abs(h2)));
plot(w3, 20*log10(abs(h3)));
hold off;
legend('Rectangular','Hamming','Hann');
xlabel('Frequency, Hz');
ylabel('|H(w)|,LPF dB');
OUTPUT
CONCLUSION
Hence we designed FIR Low-pass filter using Rectangular, Hamming and Hann windows.
SOFTWARE/HARDWARE REQUIRED:
Octave Online
THEORY:
IIR Filter:
The infinite impulse response (IIR) filter is a recursive filter in that the output from the filter is
computed by using the current and previous inputs and previous outputs. Because the filter uses
previous values of the output, there is feedback of the output in the filter structure.
Butterworth Filter:
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.
The frequency response of the Butterworth filter is flat in the passband (i.e. a bandpass filter) and
roll-offs towards zero in the stopband. The rate of roll-off response depends on the order of the
filter. The number of reactive elements used in the filter circuit will decide the order of the filter.
Syntax:
[b,a] = butter(n,Wn) returns the transfer function coefficients of an nth-order lowpass digital
Butterworth filter with normalized cutoff frequency Wn.
[n,Wn] = buttord(Wp,Ws,Rp,Rs) returns the lowest order, n, of the digital Butterworth filter
with no more than Rp dB of passband ripple and at least Rs dB of attenuation in the
stopband. Wp and Ws are respectively the passband and stopband edge frequencies of the
filter, normalized from 0 to 1, where 1 corresponds to π rad/sample.
[h,w] = freqz(b,a,n) returns the n-point frequency response vector h and the corresponding
angular frequency vector w for the digital filter with transfer function coefficients stored
in b and a.
plot(w/pi,20*log10(abs(h))) used for plotting only the magnitude(dB) vs freq(Hz) plot.
CODE
clc;
clear all;
close all;
Fs = 8000; %sampling freq
fp= 1500; %passband edge freq
fs= 2000; %stopband edge freq
Ap = 3; %passband ripple
%Filter order
[N,wc] = buttord(2*fp/Fs,2*fs/Fs,Ap,As);
%%plots
[h1,w1]= freqz(b1,a1,1024,Fs);
[h2,w2]= freqz(b2,a2,1024,Fs);
[h3,w3]= freqz(b3,a3,1024,Fs);
figure;
hold on;
plot(w1,20*log10(abs(h1)) );
plot(w2,20*log10(abs(h2)) );%magnitude of H(jw) on y axis
plot(w3,20*log10(abs(h3)) );
hold off;
grid on;
legend('N-5','N','N+5');
xlabel('Frequency,Hz');
ylabel('|H(\omega)|,dB');
OUTPUT
Fig 2. Comparison of different Frequency Responses with Different Orders
CONCLUSION
Successfully studied and designed an IIR Butterworth Filter with minimum order that would
allow specified passband ripple and the specified at least attenuation in stopband, order less than
the minimum order, and more than the minimum order.
We observed that the passband is maximally flat, there are no ripples in pass band and stop band.
The magnitude response is monotonically decreasing. On increasing the order, the transition
band becomes sharper, so we move closer to the ideal filter response.
SOFTWARE/HARDWARE REQUIRED:
Octave Online
THEORY:
Chebyshev Function:
It is a mathematical function used to produce passband, or stopband, ripples constrained within
fixed bounds. There are families of Chebyshev functions based on the amount of ripple such as 1
dB, 2 dB, and 3 dB of ripple.
Chebyshev filters can be designed to have a frequency response with ripples in the passband and
flat passbands (Chebyshev Type I), or flat passbands and ripples in the stopband (Chebyshev
Type II). Chebyshev filters cannot have ripples in both the passband and the stopband.
CODE
clc; clear all;
Fs = 8000; % Sampling Frequency
fp = 1500;
fs = 2000;
Ap = 3;
As = 40;
%% Filter Order
[N1,wc1] = buttord(2*fp/Fs,2*fs/Fs,Ap,As);
[N2,wc2] = cheb1ord(2*fp/Fs,2*fs/Fs,Ap,As);
[N3,wc3] = cheb2ord(2*fp/Fs,2*fs/Fs,Ap,As);
disp('Order of Butterworth Filter:')
disp(N1)
disp('Order of Chebyshev Type I Filter:')
disp(N2)
disp('Order of Chebyshev Type II Filter:')
disp(N3)
%% Filter Design
[b1,a1] = butter(N1,wc1,'low'); %Butterworth
[b2,a2] = cheby1(N2,Ap,wc2,'low'); %Chebyshev Type I LPF
[b3,a3] = cheby2(N3,As,wc3,'low'); %Chebyshev Type II LPF
%% Plots
[h1,w1] = freqz(b1,a1,1024,Fs);
[h2,w2] = freqz(b2,a2,1024,Fs);
[h3,w3] = freqz(b3,a3,1024,Fs);
figure;hold on;
plot(w1,20*log10(abs(h1)),'r');
plot(w2,20*log10(abs(h2)),'k');
plot(w3,20*log10(abs(h3)),'m');
hold off;
xlabel('Frequency, Hz');
ylabel('|H(\omega)|, dB');
title('IIR LPF');
legend('Butterworth','ChebyshevTypeI','Chebyshev TypeII');
axis tight; grid on;
%%
figure;hold on;
plot(w1,20*log10(abs(h1)),'r');
plot(w2,20*log10(abs(h2)),'k');
plot(w3,20*log10(abs(h3)),'m');
hold off;
xlabel('Frequency, Hz');
ylabel('|H(\omega)|, dB');
title('IIR LPF: zoomed in');
legend('Butterworth','ChebyshevTypeI','Chebyshev TypeII');
axis tight;ylim([-60 2]); grid on;
OUTPUT
Order of Butterworth Filter:
12
Order of Chebyshev Type I Filter:
6
Order of Chebyshev Type II Filter:
6
CONCLUSION
Successfully studied and designed Chebyshev Filter of Type I and Type II. For the given values
of Attenuation of pass band, stop band and certain order N, Chebyshev Filter gives Narrower
Transition Band. AlsoChebyshev Filter of Type I has ripples in pass band, while the Chebyshev
Filter of Type II has ripples in the stop band.
SOFTWARE/HARDWARE REQUIRED:
Octave Online
THEORY:
Up Sampler
Up sampling can be synonymous with expansion, or it can describe an entire process of
expansion and filtering (interpolation). When up sampling is performed on a sequence of
samples of a signal or other continuous function, it produces an approximation of the sequence
that would have been obtained by sampling the signal at a higher rate.
Down Sampler
In digital signal processing, down sampling, compression, and decimation are terms associated
with the process of resampling in a multi-rate digital signal processing system. Both down
sampling and decimation can be synonymous with compression, or they can describe an entire
process of bandwidth reduction (filtering) and sample-rate reduction.
CODE
clc; clear all;
%Generate Sinusoid
T = 0.3; %Total Time Duration
fo=5; %Frequency of Sinsuoid
fs=600; %Sampling Frequency
t1 = 0:1/fs:T-1/fs; %Time Vector
y1= sin(2*pi*fo.*t1);
%Plot
figure;
subplot(411); stem(t1,y1,'markersize',1); axis tight;
ylabel('Original');
subplot(412); stem(t1u,y1u,'markersize', 1); axis tight;
ylabel('Interpolation by 4');
subplot(413); stem(t1d,y1d,'markersize', 1); axis tight;
ylabel('Decimate by 4');
subplot(414); stem(t1r,y1r,'markersize', 1); axis tight;
ylabel('Resample by 2/3');
OUTPUT
Fig 3. Original Signal, UpSampled Signal, DownSampled Signal and Re Sampled Signal
CONCLUSION
Upsampling increases the number of signals whereas downsampling decreases the number of
signals and hence analyzed the effects of up-sampler and down-sampler in multi-rate systems.