Compare two irregularly sampled, noisy sinusoidal signals
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Akzeptierte Antwort
Star Strider
am 29 Jan. 2025
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)
rms_difference = rms(difference)
[h,tprob] = ttest2(abs(X),abs(Y))
[prob,h,RStats] = ranksum(abs(X),abs(Y))
B = [abs(X) ones(size(abs(X)))] \ abs(Y)
RL = [abs(X) ones(size(abs(X)))] * B;
Mdl = fitlm(abs(X), abs(Y))
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
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.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!