Align two plots based on amplitude

13 次查看(过去 30 天)
I have two plots.
Plot A and Plot B
Both have there own data sets, which need to be a little calibrated but aligning the ampliture, so all average peaks are very close.
This is my plot as an example
As you can see the bottom plot data neds to be shifted up a little. Is there a tool which can help get a good alignment in y axis?
  4 个评论
Image Analyst
Image Analyst 2022-10-15
编辑:Image Analyst 2022-10-15
Well the obvious solution would have been to just take a small subset of the data. Nonetheless, see what @Star Strider has done below with synthesized data and see if it's what you want. If not, then attach less than 5 MB subset of your data. It's what I would have done, which is to basically just assume one curve is just a linearly scaled and shifted version of the other curve.
Dharmesh Joshi
Dharmesh Joshi 2022-10-15
Thanks i i will see if i can extract small amount of data ,

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2022-10-14
Perhaps something like this —
t = linspace(0, 10, 1000);
y1 = sin(2*pi*t/2.5) + randn(size(t))*0.1;
y2 = 1.5*sin(2*pi*t/2.5) + randn(size(t))*0.1 + rand;
B = [y2(:) ones(size(y2(:)))] \ y1(:);
fprintf('\nMultiplier = %7.4f\nOffset = %7.4f\n',B)
Multiplier = 0.6536 Offset = -0.5288
y2s = [y2(:) ones(size(y2(:)))] * B;
figure
subplot(2,1,1)
plot(t, [y1; y2])
grid
xlabel('Time')
ylabel('Amplitudes')
title('Original')
subplot(2,1,2)
plot(t, [y1; y2s.'])
grid
xlabel('Time')
ylabel('Amplitudes')
title('Shifted & Scaled')
.
  2 个评论
Dharmesh Joshi
Dharmesh Joshi 2022-10-15
Does both data sets need to be equal in size?
Star Strider
Star Strider 2022-10-15
If you want to compare them, yes.
Changing them to have equal lengths can be done easily with the interp1 function. A linear interpolation decreasing the number of points in the either vector will not change the shape of that vector. It will only change the number of points defining it without creating new points where none previously existed. For that reason, it would be best to decrease the number of points in the longer vector and then do the compariison.
If you are doing signal processing with the vectors, use the Signal Processing Toolbox resample function instead of interp1 to change the number of pionts in the longer vector.
t1 = linspace(0, 10, 1000); % Original, 1000 Samples
y1 = sin(2*pi*t1/2.5) + randn(size(t1))*0.1;
t2 = linspace(0, 10, 250); % Original, 250 Samples
y2 = 1.5*sin(2*pi*t2/2.5) + randn(size(t2))*0.1 + rand;
figure
plot(t1, y1, '.')
hold on
plot(t2, y2, '.')
hold off
y1i = interp1(t1, y1, t2); % Resample 'y1' To 'y2' Points (250)
figure
plot(t2, y1i, '.') % Resampled To 250 Points
hold on
plot(t2, y2, '.') % Original At 250 Points
hold off
These vectors can now be compared, since they both have the same lengths and both are sampled at the same times.
This is simply an illustration using created vectors. It should work with your data.
.

请先登录,再进行评论。

更多回答(0 个)

类别

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

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by