-
Notifications
You must be signed in to change notification settings - Fork 0
/
exp3.txt
78 lines (78 loc) · 2.81 KB
/
exp3.txt
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
% Sampling theorem in time domain
tfinal = 0.01;
t = 0 : 0.0001 : 0.01;
xanalog = cos(2*pi*400*t) + cos(2*pi*700*t); subplot(4, 1, 1);
plot(t, xanalog, 'r-'); xlabel("time");
ylabel("amplitude"); title("analog signal");
% critical sampling (fs = 2*fm)
fs = 1400;
tsamp = 0 : 1/fs : tfinal;
xsampled = cos(2*pi*400*tsamp) + cos(2*pi*700*tsamp); subplot(4, 1, 2);
plot(tsamp, xsampled, 'b*-');
xlabel("time");
ylabel("amplitude");
title("Critical sampling");
% under sampling (fs < 2*fm)
fs = 1400;
tsamp = 0 : 1/fs : tfinal;
xsampled = cos(2*pi*400*tsamp) + cos(2*pi*700*tsamp); subplot(4, 1, 3);
plot(tsamp, xsampled, 'b*-');
xlabel("time");
ylabel("amplitude");
title("Under sampling");
% over sampling (fs > 2*fm)
fs = 2000;
tsamp = 0 : 1/fs : tfinal;
xsampled = cos(2*pi*400*tsamp) + cos(2*pi*700*tsamp); subplot(4, 1, 4);
plot(tsamp, xsampled, 'b*-');
xlabel("time");
ylabel("amplitude");
title("Over sampling");
FREQUENCY DOMAIN
% Sampling theorem in frequency domain
tfinal = 0.01;
t = 0 : 0.00001 : tfinal;
xanalog = cos(2*pi*400*t) + cos(2*pi*700*t);
%plotting the analog signal
figure;
subplot(4, 1, 1); plot(t, xanalog); xlabel("time"); ylabel("amplitude"); title("Analog signal");
% Critical sampling (fs = 2*fm)
fs = 1400;
tsamp = 0 : 1/fs : 13/fs;
xsampled = cos(2*pi*400*tsamp) + cos(2*pi*700*tsamp); xsampled_DFT = abs(fft(xsampled));
xsampled_length = 0 : (length(xsampled_DFT) - 1);
subplot(4, 1, 2);
stem(100 * xsampled_length, xsampled_DFT); xlabel("frequency");
ylabel("magnitude"); title("Critical sampling");
xreconstructed = ifft(fft(xsampled)); subplot(4, 1, 3);
plot(tsamp, xreconstructed, "b*-"); xlabel("time");
ylabel("amplitude");
title("Critical sampling");
% Under sampling (fs < 2*fm)
fs = 700;
tsamp = 0 : 1/fs : 6/fs;
xsampled = cos(2*pi*400*tsamp) + cos(2*pi*700*tsamp); xsampled_DFT = abs(fft(xsampled));
xsampled_length = 0 : (length(xsampled_DFT) - 1);
subplot(4, 1, 4);
stem(100 * xsampled_length, xsampled_DFT); xlabel("frequency");
ylabel("magnitude"); title("Under sampling");
xreconstructed = ifft(fft(xsampled));
figure;
subplot(4, 1, 1); plot(t, xanalog); xlabel("time"); ylabel("amplitude");
title("analog signal (400Hz + 700 Hz)");
subplot(4, 1, 2);
plot(tsamp, xreconstructed, "b*-"); xlabel("time");
ylabel("amplitude");
title("Under sampling (fs < 2*fm)");
% Over sampling (fs > 2*fm)
fs = 2000;
tsamp = 0 : 1/fs : 19/fs;
xsampled = cos(2*pi*400*tsamp) + cos(2*pi*700*tsamp); xsampled_DFT = abs(fft(xsampled));
xsampled_length = 0 : (length(xsampled_DFT) - 1);
subplot(4, 1, 3);
stem(100 * xsampled_length, xsampled_DFT); xlabel("frequency");
ylabel("magnitude"); title("Over sampling");
xreconstructed = ifft(fft(xsampled)); subplot(4, 1, 4);
plot(tsamp, xreconstructed, "b*-"); xlabel("Time");
ylabel("Amplitude");
title("Oversampling (fs > 2fm)");