You are on page 1of 25

L

Aim: To perform shifting operation on Discrete Time Signal.


Apparatus/Software used: MATLAB 2019a
Theory:
Time shifting is, as the name suggests, the shifting of a signal in
time. This is done by adding or subtracting an integer quantity of
the shift to the time variable in the function. Subtracting a fixed
positive quantity from the time variable will shift the signal to the
right (delay) by the subtracted quantity, while adding a fixed
positive amount to the time variable will shift the signal to the left
(advance) by the added quantity.

Program:
t = 1:1.5:20;
x = 2*sin(t);
subplot (3,1,1)
stem(t,x)
xlabel("Time Period")
ylabel("Amplitude")
title ("Original Signal")
subplot (3,1,2)
stem (t-5, x)
xlabel("Time Period")
ylabel("Amplitude")
title ("Signal Shifted Left")
subplot (3,1,3)
stem (t+5, x)
xlabel("Time Period")
ylabel("Amplitude")
title ("Signal Shifted Right")

Output:

Result: Thus, we have performed shifting operation on Discrete


Time Signal.
L

Aim- To perform Unit step, Unit Impulse and Ramp Function on


Discrete Time Signal.
Apparatus/Software used: MATLAB 2019a
Theory-
Unit Step Function
Unit step function is denoted by u(t). It is defined as u(t) = {10t⩾0t<0{1t⩾00t<0

● It is used as best test signal.


● Area under the unit step function is unity.

Unit Impulse Function


Impulse function is denoted by δ(t). and it is defined as δ(t) = {10t=0t≠0{1t=00t≠0
∫∞−∞δ(t)dt=u(t)∫−∞∞δ(t)dt=u(t)
δ(t)=du(t)dtδ(t)=du(t)dt
Ramp Signal

Ramp signal is denoted by r(t), and it is defined as r(t) = {t0t⩾0t<0{tt⩾00t<0

∫u(t)=∫1=t=r(t)∫u(t)=∫1=t=r(t)
u(t)=dr(t)dtu(t)=dr(t)dt
Area under the unit ramp is unity.

Program-
t=-2:1:2;
y= [zeros (1,2), ones (1,1), zeros (1,2)];
subplot (2,2,1);
stem(t,y);
ylabel("d(n)");
xlabel("unit impulse");
n=input ("Enter n values");
t=0:1: n-1;
y1=ones (1, n);
subplot (2,2,2);
stem(t, y1);
ylabel("Amplitude");
xlabel("unit step");

n=input ("Enter n values");


t=0:1: n-1;
subplot (2,2,3);
stem(t,t);
ylabel("Amplitude");
xlabel("unit ramp");

n=input ("Enter length of exponential seq");


t=0:1: n-1;
a=input ("Enter a value");
y2=exp(a*t);
subplot (2,2,4);
stem(t, y2);
xlabel("Exponential fun");
ylabel("Amplitude");

Output-

Result- Thus we have performed Unit step, Unit Impulse and


Ramp Function on Discrete Time Signal.
L

Aim- To study the Computation of N Point DFT of a given


sequence and to plot magnitude and phase spectrum
Apparatus/Software used: MATLAB 2019a
Theory-
The DFT of a discrete-time signal x(n) is a finite duration
discrete frequency sequence. The DFT sequence is denoted by
X(k). The DFT is obtained by sampling one period of the Fourier
transform X(W) of the signal x(n) at a finite number of frequency
points. This sampling is conventionally performed at N equally
spaced points in the period 0 ≤w≤2w or at wk = 2πk/N; 0 ≤ k≤ N –
1. We can say that DFT is used for transforming discrete-time
sequence x(n) of finite length into discrete frequency sequence
X(k) of finite length. The DFT is important for two reasons. First it
allows us to determine the frequency content of a signal, that is to
perform spectral analysis. The second application of the DFT is to
perform filtering operations in the frequency domain. Let x(n) be a
discrete-time sequence with Fourier transform X(W), then the
DFT of x(n) denoted by X(k) is defined as
X(k) = X(w)
The DFT of x(n) is a sequence consisting of N samples of X(k).
The DFT sequence starts at k = 0, corresponding to w = 0, but
does not include k = N corresponding to w = 2π (since the sample
at w = 0 is the same as the sample at w = 2 π). Generally, the
DFT is defined as follows
Program-
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-

Result- Thus we have studied the Computation of N Point DFT of


a given sequence and to plot magnitude and phase spectrum
L

Aim-To study the Linear Convolution of given two Sequences.


Apparatus/Software used: MATLAB 2019a
Theory-
Convolution is used to find out the output of an LTI system. If
the response of the system to the impulse signal is known(h(t)h(t)
or h(n)h(n)), then the response to any other input to the system
can be found out by convolving the input signal with impulse
response.
Linear convolution is the basic operation to calculate the output
for any linear time invariant system given its input and its impulse
response.

Program-
clc;
clear all;
close all;
x1 = input("Enter First sequence x1(n)[] : ");
t1 = input("Enter Origin location Of Sequence x1 : ");
x2 = input("Enter Second sequence x2(n)[] : ");
t2 = input("Enter Origin location Of Sequence x2 : ");
l1 = length(x1); %length of sequence x1
l2 = length(x2); %length of sequence x2
ln = l1+l2-1; %length of convoluted sequence
y = conv(x1,x2); % performing convolution using conv() function
a = t1+l1-1;
t = t1:a;
subplot(3,1,1);
stem(t,x1);
xlabel("Time");
ylabel("Amplitude");
title("x1");
a = t2+l2-1;
t = t2:a;
subplot (3,1,2);
stem (t, x2);
xlabel("Time");
ylabel("Amplitude");
title('x2');
tn = t1+t2;
a = tn+ln-1;
t = tn:a;
subplot (3,1,3);
disp("Convoluted Sequence ");
disp(y); % For printing the convoluted output in MATLAB
command window
stem(t,y); % For plotting the convoluted output in MATLAB graph
window
xlabel('Time');
ylabel("Amplitude");
title ("Convoluted Sequence");
Output-

Result- Thus we have performed the linear convolution of two


Sequences.
L

Aim-To Study the Circular Convolution of two given sequences.


Apparatus/Software used: MATLAB 2019a
Theory –
Circular convolution, also known as cyclic convolution, is a
special case of periodic convolution, which is the convolution of two
periodic functions that have the same period. Periodic convolution
arises, for example, in the context of the discrete-time Fourier
transform (DTFT). In particular, the DTFT of the product of two
discrete sequences is the periodic convolution of the DTFTsof the
individual sequences. And each DTFT is a periodic summation of
a continuous Fourier transform function (see DTFT
§ Definition).

Program-
clc;
g=input("Enter the sequence 1:");
h=input("Enter the sequence 2:");
N1=length(g);
N2=length(h);
N=max(N1,N2);
N3=N1-N2;
if(N3>0)
h=[h,zeros(1,N3)];
else
g=[g,zeros(1,-N3)];
end
for n=1:N;
y(n)=0;
for i=1:N;
j=n-i+1;
if(j<=0)
j=N+j;
end
y(n)=[y(n)+(g(i)*h(j))];
end
end
disp("The resultant is");y
subplot(2,1,1);
stem(y);
xlabel("N->");
ylabel("Amplititude->");
Output-

Result- Thus we performed Circular convolution of two


Sequences.
L

Aim-To find Impulse Response of the system with Transfer


Function.
Apparatus/Software used: MATLAB 2019a
Theory –
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. In
both cases, the impulse response describes the reaction of theIn
signal processing, the impulse response, or impulse response
function (IRF), of a dynamic system is its system as a function of
time (or possibly as a function of some other independent variable
that parameterizes the dynamic behavior of the system).

Program-
clear;
clc;
close all;
Fs = 100e6;
R1 = 2500;
R2 = 50;
C = 30*1e-12;
H = [];
for i = 1:100
f = -Fs/2+(Fs/100)*i; %f=-Fs/2:Fs/128:Fs/2
x(i) = f;
H(i) = R2/(R1/(1+(2*pi*f*C*R1*j)+R2));
end
Habs=abs(H);
plot(x,Habs);
y=abs(ifft((H)));

Output-

Result- Thus we found the Impulse Response of the system with


Transfer Function.
L

Aim-To Perform the Realization of Unit Sample Sequence.


Apparatus/Software used: MATLAB 2019a
Theory –
Discrete-time systems can act on discrete-time signals in
ways similar to those found in analog signals and systems.
Because of the role of software in discrete-time systems, many
more different systems can be envisioned and "constructed" with
programs than can be with analog signals. In fact, a special class
of analog signals can be converted into discrete-time signals,
processed with software, and converted back into an analog
signal, all without the incursion of error. For such signals, systems
can be easily produced in software, with equivalent analog
realizations difficult, if not impossible, to design.

Program-
clc;
% Generate a vector from -10 to 20
n = -10:20;
% Generate the unit step sequence
s = [zeros(1,10) ones(1,21)];
% Plot the unit step sequence
stem(n,s);
xlabel("Time index n");
ylabel("Amplitude");
title("Unit Step Sequence");
axis([-10 20 0 1.2]);

Output-

Result- Thus we Performed the Realization of Unit Sample


Sequence.
L

Aim- To Design and Implementation of FIR Butterworth Filter


Apparatus/Software used: MATLAB 2019a
Theory –
A Butterworth filter is a type of signal processing filter
designed to have a frequency response as flat as possible in the
passband. Hence the Butterworth filter is also known as
“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.
he inductor and capacitor are reactive elements used in filters.
But in the case of Butterworth filter only capacitors are used. So,
the number of capacitors will decide the order of the filter.
Here, we will discuss the Butterworth filter with a low pass filter.
Similarly, the high pass filter can be designed by just changing the
position of resistance and capacitance.

Program-
1) Lowpass Butterworth Filter
fc = 300;
fs = 1000;
[b,a] = butter(6,fc/(fs/2));
freqz(b,a)
dataIn = randn(1000,1);
dataOut = filter(b,a,dataIn);
2) Bandstop Butterworth Filter
[b,a] = butter(3,[0.2 0.6],'stop');
freqz(b,a)
dataIn = randn(1000,1);
dataOut = filter(b,a,dataIn);

3) Highpass Butterworth Filter


[z,p,k] = butter(9,300/500,'high');
sos = zp2sos(z,p,k);
fvtool(sos,'Analysis','freq')

4) Bandpass Butterworth Filter

[A,B,C,D] = butter(10,[500 560]/750);


d = designfilt('bandpassiir','FilterOrder',20, ...
'HalfPowerFrequency1',500,'HalfPowerFrequency2',560, ...
'SampleRate',1500);
sos = ss2sos(A,B,C,D);
fvt = fvtool(sos,d,'Fs',1500);
legend(fvt,'butter','designfilt')
Output-
1) Lowpass Butterworth Filter

2) Bandstop Butterworth Filter

3) High Pass Butterworth Filter


4) Bandpass Butterworth Filter

Result- Thus we Designed and Implemented FIR Butterworth


Filter.

You might also like