0% found this document useful (0 votes)
13 views23 pages

MATLAB DSP Practical File

The document is a practical file for a Digital Signal Processing course at Delhi Technological University, detailing various experiments conducted using MATLAB. It includes aims, procedures, results, and conclusions for experiments on signal plotting, smoothing, sampling, DTFT, and DFT. Each experiment is documented with code snippets and visual outputs to demonstrate the results achieved.

Uploaded by

Shabs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views23 pages

MATLAB DSP Practical File

The document is a practical file for a Digital Signal Processing course at Delhi Technological University, detailing various experiments conducted using MATLAB. It includes aims, procedures, results, and conclusions for experiments on signal plotting, smoothing, sampling, DTFT, and DFT. Each experiment is documented with code snippets and visual outputs to demonstrate the results achieved.

Uploaded by

Shabs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DELHI TECHNOLOGICAL

UNIVERSITY

Digital Signal Processing


Practical File
SUBJECT CODE- EC304

Submitted by​:- MD SHAHBAZ KHAN


Roll no.​:- 2K16/EC/076
Section​:- ​D1
Semester​:- 6​ th​​ Sem
Session​:- ​2018-19
INDEX

[Link]. EXPERIMENT DATE SIGNATURE


Experiment:- 01

Aim- ​i) To plot the following signals in MATLAB-


1. δ​(x) 2. Unit step function, u(x)
3. Ramp function, r(x) 4. sin (nw)
5. cos (nw) 6. sinc (nw)
7. Exponential function, e (ax) 8. Exponential function, e (-ax)
9. Sawtooth wave 10. Triangular pulse
11. Rectangular pulse

ii) To perform following operations on discrete signals-


1. Addition 2. Subtraction
3. Multiplication 4. Time shifting
5. Folding 5. Linear convolution
6. Linear convolution with a folded signal
7. Correlation

Software Used​:- Matlab 2018b

Program​:-
i.) ​Plotting of basic Signals
t = -5:0.01:5
y=1
fc = 0.5
a = 0.1
delta = []
unit = []
for x = -5:0.01:5
if(x==0)
delta(y) = 1; %forming delta function
else
delta(y) = 0;
end
if(x>=0)
unit(y) = 1; %forming unit step function
ramp(y) = x; %forming ramp function
else
unit(y) = 0;
ramp(y) = 0;
end
y = y+1;
end
figure(1)
subplot(3,1,1)
plot(t,delta) %plotting delta function
xlabel('Time')
ylabel('Amplitude')
title('Delta function -Shahbaz')
grid on;
subplot(3,1,2)
plot(t,unit) %plotting unit step function
xlabel('Time')
ylabel('Amplitude')
title('Unit step function -Shahbaz')
grid on;
subplot(3,1,3)
plot(t,ramp) %plotting ramp function
xlabel('Time')
ylabel('Amplitude')
title('Ramp function -Shahbaz')
grid on;
figure(2)
subplot(3,1,1)
plot(t,sin(2*pi*fc*t)); %sine function with frequency = 0.1Hz
xlabel('Time')
ylabel('Amplitude')
title('Sine function -Shahbaz')
grid on;
subplot(3,1,2)
plot(t,cos(2*pi*fc*t)); %cosine function with frequency = 0.1Hz
xlabel('Time')
ylabel('Amplitude')
title('Cosine function -Shahbaz')
grid on;
subplot(3,1,3)
plot(t,sinc(2*pi*fc*t)) %sinc function with frequency = 0.1Hz
xlabel('Time')
ylabel('Amplitude')
title('Sinc function -Shahbaz')
grid on;
figure(3)
subplot(2,1,1)
plot(t,exp(a*t)) %exponential function with a = 0.1
xlabel('Time')
ylabel('Amplitude')
title('Exp(at) function -Shahbaz')
grid on;
subplot(2,1,2)
plot(t,exp(-a*t)) %exponential function with a = -0.1
xlabel('Time')
ylabel('Amplitude')
title('Exp(-at) function -Shahbaz')
grid on;
figure(4)
subplot(3,1,1)
plot(t,sawtooth(10*t,0.1)) %sawtooth function
xlabel('Time')
ylabel('Amplitude')
title('Sawtooth function -Shahbaz')
grid on;
subplot(3,1,2)
plot(t,tripuls(t,4)) %triangular function of width 4s
xlabel('Time')
ylabel('Amplitude')
title('Triangular function -Shahbaz')
grid on;
subplot(3,1,3)
plot(t,rectangularPulse(-3,3,t)) %rectangular function of width 6s
xlabel('Time')
ylabel('Amplitude')
title('Rectangular function -Shahbaz')
grid on;

ii.)​ Performing basic operations


