Compare two irregularly sampled, noisy sinusoidal signals

4 Ansichten (letzte 30 Tage)
William
William am 29 Jan. 2025
Kommentiert: Star Strider am 30 Jan. 2025
I am an engineer by discipline, so I have a basic understanding of sine waves, but I am unfamiliar with signal processing techniques. I have two sets of noisy, irregularly sampled sinusoids and I have been tasked quantify how similar they are. The code below generates arrays that are similar to the data I am looking at. My data, however, was measured, so I have no prior knowledge of the amplitudes/frequencies of the sinusoids, only 3 arrays: one containing the discrete time points, and the other two containig the discrete values for signal x and signal y.
t = sort(10*rand(10000,1)); % Generate uneven sample times
x = 2*sin(pi*t) + 3*cos(2*pi*t) + rand(size(t)); % Generate signal 1
y = 2.1*sin(pi*t+0.3) + 3.1*cos(2*pi*t+0.3) + rand(size(t)); % Generate signal 2
I'd greatly appreciate any guidance/references to how to accomplish the task. Thank you for your time.

Akzeptierte Antwort

Star Strider
Star Strider am 29 Jan. 2025
Use the nufft function for irregularly-sampled data.
Beyond that, ‘similarity’ is a somewhat amorphous concept. I did a linear regression of the Fourier transforms of both of them here, as well as calculate the differences and the RMS of the diffeerences. There are likely other metrics that you could use.
t = sort(10*rand(10000,1)); % Generate uneven sample times
x = 2*sin(pi*t) + 3*cos(2*pi*t) + rand(size(t)); % Generate signal 1
y = 2.1*sin(pi*t+0.3) + 3.1*cos(2*pi*t+0.3) + rand(size(t)); % Generate signal 2
X = nufft(x,t);
Y = nufft(y,t);
n = length(t);
f = (0:n-1)/n;
figure
plot(f, abs(X), DisplayName='x(t)')
hold on
plot(f, abs(Y), DisplayName='y(t)')
hold off
grid
legend(Location='best')
difference = abs(X) - abs(Y);
[dmin,dmax] = bounds(difference)
dmin = -790.1515
dmax = 403.9901
rms_difference = rms(difference)
rms_difference = 299.0816
[h,tprob] = ttest2(abs(X),abs(Y))
h = 0
tprob = 0.2047
[prob,h,RStats] = ranksum(abs(X),abs(Y))
prob = 0.0325
h = logical
1
RStats = struct with fields:
zval: 2.1378 ranksum: 100877758
B = [abs(X) ones(size(abs(X)))] \ abs(Y)
B = 2×1
1.0548 -112.2130
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
RL = [abs(X) ones(size(abs(X)))] * B;
Mdl = fitlm(abs(X), abs(Y))
Mdl =
Linear regression model: y ~ 1 + x1 Estimated Coefficients: Estimate SE tStat pValue ________ __________ _______ ___________ (Intercept) -112.21 3.0721 -36.526 2.6456e-274 x1 1.0548 0.00065633 1607.2 0 Number of observations: 10000, Error degrees of freedom: 9998 Root Mean Squared Error: 224 R-squared: 0.996, Adjusted R-Squared: 0.996 F-statistic vs. constant model: 2.58e+06, p-value = 0
figure
plot(abs(X), abs(Y), '.', MArkerSize=0.25, DisplayName='Fourier Transformed Data' )
hold on
plot(abs(X), RL, '-r', DisplayName='Linear Regression')
hold off
grid
legend(Location='best')
Assuming unpaired tests, from the t-test, the two are not different, agreeing with the ranksum result that the medians are not different. In the regression, they are almost collinear. These are just some of the tests you can use. The test you choose depends on what you want from the data.
.
  2 Kommentare
William
William am 30 Jan. 2025
Thank you so much for your reply! This is very helpful to help me wrap my head around the task!
Star Strider
Star Strider am 30 Jan. 2025
As always, my pleasure!
Other options could be findsignal (or alignsignals), however they would not produce any sort of metric that could be used to compare them, only a maximum distance metric (for findsignal) that would not actually have a context, so you would have to provide a context for it by comparing it to another value derived from at least one of the signals in order to estimate similarity.
That’s the reason I didn’t use it initially here. The functions I chose produce probability estimates. They have an inherent context.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by