Effacer les filtres
Effacer les filtres

Find the central line (midpoint) of a sinusoidal wave

3 vues (au cours des 30 derniers jours)
Snow
Snow le 15 Juin 2023
Modifié(e) : Matt J le 16 Juin 2023
I used another program (tracker) to track the oscillation of a laser. I generated a plot of position with respect to time with the data used from the program.
Attached is an image of the data with a curve fit generated in matlab.
Is there a way to generate a horizontal line on this same plot in order to show the centerline of the oscillation?
For example, The biggest peak ranges fromo 45 to 75 cm. Its midpoint would be 57.5cm. A horizontal line at 57.5 would indicate the centerline of this oscillation.

Réponse acceptée

Matt J
Matt J le 16 Juin 2023
Modifié(e) : Matt J le 16 Juin 2023
yline(mean(y))

Plus de réponses (1)

Angelo Yeo
Angelo Yeo le 16 Juin 2023
Please consider the following example.
clear;
%% creating an oscillating signal with bias
fs = 10000;
t = 0: 1/fs: 1- 1/fs;
x1 = sin(2*pi*10*t);
x2 = exp(-1*t);
my_bias = exp(0.1 * t);
x = x1.*x2 + my_bias;
figure
plot(t, x);
%%
[pks_p, locs_p] = findpeaks(x); % find peaks
[pks_n, locs_n] = findpeaks(-x);
hold on;
plot(t(locs_p), pks_p, 'r*');
plot(t(locs_n), -1 * pks_n, 'b*');
%% creating a center line
yline(mean([pks_p, -1 * pks_n]))

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by