align signal plot close to the origin Y Axis

2 次查看(过去 30 天)
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 个评论
Jorge Luis
Jorge Luis 2024-1-3
编辑:Jorge Luis 2024-1-3
Dear Star Strider. Happy New Year and my apologies. I was commenting and thanking your brilliant response and then when I submited my comment it showed an error. I decided to copy and paste it on word just in case sth wrong happened. Then, I realized you deleted your response. Could you please write down your response again using the information from my edited question I made so then I can update it and delete your very helpful code from my edited question. I am really sorry for what I did, I thought that information could have helped other people and it should not have been deleted it. Thank you for your time in helping others :).
Star Strider
Star Strider 2024-1-3
I did not keep my code.
Since you did not accept my answer, I have no incentive to follow up on this.

请先登录,再进行评论。

采纳的回答

Hassaan
Hassaan 2023-12-31
To address this issue, one approach would be to apply a detrending method to remove any linear trend from the signal, which could re-align the signal closer to the Y-axis origin. This can be done using MATLAB's detrend function, which by default removes the best straight-line fit. Here is a conceptual example of how you might apply it:
% Load your signal data
signal = % your signal data here;
% Apply detrending to remove linear trend
signal_detrended = detrend(signal);
% Now, plot the detrended signal
plot(signal_detrended);
xlabel('Time (s)');
ylabel('Amplitude');
title('Detrended Signal Plot');
This approach assumes that the deviation from the origin is linear over time. If the deviation is more complex, you might need a more sophisticated method like polynomial fitting and subtraction or other types of baseline correction methods that fit the non-linear trends in the data before subtracting them.
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multirate Signal Processing 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by