0% found this document useful (0 votes)
8 views

DSP_{1-6a}[1]

Uploaded by

akshatsaxena2008
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

DSP_{1-6a}[1]

Uploaded by

akshatsaxena2008
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 28

EXPERIMENT – 1

Aim : Write a MATLAB program to graphically represent the basic signals.

SOFTWARE Used : MATLAB R2013a

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);

Enrollment no.- 08315002822 Name- Jiya Arora


ylabel('amplitude');

Enrollment no.- 08315002822 Name- Jiya Arora


xlabel('time');
title('discrete exponential');

% 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');

Enrollment no.- 08315002822 Name- Jiya Arora


title('continuous step');

Enrollment no.- 08315002822 Name- Jiya Arora


% Continuous Ramp
n= 0:1:10;
x= n;
subplot(4,3,9);
plot(n,x);
ylabel('amplitude');
xlabel('time');
title('continuous ramp');

% 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');

Enrollment no.- 08315002822 Name- Jiya Arora


Experiment – 02
Aim : Write a program to compute N point DFT of a given sequence and to plot
magnitude and phase spectrum.

Software Used : MATLAB R2013a

8-point DFT
Code :
clc;

clear

all;

close

all;

xn=input('Enter the sequence x(n): ');

% Get 8 point sequence from user for 8 point DFT or 16 point sequence from user for 16
point DFT

In=length(xn);

% find the length of the sequence

xk=zeros(1,ln);

% initialize an array of same size as that of input

ixk=zeros(1,In);

% DFT of the sequence

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;

Enrollment no.- 08315002822 Name- Jiya Arora


% Plotting input sequence

t=0:In-1;

subplot(2,2,1);

Enrollment no.- 08315002822 Name- Jiya Arora


stem(t,xn);

ylabel('Amplitude')

xlabel('Time');

title('Input

Sequence');

% Find the magnitudes and phases of individual DFT

points magnitude=abs(xk); % plot the magnitude

response t=0:In-1;

subplot(2,2,2);

stem(t,

magnitude);

ylabel

('Amplitude');

xlabel ('K');

title('Magnitude Response');

% phases of individual DFT points

phase angle(xk);

% plot the magnitude sequence t=0:In-1;

subplot(2,2,3)

stem(t,phase)

; ylabel

('Phase');

xlabel ('K');

title ('Phase Response');

Enrollment no.- 08315002822 Name- Jiya Arora


% IDFT of the sequence

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;

Enrollment no.- 08315002822 Name- Jiya Arora


% code block to plot the input sequence

t=0:In-1;

subplot(2,2,4);

stem(t,ixk);

ylabel ('Amplitude');

xlabel ('Time Index');

title ('IDFT

sequence');

-------------------------------

Output :

Enrollment no.- 08315002822 Name- Jiya Arora


Experiment – 03
Aim : To implement Time Shifting and time reversal property of
DFT.
Software Used : MATLAB R2013a

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;

Enrollment no.- 08315002822 Name- Jiya Arora


subplot(2,1,
1); stem(x);
title(„Input
sequence‟);
xlabel(„time index‟);
ylabel(„amplitude‟);

Enrollment no.- 08315002822 Name- Jiya Arora


subplot(2,1,
2);
stem(xn0);
title(“delayed
sequence”);
xlabel(„Time index‟);
ylabel(„amplitude‟);
figure;
w=0:pi/xn:pi*(xn-
1)/xn;
X=fft(x,length(w));
Xn0=fft(xn0,length(
w)); s=exp(-
j*w*n)*X;

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‟);

Enrollment no.- 08315002822 Name- Jiya Arora


Command Window :

Enrollment no.- 08315002822 Name- Jiya Arora


Outputs :

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');

Enrollment no.- 08315002822 Name- Jiya Arora


figure;
G = X(mod(-n,N)+1);

Enrollment no.- 08315002822 Name- Jiya Arora


g = ifft(G)

subplot(2,1,2);
stem(abs(g));
title('reversed
output');
xlabel('time
index');
ylabel('amplitude');

Outputs :

Enrollment no.- 08315002822 Name- Jiya Arora


Experiment – 04
Aim : To find linear convolution of two given sequences.

Software Used : MATLAB R2013a

Code :
clc;

clear

all;

close

all;

x1=input('enter the input sequence : ');

x2=input('enter the response sequence ');

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

1); grid on;

xlabel('n1')

ylabel('amplitude')

; title('input

Enrollment no.- 08315002822 Name- Jiya Arora


sequence');

n2=0:M-1;

subplot(3,1,2);

stem(n2,x

2); grid on;

Enrollment no.- 08315002822 Name- Jiya Arora


xlabel('n2');

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 :

Enrollment no.- 08315002822 Name- Jiya Arora


Output :

Enrollment no.- 08315002822 Name- Jiya Arora


Experiment – 05
Aim : To find circular convolution of two given sequences.

Software Used : MATLAB R2013a

Code :
clc;

clear

all;

close

all;

x=input('enter the input sequence:

'); h=input('enter the response

sequence: '); l1=length(x);

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);

Enrollment no.- 08315002822 Name- Jiya Arora


disp('the values of y

are: '); disp(y);

subplot(3,1,1);

stem(x);

xlabel('n1');

ylabel('amplitud

e');

Enrollment no.- 08315002822 Name- Jiya Arora


title('input sequence');

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 :

Enrollment no.- 08315002822 Name- Jiya Arora


Output :

Enrollment no.- 08315002822 Name- Jiya Arora


Experiment – 06
a) Aim: To perform linear convolution from circular convolution.

Software used : MATLAB R2013a

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');

x2=input('Enter the response sequence');


subplot(3,1,2);
l2=length(x2);
stem(x2);
xlabel('Time');
ylabel('Amplitude');
title('Second 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);

Enrollment no.- 08315002822 Name- Jiya Arora


stem(f);

Enrollment no.- 08315002822 Name- Jiya Arora


xlabel('Time');
ylabel('Amplitude');
title('Convoluted sequence');

Command Window :

Output :

Enrollment no.- 08315002822 Name- Jiya Arora

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy