-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotDFT.m
More file actions
197 lines (148 loc) · 5.48 KB
/
plotDFT.m
File metadata and controls
197 lines (148 loc) · 5.48 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
function [] = plotDFT (signal, handles)
%LOAD SETTINGS
settings = LoadSettings('Settings.json',handles);
sampleFreq = get(handles.dataTable, 'sampleFreq');
showProcessed = get(handles.processedData, 'Value');
showRaw = get(handles.rawData, 'Value');
showMath = get(handles.mathData, 'Value');
enableWindowFunction = get(handles.enableWindowFunction, 'appliedValue');
enableSmoothing = get(handles.enableSmoothingFunction, 'appliedValue');
%fprintf('plotting...\n');
Xp = fft(signal);
Phi = angle(Xp);
Mag = mag2db(abs(Xp));
processedSignal = signal;
if(enableSmoothing)
processedSignal = smooth(signal, settings.SmoothingFunction);
end
if(enableWindowFunction)
processedSignal = applyWindowFunction(signal, settings.WindowFunction);
end
mathSignal = generateMathChannel(signal, processedSignal, handles);
K = [0:1:length(signal)-1];
Kprocessed = [0:1:length(processedSignal)-1];
XpProcessed = fft(processedSignal);
PhiProcessed = angle(XpProcessed);
MagProcessed = mag2db(abs(XpProcessed));
XpMath = fft(mathSignal);
PhiMath = angle(XpMath);
MagMath = mag2db(abs(XpMath));
%TIME DOMAIN PLOT
axes(handles.timeDomainPlot);
cla;
hold on;
if showRaw == 1
plot(K, signal, '-og', 'MarkerEdgeColor', 'Blue', 'MarkerFaceColor','Blue','Color','Blue', 'MarkerSize', 2);
legend('Raw data');
end
if showProcessed == 1
plot(Kprocessed, processedSignal, '-og', 'MarkerEdgeColor', 'Red', 'MarkerFaceColor','Red','Color','Red', 'MarkerSize', 2);
legend('Processed data');
end
if showMath == 1
plot(Kprocessed, mathSignal, '-og', 'MarkerEdgeColor', 'Green', 'MarkerFaceColor','Green','Color','Green', 'MarkerSize', 2);
legend('Math data');
end
if showRaw == 0 && showProcessed == 1 && showMath == 1
legend('Processed data', 'Math data');
end
if showRaw == 1 && showProcessed == 0 && showMath == 1
legend('Raw data', 'Math data');
end
if showRaw == 1 && showProcessed == 1 && showMath == 0
legend('Raw data', 'Processed data');
end
if showRaw == 1 && showProcessed == 1 && showMath == 1
legend('Raw data', 'Processed data','Math data');
end
hold off;
title('Time Domain');
xlabel('k');
ylabel('x[k]');
grid on;
K = K .* ((2*pi*sampleFreq)/length(K));
Kprocessed = Kprocessed .* ((2*pi*sampleFreq)/length(Kprocessed));
%MAGNITUDE PLOT
axes(handles.frequencyMagnitudePlot);
cla;
% if(showRaw == 1)
% plot(K, Mag, 'o', 'MarkerEdgeColor','Blue', 'MarkerFaceColor','Blue', 'MarkerSize', 2);
% legend('Raw data');
% hold on;
% end
%
% if(showProcessed == 1)
% plot(K, MagProcessed, 'o', 'MarkerEdgeColor','Red', 'MarkerFaceColor','Red', 'MarkerSize', 2);
% legend('Processed data');
% end
hold on;
if showRaw == 1
plot(K, Mag, 'og', 'MarkerEdgeColor', 'Blue', 'MarkerFaceColor','Blue','Color','Blue', 'MarkerSize', 2);
legend('Raw data');
end
if showProcessed == 1
plot(Kprocessed, MagProcessed, 'og', 'MarkerEdgeColor', 'Red', 'MarkerFaceColor','Red','Color','Red', 'MarkerSize', 2);
legend('Processed data');
end
if showMath == 1
plot(Kprocessed, MagMath, 'og', 'MarkerEdgeColor', 'Green', 'MarkerFaceColor','Green','Color','Green', 'MarkerSize', 2);
legend('Math data');
end
if showRaw == 0 && showProcessed == 1 && showMath == 1
legend('Processed data', 'Math data');
end
if showRaw == 1 && showProcessed == 0 && showMath == 1
legend('Raw data', 'Math data');
end
if showRaw == 1 && showProcessed == 1 && showMath == 0
legend('Raw data', 'Processed data');
end
if showRaw == 1 && showProcessed == 1 && showMath == 1
legend('Raw data', 'Processed data','Math data');
end
hold off;
title('Magnitude [dB]');
xlabel('\omega');
ylabel('|X_p [k]|');
grid on;
%PHASE PLOT
axes(handles.frequencyPhasePlot);
cla;
hold on;
% if(showRaw == 1)
% plot(K, Phi, 'o', 'MarkerEdgeColor', 'Blue', 'MarkerFaceColor','Blue', 'MarkerSize', 2);
% hold on;
% legend('Raw data');
% end
%
% if(showProcessed == 1)
% plot(K, PhiProcessed, 'o', 'MarkerEdgeColor', 'Red', 'MarkerFaceColor','Red', 'MarkerSize', 2);
% legend('Processed data');
% end
if showRaw == 1
plot(K, Phi, 'og', 'MarkerEdgeColor', 'Blue', 'MarkerFaceColor','Blue','Color','Blue', 'MarkerSize', 2);
legend('Raw data');
end
if showProcessed == 1
plot(Kprocessed, PhiProcessed, 'og', 'MarkerEdgeColor', 'Red', 'MarkerFaceColor','Red','Color','Red', 'MarkerSize', 2);
legend('Processed data');
end
if showMath == 1
plot(Kprocessed, PhiMath, 'og', 'MarkerEdgeColor', 'Green', 'MarkerFaceColor','Green','Color','Green', 'MarkerSize', 2);
legend('Math data');
end
hold off;
if showRaw == 1 && showProcessed == 0 && showMath == 1
legend('Raw data', 'Math data');
end
if showRaw == 1 && showProcessed == 1 && showMath == 0
legend('Raw data', 'Processed data');
end
if showRaw == 1 && showProcessed == 1 && showMath == 1
legend('Raw data', 'Processed data','Math data');
end
title('Phase[°]');
xlabel('\omega');
ylabel('Arg(X_p [k])');
grid on;
end