Skip to content

Commit a675775

Browse files
authored
Merge pull request #177 from upb-lea/dct
fix missing RMS value in case of vector with a timestep of zero is given
2 parents 440275c + 0a99f84 commit a675775

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

femmt/functions_reluctance.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,9 @@ def max_value_from_value_vec(*args):
536536

537537
return tuple(peak_list)
538538

539-
540539
def phases_deg_from_time_current(time_vec: list, *args):
541540
"""
542-
Return the phases_deg of the peaks.
541+
Return the phases_deg of the peaks. To rebuild the signal, use cosine instead of sine.
543542
544543
:param time_vec: time vector with time steps
545544
:type time_vec: list
@@ -1145,7 +1144,7 @@ def resistance_litz_wire(core_inner_diameter: float, window_w: float, window_h:
11451144
# return R = rho * l / A
11461145
return total_turn_length / litz_wire_effective_area / sigma_copper
11471146

1148-
def i_rms(time_current_matrix: np.array) -> float:
1147+
def i_rms(time_current_matrix: np.ndarray) -> float:
11491148
"""
11501149
RMS calculation from a time-current-vector.
11511150
@@ -1154,17 +1153,23 @@ def i_rms(time_current_matrix: np.array) -> float:
11541153
:return: rms current
11551154
:rtype: float
11561155
"""
1156+
if not isinstance(time_current_matrix, np.ndarray):
1157+
time_current_matrix = np.array(time_current_matrix)
1158+
11571159
time = time_current_matrix[0]
11581160
current = time_current_matrix[1]
11591161

1162+
time_unique, index = np.unique(time, return_index=True)
1163+
current_unique = current[index]
1164+
11601165
square_integral_sum = 0
11611166

11621167
# set up function
1163-
for count in np.arange(np.shape(time_current_matrix)[1] - 1):
1168+
for count in np.arange(np.shape(current_unique)[0] - 1):
11641169
# figure out linear equation between points
1165-
y_axis = current[count]
1166-
delta_time = time[count + 1] - time[count]
1167-
delta_current = current[count + 1] - current[count]
1170+
y_axis = current_unique[count]
1171+
delta_time = time_unique[count + 1] - time_unique[count]
1172+
delta_current = current_unique[count + 1] - current_unique[count]
11681173
gradient = delta_current / delta_time
11691174

11701175
# calculate solution of (partly) square integral
@@ -1175,7 +1180,7 @@ def i_rms(time_current_matrix: np.array) -> float:
11751180
square_integral_sum += square_integral
11761181

11771182
# return "mean" and "root" to finalize rms calculation
1178-
return np.sqrt(square_integral_sum / time[-1])
1183+
return np.sqrt(square_integral_sum / time_unique[-1])
11791184

11801185
def calc_skin_depth(frequency: float, material_name: str = "Copper", temperature: float = 100) -> float:
11811186
"""

0 commit comments

Comments
 (0)