DSP File 37-1
DSP File 37-1
Submitted to : Submitted by :
Mr. Sandeep Sheoran Name : Siddharth Singh
Assistant Professor Branch : ECE – 3
ECE Department Enrol. No: 04496302820
MSIT Class Sr. No. : 37
INDEX
Aim : Write a program to Plot unit step, Unit Impulse, ramp, exponential, Sine & cosine
Signal in both continuous and discrete form.
Software used : MATLAB 7.0
Program :
clc;
clear all;
close all;
x=-pi:0.2:pi;
% Sine Function
subplot(2,6,1);
plot(x,sin(x));
xlabel('time');
ylabel('amplitude');
title('sine continuous');
subplot(2,6,2);
stem(x,sin(x));
xlabel('time');
ylabel('amplitude');
title('sine discrete');
% Cosine Function
subplot(2,6,3);
1
plot(x,cos(x));
xlabel('time');
ylabel('amplitude');
title('cos continuous');
subplot(2,6,4);
stem(x,cos(x));
xlabel('time');
ylabel('amplitude');
title('cos discrete');
% Unit Step Function
t=0:1:10;
y=ones(1,11);
subplot(2,6,5);
plot(t,y);
xlabel('time');
ylabel('amplitude');
title('step continuous');
subplot(2,6,6);
stem(t,y);
xlabel('time');
ylabel('amplitude');
title('step discrete');
2
% Ramp Function
n=0:1:10;
a=1:1:11;
subplot(2,6,7);
plot(n,a);
xlabel('time');
ylabel('amplitude');
title('ramp continuous');
subplot(2,6,8);
stem(n,a);
xlabel('time');
ylabel('amplitude');
title('ramp discrete');
% Exponential Function
m=-pi:0.1:pi;
b=exp(m);
subplot(2,6,9);
plot(m,b);
xlabel('time');
ylabel('amplitude');
title('exp continuous');
subplot(2,6,10);
stem(m,b);
3
xlabel('time');
ylabel('amplitude');
title('exp discrete');
% Impulse Function
p=-3:1:3;
c=[0,0,0,1,0,0,0];
subplot(2,6,11);
plot(p,c);
xlabel('time');
ylabel('amplitude');
title('Impulse continuous');
subplot(2,6,12);
stem(p,c);
xlabel('time');
ylabel('amplitude');
title('Impulse discrete');
Result : Unit step, Unit Impulse, ramp, exponential, Sine & cosine Signal in both
continuous and discrete form is plotted using MATLAB7.0.
4
Output
5
Experiment 2
Aim : Write a program to find Convolution.
6
subplot(3,1,2);
stem(N2,x2);
grid on;
xlabel('N2----->');
ylabel('amplitude- - - ->');
title('second sequence');
N3=0:N-1;
subplot(3,1,3);
stem(N3,Yn);
grid on;
xlabel('N3----->');
ylabel('amplitude- - - ->');
title('output convolution sequence');
Output
7
Output
8
Program : (B) Circular Convolution
clc;
close all;
clear all;
x=input('enter the first sequence x(n)');
h=input('enter the second sequence h(n)');
m=length(x);
n=length(h);
N=max(m,n);
x=[x,zeros(1,N-m)];
h=[h,zeros(1,N-n)];
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)+x(i)*h(j)];
end
end
n=0:N-1;
subplot(3,1,1);
disp('first sequence x is : ');
disp(x);
stem(n,x);
xlabel('n');
ylabel('x(n)');
9
title('first sequence');
grid on;
subplot(3,1,2);
disp('second sequence h is :');
disp(h);
stem(n,h);
xlabel('n');
ylabel('h(n)'); title('second
sequence : '); grid on;
subplot(3,1,3);
disp('convoluted sequence y(n) is :');
disp(y);
stem(n,y);
xlabel('n');
ylabel('y(n)');
title('circular convoluted sequence ');
grid on;
Result : Circular Convolution has been performed using MATLAB7.0.
Output
10
Output
11
Experiment 3
Aim : Write a program to perform Linear convolution using circular convolution and
Vice Versa.
Software used : MATLAB 7.0
Program : (A) Linear convolution using circular convolution.
clc;
clear all;
close all;
x1 = input(‘Enter the 1st Sequence: ’ );
x2=input(‘Enter the 2nd Sequence: ’);
l1=length(x1);
l2=length (x2);
n=l1+l2-1;
subplot(3,1,1);
stem(x1);
xlabel(‘Time’);
ylabel(‘Amplitude’);
title(‘first Sequence’);
subplot(3,1,2);
stem(x2);
xlabel(‘Time’);
ylabel(‘Amplitude’);
title(‘second Sequence’);
12
if l1>l2
l3=l1-l2;
x2=[x2,zeros(1,l3)];
elseif l2>l1
l3=l2-l1;
x1=[x1,zeros(1,l3)];
end
n=l1+l2-1;
f=count(x1,x2,n);
disp(‘The convoluted sequence is:’);
disp(f);
Subplot(3,1,3);
stem(f);
xlabel(‘Time’);
ylabel(‘Amplitude’);
title (‘Convoluted Sequence:’);
Result : Linear convolution using circular convolution has been performed successfully.
13
Output
14
(B) Circular convolution using Linear convolution.
clc;
clear all;
close all;
n=0:1:n1-1; subplot
(3, 1, 1); stem(n,x);
xlabel(‘Time’);
ylabel(‘Amplitude’);
title(‘first
Sequence’);
n=n1+n2-1;
if n1>n2
n3=n1-n2;
h=[h,zeros(1,n3)];
elseif n2>n1
n3=n2-n1;
x=[x,zeros(1,n3)];
end
x=[x,zeros(1,n-n1)];
15
h=[h,zeros(1,n-n2)];
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)+x(i)*h(j)];
end
end
disp(‘circular convolution of x&h is:’);
disp(y);
Subplot(3,1,3);
stem(y);
xlabel(‘Time’);
ylabel(‘Amplitude’);
title (‘Circular Convoluted Sequence’);
Result : Circular convolution using Linear convolution has been performed successfully.
16
Output
17
Experiment 4
clc;
clear all;
close all;
xn= input(‘Enter the Sequence x(n): ’); % Get 8 point sequence
ln=length(xn); % from user for 8 point DFT
xk=zeros(1,ln); % Get 16 point sequence
ixk=zeros(1,ln); % from user for 16 point DFT
for k=0:ln-1
for n=0:ln-1
t =0:ln-1;
Subplot(2,2,1);
stem(t,xn);
xlabel(‘Time’);
18
ylabel(‘Amplitude’);
title (‘input Sequence’);
magnitude=abs(xk);
subplot (2, 2, 2);
stem(t,magnitude);
xlabel(‘k’);
ylabel(‘amplitude’);
title(‘Magnitude response’);
magnitude=abs(xK);
phase=angle(xk);
subplot(2, 2, 3);
stem(t, phase);
xlabel(‘k’);
ylabel('amplitude’);
title(‘Phase response’);
for k=0:ln-1
for n=0:ln-1
19
ylabel(‘amplitude’);
title (‘IDFT sequence’);
Result : 8 point DFT ,16 point DFT and their magnitude, phase plot and inverse DFT has
been performed successfully.
20
Output
for 8 point DFT
21
Output
for 16 point DFT
22
Experiment 5
23
subplot(3,1,2);
stem(y);
title('DFT of shifted sequence');
W=fft(f);
subplot(3,1,3);
stem(W);
title('LDFT of shifted sequence by function');
disp(W);
Command window :
24
Output
25
(B) Circular fold of a sequence
clc;
close all;
clear all;
X=input('Enter the sequence');
a=length(X);
n=1:1:a;
subplot(2, 1, 1);
stem(n,X);
xlabel('number of samples');
ylabel('amplitude');
title('Input signal');
m=-a:1:-1;
y = X (a-n+1); subplot
(2,1,2); stem(m,y);
xlabel('number of
samples');
ylabel('amplitude');
title('folded signal');
display(X); display(y);
display(n);
display(m);
26
Command window
27
Output
28