modified: .DS_Store

modified:   .gitignore
	new file:   __pycache__/convert_teacher_csv.cpython-314.pyc
	new file:   __pycache__/evaluation_studio.cpython-314.pyc
	new file:   convert_teacher_csv.py
	new file:   downloads/Non_TMD/free_vib/data_converted_free.csv
	new file:   downloads/TMD/val/data_converted_tmd.csv
	new file:   evaluation_studio.py
	new file:   scripts_2/__pycache__/__init__.cpython-314.pyc
	new file:   scripts_2/__pycache__/signal_utils.cpython-314.pyc
	new file:   scripts_2/__pycache__/task3_identify.cpython-314.pyc
	new file:   scripts_3/__pycache__/__init__.cpython-314.pyc
	new file:   scripts_3/__pycache__/task4_predict_freq.cpython-314.pyc
	modified:   scripts_3/task4_predict_freq.py
	new file:   scripts_4/__pycache__/__init__.cpython-314.pyc
	modified:   scripts_4/__pycache__/adapter.cpython-314.pyc
This commit is contained in:
CrbnsCat10n
2026-05-07 12:48:31 +08:00
parent 79f3de05f7
commit d2dde4f557
16 changed files with 127259 additions and 2 deletions

Binary file not shown.

View File

@@ -10,6 +10,7 @@ matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
from scipy.signal import find_peaks
if __package__ is None or __package__ == "":
sys.path.append(str(Path(__file__).resolve().parents[1]))
@@ -98,6 +99,37 @@ def save_task4_figure(
return figure_path
def pick_fundamental_peak_index(
freqs: np.ndarray,
magnitudes: np.ndarray,
min_hz: float = 0.1,
max_hz: float = 5.0,
relative_threshold: float = 0.20,
relative_prominence: float = 0.08,
) -> int:
band_mask = (freqs >= min_hz) & (freqs <= max_hz)
band_indices = np.where(band_mask)[0]
if band_indices.size == 0:
raise ValueError("No FFT bins fall inside the requested frequency band.")
band_magnitudes = magnitudes[band_mask]
max_magnitude = float(np.max(band_magnitudes))
height_threshold = relative_threshold * max_magnitude
prominence_threshold = relative_prominence * max_magnitude
local_peaks, _ = find_peaks(
band_magnitudes,
height=height_threshold,
prominence=prominence_threshold,
)
if local_peaks.size == 0:
# Fallback for very smooth spectra: choose the strongest bin in band.
return int(band_indices[int(np.argmax(band_magnitudes))])
# Fundamental-first rule: choose the left-most valid peak.
return int(band_indices[int(local_peaks[0])])
def analyze_forced_vibration(
file_path: Path,
output_dir: Path,
@@ -107,13 +139,22 @@ def analyze_forced_vibration(
time_values, raw_signal = read_sensor_signal(file_path, sensor_code=TOP_RESPONSE_SENSOR, value_column=TOP_RESPONSE_AXIS)
time_segment, signal_segment = get_middle_segment(time_values, raw_signal)
sampling_rate = estimate_sampling_rate(time_segment)
predicted_frequency_hz, freqs, magnitudes, peak_index = dominant_frequency_in_band(
_, freqs, magnitudes, _ = dominant_frequency_in_band(
signal_segment,
sampling_rate=sampling_rate,
min_hz=0.1,
max_hz=5.0,
zero_padding_factor=32,
)
peak_index = pick_fundamental_peak_index(
freqs=freqs,
magnitudes=magnitudes,
min_hz=0.1,
max_hz=5.0,
relative_threshold=0.20,
relative_prominence=0.08,
)
predicted_frequency_hz = float(freqs[peak_index])
true_frequency_hz = parse_frequency_from_filename(file_path.name)
absolute_error_hz = None if true_frequency_hz is None else abs(predicted_frequency_hz - true_frequency_hz)