You are on page 1of 7

Generation of DT signals, linear and circular convolution

Exp. No.: 1 Date :

Objective: 1. To generate the following elementary discrete-time signals over the given time interval in MATLAB 1. Unit Sample Sequence [Unit Impulse] 2. Unit Step Sequence 3. Exponential Sequence 4. Ramp Sequence 5. Sine Wave 6. Cosine Wave 7. Square Wave 8. Sinc Wave 2. Perform linear and circular convolution over a finite length discrete-time sequence.

Theory: Students are instructed to write a theory about DT signal generation, Linear and Circular convolutions.

Procedure: Students are instructed to write a step-by-step procedure on how to generate different DT signals in MATLAB and also instructed to write procedure to perform linear and Circular convolutions on finite length DT sequences.

Programs [M-codes] The sample M-codes are given here,

Generation of elementary DT signals


% Program to generate elementary discrete-time signals % Sine signal generation clear all; close all; clc; frequency=1000; % Set the frequency of the signal timeperiod=1/frequency; % Compute the time period amplitude=1; % Set the amplitude of the signal dcoffset=0; % Mention the dc offset value t=0:0.00001:2*timeperiod; % Define the time period the signal out=dcoffset+amplitude*sin(2*pi*frequency*t); %Generate the signal as per the given specifications subplot(4,2,1); plot(t,out); title('Sinusoidal Signal'); xlabel('Time'); ylabel('Amplitude');

% Cosine signal generation clear all; clc; frequency=1000; % Set the frequency of the signal timeperiod=1/frequency; % Compute the time period amplitude=1; % Set the amplitude of the signal dcoffset=0; % Mention the dc offset value t=0:0.00001:2*timeperiod; % Define the time period of the signal out=dcoffset+amplitude*cos(2*pi*frequency*t); % Generate the signal as per the given specifications subplot(4,2,2); plot(t,out); title('Cosine Signal'); xlabel('Time'); ylabel('Amplitude');

% Sinc signal generation clear all; clc; frequency=1000; % Set the frequency of the signal timeperiod=1/frequency; % Compute the time period amplitude=1; % Set the amplitude of the signal dcoffset=0; % Mention the dc offset value t=-timeperiod:0.00001:timeperiod; % Define the time period of the signal out=dcoffset+amplitude*sinc(2*pi*frequency*t); %Generate the signal as per the given specifications subplot(4,2,3); plot(t,out); title('Sinc Signal'); xlabel('Time'); ylabel('Amplitude');

