0% found this document useful (0 votes)
8 views7 pages

DFT Perfect

The document contains MATLAB code for various signal processing techniques including the Discrete Fourier Transform (DFT), Inverse Discrete Fourier Transform (IDFT), linear convolution (both using and not using the CONV function), circular convolution, and Z-transform. It also includes the formation of unit impulse, unit step, ramp, and parabolic signals. Each section displays input sequences, output sequences, and their respective plots.

Uploaded by

palsayan553
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views7 pages

DFT Perfect

The document contains MATLAB code for various signal processing techniques including the Discrete Fourier Transform (DFT), Inverse Discrete Fourier Transform (IDFT), linear convolution (both using and not using the CONV function), circular convolution, and Z-transform. It also includes the formation of unit impulse, unit step, ramp, and parabolic signals. Each section displays input sequences, output sequences, and their respective plots.

Uploaded by

palsayan553
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

DFT of a Sequence

x=[1,1,1]

N=8;

l=length(x);

x=[x,zeros(1,(N-l))]

X=zeros(1,N)

subplot(2,2,1)

stem(0:N-1,x)

title('Input Sequence')

xlabel('n---->')

ylabel('x[n]')

W = exp(-1i*2*pi/N)

for k=1:N

for n=1:N

X(k)=X(k)+x(n)*(W^((n-1)*(k-1)))

end

end

disp('the DFT is: ');

disp(X)

subplot(2,2,2)

stem(0:N-1,real(X))

title('Real Part of DFT')

xlabel('k---->')

ylabel('X[k]')

p=abs(X)

subplot(2,2,3)

stem(0:N-1,p)

title('Magnitude of DFT')

xlabel('k---->')

ylabel('|X[k]|')

q=angle(X)

subplot(2,2,4)

stem(0:N-1,q)

title('Phase of DFT')

xlabel('k---->')

ylabel('<X[k]')
IDFT of a Sequence
clc

clf

X=[12,-4+4i,-4,-4-4i];

N=length(X);

x=zeros(1,N);

subplot(2,2,1)

stem(0:N-1,X)

title('Input Sequence')

xlabel('k---->')

ylabel('X[k]')

W=exp(1i*2*pi/N)

for n=1:N

for k=1:N

x(n)=x(n)+X(k)*(W^((n-1)*(k-1)))

end

end

x=x/N

disp('The IDFT is: ')

disp(x)

subplot(2,2,2)

stem(0:N-1,real(x))

title('real part of IDFT')

xlabel('n---->')

ylabel('x[n]')

p=abs(x)

subplot(2,2,3)

stem(0:N-1,p)

title('Magnitude of IDFT')

xlabel('n---->')

ylabel('|x[n]|')

q=angle(x)

subplot(2,2,4)

stem(0:N-1,q)

title('Phase of IDFT')

xlabel('n---->') ylabel('<x[n]')
Linear Convolution using CONV function
x1=[1,5,3,2,0]

n1=length(x1)

a=0:1:n1-1

subplot(3,1,1)

stem(a,x1)

xlabel('n------>')

ylabel('x1[n]')

title('Input Sequence')

x2=[4,2,1,5]

n2=length(x2)

b=0:1:n2-1

subplot(3,1,2)

stem(b,x2)

xlabel('n------>')

ylabel('x2[n]')

title('Impulse Response')

y=conv(x1,x2)

c=0:1:(n1+n2-2)

subplot(3,1,3)

stem(c,y)

xlabel('n------>')

ylabel('y[n]')

title('Output Sequence')
Linear Convolution without using CONV function

x=[1,5,3,2,0]

h=[4,2,1,5]

n1=length(x)

n2=length(h)

subplot(3,1,1)

stem(0:n1-1,x)

title('Input Sequence')

xlabel('n---->')

ylabel('x[n]')

subplot(3,1,2)

stem(0:n2-1,h)

title('Impulse Response')

xlabel('n---->')

ylabel('h[n]')

N=n1+n2-1

y=zeros(1,N)

for i=1:n1

for j=1:n2

y(i+j-1)=y(i+j-1)+x(i)*h(j)

j=j+1

end

i=i+1

end

disp(y)

subplot(3,1,3)

stem(0:N-1,y)

title('Output Sequence')

xlabel('n---->')

ylabel('y[n]')
Circular Convolution
clear all

close all

clc

x1=[1,-1,-2,3,-1];

x2=[1,2,3];

N1=length(x1);

N2=length(x2);

N=max(N1,N2);

x1=[x1,zeros(1,N-N1)];

x2=[x2,zeros(1,N-N2)];

y=zeros(1,N);

for k=0:N-1

for n=0:N-1

y(n+1)=y(n+1)+[x1(k+1)*(x2(mod(n-k,N)+1))];

end

end

disp(y)

subplot(3,1,1)

a=0:N-1;

stem(a,x1,'m')

xlabel("Time------->");

ylabel("Amp-------->");

title('x[n]');

subplot(3,1,2)

b=0:N-1;

stem(b,x2,'m')

xlabel("Time------->");

ylabel("Amp-------->");

title('h[n]');

subplot(3,1,3)

c=0:N-1;

stem(c,y,'m')

xlabel("Time------->");

ylabel("Amp-------->");

title('y[n]');
Z transform without using function

clear all

close all

clc

x=[1,2,3,4,5];

lx=length(x);

syms z;

ans=0;

for n=0:lx-1

ans=ans+x(n+1)*z^(-n);

end

disp(ans)

Z transform using function

clear all

close all

clc

syms n z a;

f1=n;

y1=ztrans(f1);

disp(y1)

f2=a^n;

y2=ztrans(f2);

disp(y2)

f3=n*(a^n);

y3=ztrans(f3);

disp(y3)
Formation of Unit Impulse, Unit Step, Ramp Signal and
Parabolic Signal

clear all

close all

clc

n=-5:5

y=[zeros(1,5),ones(1,1),zeros(1,5)]

subplot(2,2,1)

stem(n,y)

title('Unit Impulse')

xlabel('n----->')

ylabel('Del(n)')

y=(n>=0)

subplot(2,2,2)

stem(n,y)

title('Unit Step')

xlabel('n----->')

ylabel('U(n)')

y=n

subplot(2,2,3)

stem(n,y)

title('Ramp Signal')

xlabel('n----->')

ylabel('R(n)')

y = (n .* n / 2) .* (n >= 0)

subplot(2,2,4)

stem(n,y)

title('Parabolic Signal')

xlabel('n----->')

ylabel('P(n)')

You might also like