-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPractice.m
78 lines (64 loc) · 1.44 KB
/
Practice.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
clc; #... Clear command line
clear all; #... Clear variables
close all; #... Clear figures
#... Discrete Fourier Transform
xInput = [1 2 3 4 5 6 7]
nPoint = length(xInput); #... How many point dft
n = 0:nPoint-1 #... Time(n)
xLength = length(xInput);
subplot(3,2,1);
stem(n, xInput, ".");
if(nPoint < xLength)
error("Can not perform dft. Point should be >= length");
endif
xInput = [xInput zeros(1,nPoint-xLength)];
for k = 0:nPoint-1
xD(k+1) = 0;
for n = 0:nPoint-1
xD(k+1) = xD(k+1)+xInput(n+1)*exp(-i*2*pi*k*n/nPoint);
endfor
endfor
#... Ploting magnitude
n = 0:nPoint-1;
subplot(3,2,2);
plot(n, abs(xD));
axis tight;
title("Magnitude spectrum");
#... Ploting phase
n = 0:nPoint-1
subplot(3,2,3);
plot(n, angle(xD));
axis tight;
title("phase spectrum");
#... Inverse Discrete Fourier Transform
for k = 0:nPoint-1
xInv(k+1) = 0;
for n = 0:nPoint-1
xInv(k+1) = xInv(k+1)+xD(n+1)*exp(i*2*pi*n*k/nPoint);
endfor
xInv(k+1) = xInv(k+1)/nPoint;
endfor
#... Ploting Inverse DFT
n = 0:nPoint-1
subplot(3,2,4);
stem(n, xInv, ".");
axis tight;
title("IDFT");
#... Time shifting property
m = 2;
for k = 0:nPoint-1
xD(k+1) = xD(k+1)*exp(i*2*pi*k*m/nPoint);
endfor
for k = 0:nPoint-1
xInv(k+1) = 0;
for n = 0:nPoint-1
xInv(k+1) = xInv(k+1)+xD(n+1)*exp(i*2*pi*n*k/nPoint);
endfor
xInv(k+1) = xInv(k+1)/nPoint;
endfor
#... Ploting shifted Inverse DFT
n = 0:nPoint-1
subplot(3,2,5);
stem(n, xInv, ".");
axis tight;
title("Shifter IDFT");