DSP_{1-6a}[1]
DSP_{1-6a}[1]
DSP_{1-6a}[1]
Program : Outputs :
clc ;
close all;
% Discrete Impulse
n= -10:1:10;
x= *zeros(1,10), ones(1,1) , zeros(1,10) +;
subplot(4,3,1);
stem(n,x);
ylabel('amplitude');
xlabel('time');
title('discrete impulse');
% Discrete Step
n= 0:1:10;
x= *ones(1,1) , ones(1,10) +;
subplot(4,3,2);
stem(n,x);
ylabel('amplitude');
xlabel('time');
title('discrete step');
% Discrete Ramp
n= 0:1:10;
x= n;
subplot(4,3,3);
stem(n,x);
ylabel('amplitude');
xlabel('time');
title('discrete ramp');
% Discrete Exponential
n= -pi:0.2:pi;
x= exp(n);
subplot(4,3,4);
stem(n,x);
% Discrete Sine
n= -pi:0.2:pi;
x= sin(n);
subplot(4,3,5);
stem(n,x);
ylabel('amplitude');
xlabel('time');
title('discrete sine');
% Discrete Cosine
n= -pi:0.2:pi;
x= cos(n);
subplot(4,3,6);
stem(n,x);
ylabel('amplitude');
xlabel('time');
title('discrete cosine');
% Continuous Impulse
n= -10:1:10;
x= *zeros(1,10), ones(1,1) , zeros(1,10) +;
subplot(4,3,7);
plot(n,x);
ylabel('amplitude');
xlabel('time');
title('continuous impulse');
% Continuous Step
n= 0:1:10;
x= *ones(1,1) , ones(1,10) +;
subplot(4,3,8);
plot(n,x);
ylabel('amplitude');
xlabel('time');
% Continuous Exponential
n= -pi:0.2:pi;
x=exp(n);
subplot(4,3,10);
plot(n,x);
ylabel('amplitude');
xlabel('time');
title('continuous exponential');
% Continuous Sine
n= -pi:0.2:pi;
x= sin(n);
subplot(4,3,11);
plot(n,x);
ylabel('amplitude');
xlabel('time');
title('continuous sine');
% Continuous Cosine
n= -pi:0.2:pi;
x= cos(n);
subplot(4,3,12);
plot(n,x);
ylabel('amplitude');
xlabel('time');
title('continuous cosine');
8-point DFT
Code :
clc;
clear
all;
close
all;
% Get 8 point sequence from user for 8 point DFT or 16 point sequence from user for 16
point DFT
In=length(xn);
xk=zeros(1,ln);
ixk=zeros(1,In);
for k=0:In-1
for n=0:In-1
xk(k+1)=xk(k+1)+
(xn(n+1)*exp((i)*2*pi*k*n/ln)); end;
end;
t=0:In-1;
subplot(2,2,1);
ylabel('Amplitude')
xlabel('Time');
title('Input
Sequence');
response t=0:In-1;
subplot(2,2,2);
stem(t,
magnitude);
ylabel
('Amplitude');
xlabel ('K');
title('Magnitude Response');
phase angle(xk);
subplot(2,2,3)
stem(t,phase)
; ylabel
('Phase');
xlabel ('K');
for n=0:In-1
for k=0:In-
ixk(n+1)=ixk(n+1)+
(xk(k+1)*exp(i*2*pi*k*n/In)); end;
end;
ixk=ixk/I
n;
t=0:In-1;
subplot(2,2,4);
stem(t,ixk);
ylabel ('Amplitude');
title ('IDFT
sequence');
-------------------------------
Output :
Time Shifting :
Code :
clc;
clear
all;
close
all;
x=input(“Enter the input
sequence”); n=input(“Enter the
delayed integer”); x1=length(x);
xn=x1+
n; for
i=1:xn;
if(i<=n)
xn0(i)=0
;
else xn0(i)=x(i-
n); end;
end;
subplot(2,1,1);
stem(abs(Xn0));
title(„DFT of the delayed
sequence‟); xlabel(„time index‟);
ylabel(„amplitude‟);
subplot(2,1,2);
stem(abs(s));
title(„DFT of the input
sequence‟); xlabel(„time
index‟); ylabel(„amplitude‟);
Time Reversal :
Code :
n = 0:N-1;
x = [1 1 2 2 3 3 4 4];
X = fft(x);
subplot(2,1,
1); stem(x);
title('Input
sequence');
xlabel('time
index');
ylabel('amplitude');
subplot(2,1,2);
stem(abs(g));
title('reversed
output');
xlabel('time
index');
ylabel('amplitude');
Outputs :
Code :
clc;
clear
all;
close
all;
L=length(x1);
M=length(x
2); N=L+M-
1;
y=conv(x1,x2);
disp(‘the values of y
: ‘); disp(y);
n1=0:L-1;
subplot(3,1,1);
stem(n1,x
xlabel('n1')
ylabel('amplitude')
; title('input
n2=0:M-1;
subplot(3,1,2);
stem(n2,x
ylabel('amplitude');
title('response
sequence');
n=0:N-1;
subplot(3,1,3);
stem(n,yn
); grid on;
xlabel('n')
ylabel('amplitude');
title('output
sequence');
-------------------------------
Command Window :
Code :
clc;
clear
all;
close
all;
l2=length(
h);
n=max(l1,l
2); if l1>l2
l3=l1-l2;
h=[h,zeros(1,l
3)];
else if
l2>l1
l3=l2-
l1;
x=[x,zeros(1,l
3)]; end
y=cconv(x,h,n);
subplot(3,1,1);
stem(x);
xlabel('n1');
ylabel('amplitud
e');
subplot(3,1,2);
stem(h);
xlabel('n2');
ylabel('amplitud
e');
title('response sequence');
subplot(3,1,3);
stem(y);
xlabel('n');
ylabel('amplitud
e');
title('output sequence');
------------------------------------------
Command Window :
Code :
clc;
clear all;
close all;
x1=input('Enter the input sequence');
subplot(3,1,1);
l1=length(x1);
stem(x1);
xlabel('Time');
ylabel('Amplitude');
title('First sequence');
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=cconv(x1,x2,n);
disp('The convolute sequence is : ');
disp(f);
subplot(3,1,3);
Command Window :
Output :