t=0:4;
y1=[0 1 2 3 4]; %generating first signal
y2=[-1 4 2 5 2]; %generating second signal
sum=y1+y2; %Addition of given signals
difference=y1-y2; %Subtraction of given signals
product=y1.*y2; %Multiplication of given signals
subplot(2,4,1);
stem(t,y1); %plotting the first signal
grid on;
title('Signal_1 -Shahbaz');
ylabel('Magnitude');
xlabel('Time');
subplot(2,4,2);
stem(t,y2); %plotting the second signal
grid on;
xlim([-1 5]);
title('Signal_2 -Shahbaz');
ylabel('Magnitude');
xlabel('Time');
subplot(2,4,3);
stem(t,sum); %plotting the sum of given signals, yi(x)+y2(x)
grid on;
xlim([-1 5]);
title('Signal_1 + Signal_2 -Shahbaz');
ylabel('Magnitude');
xlabel('Time');
subplot(2,4,4);
stem(t,difference); %plotting the difference of given signals, y1(x)-y2(x)
grid on;
xlim([-1 5]);
title('Signal_1 - Signal_2 -Shahbaz');
ylabel('Magnitude');
xlabel('Time');
subplot(2,4,5);
stem(t+2,y1); %plotting of signal 1 time delayed by 2 units
grid on;
xlim([0 8]);
title('Shifting by 2 sec -Shahbaz');
ylabel('Magnitude');
xlabel('Time');
subplot(2,4,6);
stem(t,product); %plotting the product of given signals, y1(x).*y2(x)
grid on;
xlim([-1 5]);
title('Signal_1 * Signal_2 -Shahbaz');
ylabel('Magnitude');
xlabel('Time');
subplot(2,4,7);
stem(-t,y1);
grid on;
xlim([-5 1]);
title('Folding f(-x) -Shahbaz'); %plotting the folded version of signal 1, y1(-x)
ylabel('Magnitude');
xlabel('Time');
conv_res=conv(y1,y2); %linear convolution of given signals
p=2*t;
subplot(2,4,8);
stem(conv_res); %plot of linear convolution of given signals
grid on;
title(' Linear Convolution of both signals -Shahbaz');
ylabel('Magnitude');
xlabel('Time');
figure;
fold_y2=fliplr(y2); %folded version of signal 2
fold_conv_res=conv(y1,fold_y2); %linear convolution of signal 1 with folded signal 2
subplot(1,2,1);
stem(fold_conv_res); %plotting linear convolution of signal 1 with folded signal 2
grid on;
title('Convolution of y1(x) with folded version of y2(x) -Shahbaz');
ylabel('Magnitude');
xlabel('Time');
corr_res=xcorr(y1,y2); %correlation of given signals
subplot(1,2,2);
stem(corr_res); %plot of correlation of given signals
grid on;
title('Correlation -Shahbaz');
ylabel('Magnitude');
xlabel('Time');

Results​:-
i.) Plotting of various signals was verified by the below output shown.
ii.)The addition, multiplication, shifting of signals and convolution between two signals between
the is verified by the below output shown.

Conclusion​:-
Experiment :- 02

AIM​:-To smooth a signal using moving average filter in MATLAB .

Software Used​:- Matlab 2018b

Program​:-
clc
clear all
R = 50;
d = rand(R,1)-0.5; %generating ‘R’ random numbers as a row vector
m = [Link]R-1; %creating a message signal
s = 2*m.*(0.9.^m); %transmitted message signal
x = s+d'; %received message signal
plot(m,d,'r-',m,s,'b--',m,x,'g--'); %plotting transmitted and received signal
xlabel('Time Index n');
ylabel('Amplitude');
legend('r-','d[n]','b--','s[n]','g--','x[n]');
pause
M = input('Number of input samples = '); %console input for number of samples
b = ones(M,1)/M; %numerator coefficients
y = filter(b,1,x); %smoothing signal by applying average filter
plot(m,d,'r-',m,s,'b--',m,y,'g--'); %plotting the smoothed signal
legend('r-','s[n]','b--','y[n]');
xlabel('Time Index n');
ylabel('Amplitude');
title('Transmitted & Received Signal -Shahbaz')
Result​:-
Smoothing of a given message signal was done using moving average filter algorithm and it was
verified with the below outputs:

For number of input signal = 10


For number of input signal = 19

For number of input signal = 50


Conclusion​:-
​Experiment :- 03

Aim​:- To perform signal sampling, under sampling, oversampling and aliasing.

Software Used​:- Matlab 2018b

