-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcase2_nonparametric_current.m
177 lines (143 loc) · 4.93 KB
/
case2_nonparametric_current.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
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
% ===========================================================
% NON-PARAMETRIC ESTIMATION: CURRENT SIGNAL
% ===========================================================
% This scripts carries out a Welch-based parametric estimation
% using a PMU-recorded current signal for forced oscillation
% identification.
%
% Last modification: 02/06/2023 by SADR.
clc
clear
close all
% Loading given data
load('data\sysid_power_case2.mat');
%% Step 0: Visualization
% ---- Setting up plotting parameters
width = 8;
height = 6;
fig = figure('Renderer', 'opengl', 'Position', [10 10 width*100 height*100]);
set(0, 'DefaultLineLineWidth', 1.5);
set(0,'DefaultAxesFontSize', 18)
set(0,'DefaultTextFontSize', 18)
set(0, 'DefaultTextFontName', 'Times')
set(0, 'DefaultAxesFontName', 'Times')
subplot(211)
plot(time, Im(:, 5), 'color', '#191970')
xlim([0, max(time)])
title('Current from Bus 5')
xlabel('Time (s)')
ylabel('$|I|$ (A)', 'interpreter', 'latex')
xline(t_event, 'color', 'red', 'linewidth', 2, 'linestyle', '--')
subplot(212)
plot(time, Im(:, 13), 'color', '#191970')
xlim([0, max(time)])
title('Current from Bus 13')
xlabel('Time (s)')
ylabel('$|I|$ (A)', 'interpreter', 'latex')
xline(t_event, 'color', 'red', 'linewidth', 2, 'linestyle', '--')
exportgraphics(fig, 'results/fig_case2_Im-time-plot.pdf', ...
'ContentType', 'vector', 'BackGroundColor', 'none');
%% Step 1: Detrending
% ---- Extracting current signals during the oscillation
y1 = Im(1:end-800, 7);
N1 = size(y1, 1);
t1 = ts:ts:N1*ts;
y2 = Im(1:end-800, 10);
N2 = size(y2, 1);
t2 = ts:ts:N2*ts;
y1 = detrend(y1);
y2 = detrend(y2);
% ---- Plotting detrended signal during the event
width = 8;
height = 6;
fig = figure('Renderer', 'opengl', 'Position', [10 10 width*100 height*100]);
set(0, 'DefaultLineLineWidth', 1.5);
set(0,'DefaultAxesFontSize', 18)
set(0,'DefaultTextFontSize', 18)
set(0, 'DefaultTextFontName', 'Times')
set(0, 'DefaultAxesFontName', 'Times')
subplot(211)
plot(t1, y1, 'color', '#191970')
xlim([0, max(t1)])
title('Current from Bus 7')
xlabel('Time (s)')
ylabel('$|I|$ (A)', 'interpreter', 'latex')
xline(t_event, 'color', 'red', 'linewidth', 2, 'linestyle', '--')
subplot(212)
plot(t2, y2, 'color', '#191970')
xlim([0, max(t2)])
title('Current from Bus 10')
xlabel('Time (s)')
ylabel('$|I|$ (A)', 'interpreter', 'latex')
xline(t_event, 'color', 'red', 'linewidth', 2, 'linestyle', '--')
exportgraphics(fig, 'results/fig_case2_Im-detrend.pdf', ...
'ContentType', 'vector', 'BackGroundColor', 'none');
%% Step 2: Analyzing Signal Whiteness
% ---- Settings for autocorrelation plots
width = 8;
height = 6;
fig = figure('Renderer', 'opengl', 'Position', [10 10 width*100 height*100]);
set(0, 'DefaultLineLineWidth', 1.5);
set(0,'DefaultAxesFontSize', 18)
set(0,'DefaultTextFontSize', 18)
set(0, 'DefaultTextFontName', 'Times')
set(0, 'DefaultAxesFontName', 'Times')
subplot(211)
autocorr(y1, 'NumLags', round(N1/4));
title('$\sigma_{y_1y_1}\left[\ell\right]$', 'interpreter', 'latex')
subplot(212)
autocorr(y2, 'NumLags', round(N2/4));
title('$\sigma_{y_2y_2}\left[\ell\right]$', 'interpreter', 'latex')
exportgraphics(fig, 'results/fig_case2_Im-autocorr.pdf', ...
'ContentType', 'vector', 'BackGroundColor', 'none');
%% Step 3: Welch-based Power Spectral Density (PSD) estimation
% ---- Window-size
Nfft = [1024, 2048, 5012];
linestyle = {'-', '-', '-', '-'};
color = {'#191970', '#6495ED', '#00BFFF', '#ADD8E6'};
% ---- Settings for PSD plots
width = 8;
height = 12;
fig = figure('Renderer', 'opengl', 'Position', [10 10 width*100 height*100]);
set(0, 'DefaultLineLineWidth', 2);
set(0,'DefaultAxesFontSize', 18)
set(0,'DefaultTextFontSize', 18)
set(0, 'DefaultTextFontName', 'Times')
set(0, 'DefaultAxesFontName', 'Times')
for i=length(Nfft):-1:1
subplot(211)
% ---- PSD estimation using Welch method
[Pyy1, f] = pwelch(y1, Nfft(i), [], Nfft(i), fs);
plot(f, 10*log10(Pyy1), linestyle{i}, 'color', color{i}, 'DisplayName', ...
"$N_{FFT}$ = " + string(Nfft(i)))
xlim([0, fs/2])
hold on
if i==1
xlabel('$f$ [Hz]', 'interpreter', 'latex');
ylabel('$10 \log_{10}\Vert \hat{S}_{y_1y_1}^2(f)\Vert$', ...
'Interpreter', 'latex');
title('Welch-based PSD Estimation of $y_1$ ($|I_{7}|$)', ...
'Interpreter','latex');
lgd = legend('interpreter', 'latex');
lgd.NumColumns = 4;
lgd.Location = 'southoutside';
end
subplot(212)
[Pyy2, f] = pwelch(y2, Nfft(i), [], Nfft(i), fs);
plot(f, 10*log10(Pyy2), linestyle{i}, 'color', color{i}, 'DisplayName', ...
"$N_{FFT}$ = " + string(Nfft(i)))
xlim([0, fs/2])
hold on
if i==1
xlabel('$f$ [Hz]', 'interpreter', 'latex');
ylabel('$10 \log_{10}\Vert \hat{S}_{y_2y_2}^2(f)\Vert$', ...
'Interpreter', 'latex');
title('Welch-based PSD Estimation of $y_2$ ($|I_{10}|$)', ...
'Interpreter','latex');
lgd = legend('interpreter', 'latex');
lgd.NumColumns = 4;
lgd.Location = 'southoutside';
end
end
exportgraphics(fig, 'results/fig_case2_Im-PSD.pdf', ...
'ContentType', 'vector', 'BackGroundColor', 'none');