Align two plots based on amplitude
조회 수: 16 (최근 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
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.
채택된 답변
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)
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
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 Center 및 File Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!