align signal plot close to the origin Y Axis
Afficher commentaires plus anciens
Hello, I have some signals that have some issues as you can see in the figure below. Herein, this example shows that the signal does not start at the origin of the Y axis (0 value) and it can have different starts from the origin for the three components (2 horizontals and 1 vertical). This potentially affects the estimation of the maximum peak amplitude for each component (PGA as shown in the figure below). The easiest option to correct this issue is to just to substract the average between the first and the last amplitud of the signal from all the points of the entire signal so that the signal can almost starts from the Y origin. You can suggest another sophisticated way to do this operation. I attached an example of one of the signals that has this issue in the amplitude of the three components. Thank you for your help. By the way, this is operation is someting different for the base line correction of signals that are performed after the filtering process.

The following code was provided by Star Strider and it was deleted by technical issues from the answers:
A1 = readmatrix('example.txt')
A1 = 19800×3
4.9381 -5.3897 -8.5907
4.9415 -5.3906 -8.5912
4.9343 -5.3983 -8.5931
4.9305 -5.3964 -8.5921
4.9291 -5.4107 -8.5983
4.9291 -5.4035 -8.5893
4.9334 -5.3868 -8.5859
4.9243 -5.4030 -8.5945
4.9248 -5.3926 -8.5921
4.9214 -5.3859 -8.5959
Fs = 200; % Signal Sampling Frequency (samples/time unit)
L = size(A1,1);
t = linspace(0, L-1, L).'/Fs;
figure
plot(t, A1)
grid
legend('Column #1','Column #2','Column #3', 'Location','best')
[PeakMax1,idx] = max(abs(A1))
PeakMax1 = 1×3
22.1162 22.4118 17.8099
idx = 1×3
5395 5237 4440
figure
tiledlayout(3,1)
for k = 1:size(A1,2)
nexttile
plot(t, A1(:,k), 'Color',[0.9 0.7 0.1])
hold on
plot(t(idx(k)), A1(idx(k),k), 'pb', 'MarkerFaceColor','b', 'MarkerSize',10)
hold off
grid
axis('padded')
text(t(idx(k)), A1(idx(k),k), sprintf(' \\leftarrow Amplitude = %.3f\n Time = %.3f', A1(idx(k),k),t(idx(k))) )
end
sgtitle('Original')
for k = 1:size(A1,2)
B(:,k) = [t([1 end]) [1;1]] \ A1([1 end],k);
nv(:,k) = [t ones(size(t))] * B(:,k);
end
[PeakMax2,idx] = max( abs(A1 - A1(1,:)) )
PeakMax2 = 1×3
17.8957 18.9390 9.8138
idx = 1×3
5044 5295 5059
figure
tiledlayout(3,1)
for k = 1:size(A1,2)
nexttile
plot(t, A1(:,k) - A1(1,k), 'Color',[0.9 0.7 0.1])
hold on
plot(t(idx(k)), A1(idx(k),k) - A1(1,k), 'pb', 'MarkerFaceColor','b', 'MarkerSize',10)
hold off
grid
axis('padded')
A1k = (A1(idx(k),k) - nv(idx(k),k));
tk = t(idx(k));
text(tk, A1k, sprintf(' \\leftarrow Amplitude = %.3f\n Time = %.3f', A1k, tk) )
end
sgtitle('Centre Normalised')
[PeakMax3,idx] = max( abs(A1 - nv) )
PeakMax3 = 1×3
17.9097 18.9066 9.8223
idx = 1×3
5044 5295 5059
PeakMaxDiff = PeakMax2 - PeakMax3
PeakMaxDiff = 1×3
-0.0140 0.0324 -0.0085
figure
tiledlayout(3,1)
for k = 1:size(A1,2)
nexttile
plot(t, A1(:,k) - nv(:,k), 'Color',[0.9 0.7 0.1])
hold on
plot(t(idx(k)), A1(idx(k),k) - nv(idx(k),k), 'pb', 'MarkerFaceColor','b', 'MarkerSize',10)
hold off
grid
axis('padded')
A1k = (A1(idx(k),k) - nv(idx(k),k));
tk = t(idx(k));
text(tk, A1k, sprintf(' \\leftarrow Amplitude = %.3f\n Time = %.3f', A1k, tk) )
end
sgtitle('Centre Detrended')
5 commentaires
Jorge Luis
le 31 Déc 2023
Hassaan
le 31 Déc 2023
Thank you. Happy New Year.
Star Strider
le 1 Jan 2024
Interesting that you copied and quoted my code (deleted, since with rare exceptions, I delete my un-accepted Answers), yet accepted the other answer.
Jorge Luis
le 3 Jan 2024
Modifié(e) : Jorge Luis
le 3 Jan 2024
Star Strider
le 3 Jan 2024
I did not keep my code.
Since you did not accept my answer, I have no incentive to follow up on this.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Descriptive Statistics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!