How can I align multiple curves on one plot to a central point?

35 ビュー (過去 30 日間)
OmartheEngineer 2023 年 1 月 3 日
コメント済み: OmartheEngineer 2023 年 1 月 10 日
I am plotting several curves on a single plot as part of several test points for a tool I am developing. In the final step, I overlay all the curves on top of one another for a visual display. As you can see all the plots are shifted relative to one another. How can i go about aligning these cruves so that similar features align? Keep in mind they will not perfectly align. What I am looking at was something like the pdf file (done in excel). I thought I could find the center point for the flat portion of the curve (already have those points defined as part of the test) and somehow make all 15 curves center point align on the curve. Any ideas are appreciated.
Edit:Updated question and attachments based on feedback.
Thanks
Sample Code:
for ii =1:length(SNSource)
%import power data for each product
ScatterData=importdata(cell2mat(SNSource(ii)))
plot(ScatterData(:,1),ScatterData(:,2))
title('ScatterData')
hold on
xlabel('Distance mm')
ylabel('Power')
end

サインインしてコメントする。

採用された回答

Image Analyst 2023 年 1 月 3 日
How about if you found where it crossed 0.001 on both sides, compute the middle from that, and then compute the delta x from there to the desired, common x center point and add it to the x vector for each curve?
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
5 件のコメント表示非表示 4 件の古いコメント
OmartheEngineer 2023 年 1 月 10 日
Thank you very much for explaing this in great detail. Makes much more sense now :)

サインインしてコメントする。

その他の回答 (1 件)

William Rose 2023 年 1 月 3 日
It would help if you would attach the actual data as a .mat file or a text file for easy import.
Your choce of a linear y-axis for one plot, and a logarithmic y-axis for the other, makes it more difficult to compare the images.
The first image file attached appears to be the one from Excel, but I am not positive, and file names and plot titles do not make it obvious. I recommend that in the future you not use terms like "the second picture", since the order of file attachment may not be what you expect.
It looks to me like you have already aligned the plots pretty well in the Excel plot. When you say you want to align the plots better, are you only doing a horizontal shift? Or do you also want to do a vertical shift? Would you allow shrinking or stretching of the horizontal or vertical scale to improve the alignment?
I will assume you just want to slide the curves horizontally, without steching or shrinkking. Here is an example of how you can use the cross correlation to adjust the horizontal position, using simulated data:
%create simulated data
N=100;
t1=1:N; t2=t1;
x1=10*[zeros(1,35),ones(1,20),zeros(1,45)]+rand(1,N);
x2=10*[zeros(1,45),ones(1,20),zeros(1,35)]+rand(1,N);
%find the optimal alignment for the simulated data
[~,idx]=max(xcorr(x1,x2)); %idx=index where cross correlation is maximum
t2adj=t2+idx-N; %shift the time base for x2
%plot the results
subplot(211); plot(t1,x1,'-r.',t2,x2,'-b.');
legend('x1','x2'); title('Raw Data');
This works nicely. You can do it again for x1 and x3, x1 and x4, etc. Good luck!
1 件のコメント表示非表示 なし
OmartheEngineer 2023 年 1 月 4 日
Thank you very much for your response. I have updated my question above. I am sorry for the lack of clarity. The issue is that these products are not all aligned the same on the system. They are all scanned over a the same distance but the saturated peak( horizontal segement) occurs at different segements of the scan range. You are correct as I do want to shift the curves left-right so that they align on top of each other. I realize they wont be perfect but more presentable and easier to view.
My thought process was computing the mid point for the horizontal segement. Choosing a point on the x axis then having align midpoints for each curve align on that point. I am not sure if that can be even done in matlab plot.
Now to your proposed solution.I got a little confused by the code. First, you find a correlation between te two curves. Would that be the maximum value for both? Then you shift the time vector ( x axis ) by that value so they align? How would that be done for 10, 20 ,30 curves. Would there be one value or several to shift by?
Thanks again for your help and response

サインインしてコメントする。

カテゴリ

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by