0% found this document useful (0 votes)
30 views9 pages

Important

The document contains MATLAB code for plotting various signals including sine, cosine, exponential, unit step, unit ramp, unit impulse, and square functions. It also contains code for computing the discrete Fourier transform (DFT) of a sequence and plotting the magnitude and phase spectra.

Uploaded by

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

Important

The document contains MATLAB code for plotting various signals including sine, cosine, exponential, unit step, unit ramp, unit impulse, and square functions. It also contains code for computing the discrete Fourier transform (DFT) of a sequence and plotting the magnitude and phase spectra.

Uploaded by

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

clc

clear all
close all
x = 0: 0.1 : 2*pi
y = sin(x)
subplot(2,2,1)
plot(y)
title('continuous sine function')
xlabel('time')
ylabel('amplitude')
subplot(2,2,2)
stem(y)
title('discrete sine function')
xlabel('time')
ylabel('amplitude')
z = cos(x)
w = exp(x)
subplot(2,2,3)
stem(z)
title('cosine function')
xlabel('time')
ylabel('amplitude')
subplot(2,2,4)
stem(w)
title('exponential function')
xlabel('time')
ylabel('amplitude')

clc
clear all
close all
for n = 1 : 10
if n>5
u(n) = 1
else
u(n) = 0
end
stem(u)
end
xlabel('time')
ylabel('amplitude')
title('unit step function')

clc
clear all
close all
for n = 1 : 10
if n >= 0
r(n) = n
else
r(n) = 0
end
stem(r)
end
xlabel('time')
ylabel('amplitude')
title('unit ramp function')

clc
clear all
close all
for n = 1 : 10
if n == 5
i(n) = 1
else
i(n) = 0
end
stem(i)
end
xlabel('time')
ylabel('amplitude')
title('unit impulse function')

clc
clear all
close all
for d = 1 : 10
if d >= 1 && d < 6
s(d) = 1
else
s(d) = 0
end
d=d+1
end
l = length(s)
p = 0 : l-1
stem(p,s)
xlabel('time')
ylabel('amplitude')
title('square function')

clc
clear all
close all
x = input('enter the input sequence')
l = length(x)
k=1
for w = 0 : 0.2 :2*pi
X(k) = 0
for n = 0 : l-1
X(k) = X(k) + (x(n+1)*(exp(-j*w*n)))
end
k=k+1
end
w = 0 : 0.2 : 2*pi
subplot(1,2,1)
plot(w,abs(X))
title('magnitude plot')
xlabel('frequency(w)')
ylabel('|X(w)|')
subplot(1,2,2)
plot(w,angle(X))
title('phase plot')
xlabel('frequency(w)')

ylabel('angle(X(k))')

clc
clear all
close all
N = input('enter the dft points')
x = input('enter the input sequence')
l = length(x)
for k = 1 : N
X(k) = 0
for n = 0 : l-1
X(k) = X(k) + (x(n+1)*(exp((-j*2*pi*k*n)/N)))
end
k=k+1
end
k = 1 :N
subplot(1,2,1)
stem(k,abs(X))
title('magnitude plot')
xlabel('k')
ylabel('|X(k)|')
subplot(1,2,2)
stem(k,angle(X))

title('phase plot')
xlabel('k')
ylabel('angle(X(k))')

enter the dft points8


N=
8
enter the input sequence[1 2 3 4 0 0 0 1]
x=
1

nter the dft points16


N=
16
enter the input sequence[1 2 3 4 0 0 0 1]

x=
1

You might also like