You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用曲线拟合优度(GOF)?MATLAB中对比原始与滤波信号相似度

Hey there! Let's tackle your two questions about Goodness of Fit (GOF) step by step, since you're looking to apply this to signal comparison in MATLAB.

1. How to Use Goodness of Fit (GOF)

Goodness of Fit is all about quantifying how well a model, curve, or processed signal matches your reference data. Here's a practical breakdown of how to use it:

  • Define your goal first: Are you evaluating if a statistical model fits raw data? Or (like your second question) comparing two signals to measure similarity? This dictates which GOF metrics you should pick.
  • Choose the right GOF metric: Different metrics work better for different scenarios:
    • R² (Coefficient of Determination): Perfect for measuring how much variance in the reference data is explained by the comparison data. Ranges from 0 to 1—closer to 1 means a better match. Best for linear relationships, but still useful for signal comparison.
    • RMSE (Root Mean Squared Error): Measures the average magnitude of the difference between reference and comparison data. Smaller values mean better alignment. Sensitive to large outliers.
    • MAE (Mean Absolute Error): Similar to RMSE but uses absolute differences instead of squared ones. More robust to outliers, as it doesn't penalize large errors as heavily.
    • Normalized RMSE (NRMSE): Scales RMSE by the range of the reference data, making it easier to compare across signals with different amplitudes.
  • Calculate the metric: Compute the residuals (differences between reference and comparison data) first, then plug them into the formula for your chosen metric.
  • Interpret the result: Don't just look at the number—context matters. For example, an R² of 0.9 might be great for a noisy signal, but underwhelming for a clean lab dataset. Also, be aware of limitations: R² can be misleading if your data has a strong trend or if you're comparing non-linear signals.
2. Comparing Original vs. Filtered Signal Similarity with GOF in MATLAB

When comparing an original signal to its filtered version, you want to quantify how much the filtered signal preserves the original's key features. Here's how to do this with common GOF metrics in MATLAB:

First, make sure your original_signal and filtered_signal are the same length and aligned (same time steps). Then use these code snippets:

Calculate R²

% Compute residuals (difference between original and filtered signals)
residuals = original_signal - filtered_signal;

% Total sum of squares (variance in original signal)
ss_total = sum((original_signal - mean(original_signal)).^2);

% Residual sum of squares (unexplained variance)
ss_residual = sum(residuals.^2);

% Calculate R²
r_squared = 1 - (ss_residual / ss_total);
fprintf('R² Value: %.4f\n', r_squared);

Interpretation: A value close to 1 means the filtered signal explains almost all the variance in the original signal.

Calculate RMSE

rmse = sqrt(mean(residuals.^2));
fprintf('RMSE Value: %.4f\n', rmse);

Interpretation: Smaller RMSE values mean the filtered signal is closer to the original on average.

Calculate Normalized RMSE (NRMSE)

Use this if your signal has a large amplitude range and you want a scale-agnostic measure:

signal_range = max(original_signal) - min(original_signal);
nrmse = rmse / signal_range;
fprintf('Normalized RMSE: %.4f\n', nrmse);

Interpretation: Values below 0.1 are generally considered a very good match.

Calculate Pearson Correlation Coefficient

This measures the linear relationship between the two signals (closely related to R² for linear fits):

[corr_coeff, ~] = corr(original_signal, filtered_signal, 'Type', 'Pearson');
fprintf('Pearson Correlation Coefficient: %.4f\n', corr_coeff);

Interpretation: Values close to 1 mean strong positive correlation (the signals move in sync).

Pro Tips:

  • If your signal has a baseline trend, consider detrend both signals first using detrend() before calculating GOF metrics—this ensures you're measuring similarity in the signal's fluctuations, not the trend.
  • Always visualize the signals alongside the metrics: plot both original and filtered signals with plot(original_signal, filtered_signal) or a time-series plot to see where differences occur.

内容的提问来源于stack exchange,提问作者MouniraZa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:43:32