-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab_8.m
106 lines (71 loc) · 1.33 KB
/
lab_8.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
close all;
clc;
clearvars;
%%
t = linspace(-0.5,0.5,1000);
x = cos(2*pi*50*t);
N = 1024;
Ftime = linspace(-500, 500, N);
X1 = zeros(1,N);
for f=1:N
for i=1:length(t)
X1(f) = X1(f) + (x(i)*exp(-1i*2*pi*Ftime(f)*t(i)))*(1/1000);
end
end
X2 = fft(x,N) / N;
abs_shift_X1 = abs(X1);
abs_shift_X2 = fftshift(abs(X2));
figure;
subplot(3,1,1);
plot(t,x);
grid on
title("x(t)");
xlabel("Time ")
ylabel("X")
subplot(3,1,2);
plot(Ftime,abs_shift_X1);
grid on
title ("Manual Forier Transform");
xlabel("Frequency");
ylabel("X1");
subplot(3,1,3);
plot(Ftime,abs_shift_X2);
grid on
title ("Automatic Forier Transform");
xlabel("Frequency");
ylabel("X2");
%%
close all;
clc;
clearvars;
t = sym('t');
f = sym('f');
y = 0.5*(sign(t+0.5)-sign(t-0.5));
z = subs(y,t,-2*t);
Y = fourier(y,f);
Z = fourier(z,f);
figure;
subplot(2,2,1);
fplot(t,y,[-1,1]);
grid on
title("y(t)");
xlabel("Time ")
ylabel("y")
subplot(2,2,2);
fplot(f,Y,[-40,40]);
grid on
title ("Forier Transform of Y");
xlabel("Frequency");
ylabel("Y");
subplot(2,2,3);
fplot(t,z,[-1,1]);
grid on
title ("z(t)");
xlabel("Frequency");
ylabel("z");
subplot(2,2,4);
fplot(f,Z,[-40,40]);
grid on
title ("Forier Transform of Z");
xlabel("Frequency");
ylabel("Z");