Program​:-
fm=10; %Frequency of the message signal
tov=-1:0.005:1; %Sampling frequency, fs=400Hz
mt_ov=sin(2*pi*fm*tov); %Message signal with fm=10Hz; Nyquist frequency, fsn=2*fm=20Hz
subplot(2,1,1);
plot(tov,mt_ov); %Plotting Oversampled signal (fs>=fsn)
grid on;
title('Oversampled signal -Shahbaz');
ylabel('Amplitude');
xlabel('Time');

tus=-1:0.12:1; %Sampling frequency, fs=16.17Hz


mt_us=sin(2*pi*fm*tus); %Message signal with fm=10Hz; Nyquist frequency, fsn=2*fm=20Hz
subplot(2,1,2);
plot(tus,mt_us); %Plotting Undersampled signal (fs<fsn)
grid on;
title('Undersampled signal -Shahbaz');
ylabel('Amplitude');
xlabel('Time');
Result​:-
Oversampling and undersampling of a given message signal was done and verified using the
following output-

Conclusion​:-
Experiment:- 04

Aim​:-​To determine the values of the DTFT of a real sequence described on a rational function in
e​-jω​.
Software Used​:- ​MATLAB
Program​:-
k = input("Number of frequency points = "); %console input for number of frequency points
num = input("Numerator coefficients = "); %console input for the coefficients in numerator
den = input("Denominator coefficients = "); %console input for the coefficients in denominator
w = 0:pi/(k-1):pi;
h = freqz(num,den,w); %calculating the N-point complex frequency response
subplot(2,2,1);
stem(w/pi,real(h)); %plotting the real part
grid on
title('Real Part -Shahbaz');
xlabel('\Omega/\pi');
ylabel('Amplitude');
subplot(2,2,2)
stem(w/pi,imag(h)); %plotting the imaginary part of frequency response
grid on
title('Imaginary Part -Shahbaz');
xlabel('\Omega/\pi');
ylabel('Amplitude');
subplot(2,2,3)
stem(w/pi,abs(h)); %plotting the magnitude of frequency response
grid on
title('Magnitude Spectrum -Shahbaz');
xlabel('\Omega/\pi');
ylabel('Magnitude');
subplot(2,2,4)
stem(w/pi,angle(h)); %plotting the angle of frequency response
grid on
title('Phase Spectrum -Shahbaz');
xlabel('\Omega/\pi');
ylabel('Phase, radians');
Results-
a) X(e​jω​) = (0.008 – 0.033 e​-jω​ +0.05 e​-2jω​ - 0.033 e​-3jω​ + 0.008 e​-4jω​)/(1 + 2.37 e​-jω​ +2.7 e​-2jω​ +
1.6 e​-3jω​ + 0.41 e​-4jω​)

b)​ ​x(n) = u(n) (Discrete Unit step function)


X(e​jω​) = 1/(1- e​-jω​)
c) ​x(n) = (0.2)​n​ u(n)
X(e​jω​) = 1/(1-0.2 e​-jω​)

d) x(n) = ​ᵟ​(n)

X(e​jω​) = 1
e) x(n) = sin(ω​o​n), ω​o =
​ 10 radians

X(e​jω​)​ ​ = (sin(ω​o​) e​-jω​)/(1-2 cos(ω​o​) e​-jω​ + e​-2jω​)

f) x(n) = cos(ω​o​n), ω​o =


​ 10 radians

X(e​jω​)​ ​ = (1 - cos(ω​o​) e​-jω​)/(1-2 cos(ω​o​) e​-jω​ + e​-2jω​)


g) x(n) = e​-jωo n​ , ω​o =
​ radians
jω​ ​ -j(ωo+​ω)​ ​
X(e​ )​ = 1/(1-e​ )

Conclusion:-
Experiment:- 05

Aim​:- To determine the M-point DFT U(k) of the following N-point sequence-
u(n)= 1, 0 ≤ n ≤ N-1
0, otherwise

Software Used​:- Matlab 2018b

Program​:-
N=50;
n=-N:N;
u=(n>=0); % Generating unit step signal

subplot(3,1,1); %Plotting the input discrete unit step function


stem(n,u);
grid on;
ylim([-0.2 1.2]);
title('Unit step function -Shahbaz');
xlabel('k');
ylabel('Amplitude');

M=105;
fft_u=fft(u,M); %fft_u= DFT of the input discrete unit step function
subplot(3,1,2); %Magnitude plot of the DFT, fft_u
stem(abs(fft_u));
grid on;
title('Magnitude Plot -Shahbaz');
xlabel('k');
ylabel('Amplitude');

subplot(3,1,3); %Phase plot of the DFT, fft_u


stem(angle(fft_u));
title('Phase Plot');
xlabel('k');
ylabel('Amplitude');
Result​:-
DFT for a given message was calculated as below-

For M = 105 point DFT

For M = 50 point DFT


For M = 30 point DFT

Conclusion​:-

You might also like