Вы находитесь на странице: 1из 7

17BEC0357 LAB TASK 1

ECE2006 – Digital Signal Processing L31+L32


Objective

To solve the given problem statements in MATLAB

i. Generate a switched Sinusoidal signal. This is achieved by multiplying a square waveform and
a sinusoidal waveform.
fs = 300;
t = 0:1/fs:1;
offset = 1;
x1 = sin(2*pi*100*t);
x2 = offset + square(2*pi*10*t);
a. Let’s assume the frequency of the square waveform is 3 KHz, with an amplitude of 1 volt
peak-to-peak and offset of 0.3V.Let’s also assume the frequency of the sin () signal is 5 KHz
with an amplitude of 2 V peak-to-peak and no offset.
b. Using subplots show all three signals.

ii. Using MATLAB, generate unit impulse function ( ), unit step sequence u(n) from -10 to 20
time indices and compute the following sequences.
a. x1(n)=u(n) – u(n-3)+ 2− 5
b. x2(n)= 0.5 ( − 3)+u(n) - u(n+5)

iii. Using MATLAB, perform the convolution between input x(n) and impulse response h(n) to
obtain the response of LTI system y(n) in the time domain without using the inbuilt function
‘conv’ and also verify the same using ‘conv’.

Algorithm

Problem 1:
1) Generation of Sinusoidal Signal according to given parameters.
2) Generation of Square signal According to given parameters.
3) Formation of Switched Sinusoidal Signal by Multiplication of two previously
Generated Signals.
4) Plotting all these 3 signals on MATLAB.

Problem 2:
1) Generation of unit impulse signal, unit step sequence for the given parameters.
2) Changing the time parameter to generate functions values at given values of
‘time’.
3) Putting the value & plotting them according to the given problem statement

Problem 3:
1) Generation of impulse response using previous question algorithm.
2) Taking input from user
3) Performing Convolution by picking elements from initial point in first sequence &
last in second sequence & multiplying them.
4) Performing Time Shift by moving to next iterative loop and then adding the
product from repeating step 3.
5) Keep on doing this till completion of loop
PROGRAM-1

clc
clear all
close all
fs=20000;
t=0:1/fs:0.02;
shift=0.3;
x1=1*sin(2*pi*5000*t);
x2=shift+0.5*square(2*pi*3000*t);
figure
subplot(3,1,1);
plot(t,x1);
xlabel('time');
subplot(3,1,2);
plot(t,x2)
xlabel('time');
subplot(3,1,3);
plot(t,x1.*x2)
xlabel('time');

Published with MATLAB® R2019a

1
PROGRAM-2

t=-10:1:20;
imp=[zeros(10,1);1;zeros(20,1)];
subplot(4,1,1)
stem(t,imp)
title('impulse function')
imp=[zeros(10,1);ones(21,1)];
subplot(4,1,2)
stem(t,imp)
title('step function')
imp=[zeros(10,1);ones(21,1)]-
[zeros(13,1);ones(18,1)]+2*[zeros(15,1);1;zeros(15,1)];
subplot(4,1,3)
stem(t,imp)
title('x1(n)')
imp=0.5*[zeros(13,1);1;zeros(17,1)]+[zeros(10,1);ones(21,1)]-
[zeros(5,1);ones(26,1)];
subplot(4,1,4)
stem(t,imp)
title('x2(n)')

Published with MATLAB® R2019a

1
PROGRAM-3

close all
clearvars
x=input('Enter x: ')
%x=sin(2*pi*0.1.*(1:1:11));
h=[1 0 0 0 0 0 0 0];
m=length(x);
n=length(h);
X=[x,zeros(1,n)];
H=[h,zeros(1,m)];
for i=1:n+m-1
Y(i)=0;
for j=1:m
if(i-j+1>0)
Y(i)=Y(i)+X(j)*H(i-j+1);
else
end
end
end
Z=conv(x,h);
figure;
subplot(4,1,1); stem(x, '-b^'); xlabel('n');
ylabel('x[n]'); grid on;
subplot(4,1,2); stem(h, '-ms');
xlabel('n'); ylabel('h[n]'); grid on;
subplot(4,1,3); stem(Y, '-ro');
ylabel('Y[n]'); xlabel('----->n'); grid on;
title('Convolution of Two Signals without conv
function'); subplot(4,1,4); stem(Z, '-ro');
ylabel('Y[n]'); xlabel('----->n'); grid on;
title('Convolution of Two Signals Using conv function');

1
Published with MATLAB® R2019a

Experimental result & inference

1) Learnt about performing Convolution without using inbuilt function as well as


using inbuilt function
2) Generation of Unit Step, Unit impulse signal & Switched Sinusoidal Function

Вам также может понравиться