% Square wave generation clear all; clc; frequency=1000; timeperiod=1/frequency; amplitude=1; dcoffset=0; t=0:0.00001:2*timeperiod; out=dcoffset+amplitude*square(2*pi*frequency*t); subplot(4,2,4); plot(t,out); title('Square ylabel('Amplitude');

Signal');

xlabel('Time');

% DT Ramp Signal clear all; clc; dcoffset=10; n=0:20; out=dcoffset+n; subplot(4,2,5); stem(n,out); ylabel('Amplitude');

title('Ramp

Signal');

xlabel('Time');

% Unit Impuse Signal clear all; clc; n=[-5:5]; out=[zeros(1,5), 1, zeros(1,5)]; subplot(4,2,6); stem(n,out); title('Unit ylabel('Amplitude');

Impuse

Signal');

xlabel('Time');

% Unit Step Signal clear all; clc; n=[-5:5]; out=[zeros(1,5), ones(1,6)]; subplot(4,2,7); stem(n,out); ylabel('Amplitude');

title('Unit

Step

Signal');

xlabel('Time');

% Real Exponential Signal clear all; clc; n=[0:20]; a=0.25; %if a<1 - decaying exponential.. if a>1 raising exponential out=a.^n; subplot(4,2,8); stem(n,out); title('Exponential Signal'); xlabel('Time'); ylabel('Amplitude');

Linear Convolution
% Program to find linear convolution of two finite length sequences clear all; clc; x=input('Enter the input sequence '); h=input('Enter the impulse response sequence '); n1=length(x); n2=length(h); N=n1+n2-1; x1=[x zeros(1,N-n1)]; h1=[h zeros(1,N-n2)]; for n=1:N for m=1:N if n>m H(m,n)=0; else H(m,n)=h1(m-(n-1)); end end end y=(H*x1'); disp(y')

Circular Convolution
% Program to perform circular convolution of two finite length sequences clear all; clc; x = input('Enter the input sequence '); h = input('Enter the impulse response sequence '); m=length(x); n=length(h); N=max(m,n); s=m-n; j=1; z=[]; if(s==0) h=[h,zeros(1,s)]; else x=[x,zeros(1,-s)]; h=[h,zeros(1,s)]; end for n=1:N y=0; for i=1:N j=(n-i)+1; if(j<=0) j=N+j; end y=y+(x(i)*h(j)); end z=[z y]; end disp(z)

Numerical/Graphical Output Sample graphical and numerical outputs are shown here. Graphical output - Signal Generation

Numerical Output Linear convolution


'Enter the input sequence ' [1 2 3 4] 'Enter the impulse response sequence ' [4 3 2 1] Linearly Convolved output sequence is [4 11 20 30 20 11 4]

Numerical Output Circular convolution


'Enter the input sequence ' [1 3 6 9] 'Enter the impulse response sequence ' [2 5 7 4] Circularly Convolved output sequence is [101 98 70 73]

Results/Conclusions Students are instructed to write the conclusion (What you have learned) from the above experiments.

Self Exercises Signal Generation


1. Compute and plot the following DT sequences using MATLABs stem function (i) x1[n] = [n-1] + [n+1] + [n-3] + [n] (ii) x2[n] = [[n] - [n-20]] 2. Generate and plot the following DT sequences (i) x1[n] =

(ii)

x2[n] =

3. Consider the following length-7 sequences defined for -3 n 3; x[n] = {3, -2, 0, 1, 4, 5, 2}, y[n] = {0, 7, 1, -3, 4, 9, -2}, w[n] = {-5, 4 3, 6, -5, 0, 1} Generate the following sequences (a) [n] = x[n] + y[n], (d) r[n] = 4.5y[n]. (b) v[n] = x[n] . w[n], (c) s[n] = y[n] w[n], and

Linear Convolution
1b. 1 (i) (ii) (iii) (iv) Consider the following sequences x1[n] = 2[n-1] - 0.5[n-3], x2[n] = -3[n-1] + [n+2], h1[n] = 2[n] + 5[n-1] - 3[n-3], and h2[n] = -[n-2] 0.5[n-1] + 3[n-3],

Determine the following sequences obtained by a linear convolution of a pair of the above sequences: (a) y1[n] = x1[n] * h1[n]

(b) (c) (d) 1b. 2

y2[n] = x2[n] * h2[n] y3[n] = x1[n] * h2[n] y4[n] = x2[n] * h1[n] Let g[n] be a finite-length sequence defined for N1 n N2, with N2 > N1. Likewise, let h[n] be a finite-length sequence defined for M1 n M2, with M2 > M1. Define y[n] = g[n] * h[n]. What is the length of y[n]? What is the range of the index n for which y[n] is defined? Consider the following three sequences x2[n] = [n], x3[n] =

(a) (b) 1b. 3

x1[n] = A (a constant),

Show that x3[n] * x2[n] *x1[n] x2[n] * x3[n] * x1[n]. Note The symbol * represents linear convolution.

Circular Convolution
1. Determine the 4-point circular convolution of the two length-4 sequences g[n] and h[n] given by g[n] = {1, 2, 0, 1}, h[n] = {2, 2, 1, 1}

2. Determine the circular convolution of the following two sequences ge[n] = 3. Determine the periodic sequence and h[n] =

[n] obtained by a periodic convolution of the following

two periodic sequences of period 5 each

[n] =

4. Exercise 1b. 1

You might also like