Shifting a graph without altering the data itself.

Hi, I have the following graph in which I'd like the two curves to coincide as closely as possible. Is there a way to achieve that without altering the data? Also, simply shifting the x data within the plot function by a certain offset (i.e. plot(x+offset,y)) doesn't yield the desired result.
Below is the plotting:
figure
subplot(2,1,1)
plot(k,RCS_PO,'k',k,RCS_MOM_soft,'m',k,RCS_MIE_soft,'b','LineWidth',2);

回答 (1 件)

Star Strider
Star Strider 2016 年 12 月 22 日

0 投票

See the Signal Processing Toolbox alignsignals (link) function.

6 件のコメント

Yuval
Yuval 2016 年 12 月 22 日
I am not sure I understand. Suppose I would like sin(x) and cos(x) to coincide as closely as possible, should I then type: [Xa,Ya] = alignsignals(sin(x),cos(x)) and then plot(x,Xa,x,Ya)?
Star Strider
Star Strider 2016 年 12 月 22 日
It requires a bit more than that:
x = linspace(0, 4*pi);
y1 = sin(x);
y2 = cos(x);
[y1a,y2a] = alignsignals(y2, y1); % Note Order of Arguments
xa = linspace(0, 4*pi*length(y1a)/length(y1), length(y1a)); % New Independent Variable For Aligned Signal
figure(1)
subplot(2,1,1)
plot(x, y1, '-b', x, y2, '-.r')
grid
subplot(2,1,2)
plot(xa, y1a, '-b', x, y2a, '-.r')
grid
Experiment with this code snippet, and with your signals to get the result you want.
Yuval
Yuval 2016 年 12 月 22 日
I am still not getting what I wanted. Here's what I did (note that my x vector is k = linspace(0.1,20,150) and that I would like the signals RCS_MOM_hard and RCS_MIE_hard to be aligned):
subplot(2,1,2)
[y1a,y2a] = alignsignals(RCS_MOM_hard,RCS_MIE_hard); %
xa = linspace(0.1, 20*length(y1a)/length(RCS_MIE_hard), length(y1a)); % New Independent Variable For Aligned Signal
plot(k,RCS_PO,'k',xa,y1a,'m',k,y2a,'b','LineWidth',2);
How should I go about fixing it?
Star Strider
Star Strider 2016 年 12 月 22 日
I don’t know what’s wrong.
Experiment with changing the order of the arguments to alignsignals. In my experiments with it, it aligns the first argument to match the second argument.
It may not be possible to align your signals exactly. Looking at the zero-crossings, they don’t appear to have the same frequencies and phase relationships.
Yuval
Yuval 2016 年 12 月 22 日
I am not looking for an exact alignment, only an adequate shift in the x axis.
Star Strider
Star Strider 2016 年 12 月 22 日
For that, I would choose a subset of your data (for example 4 to 8 ka) and use the delay calculated from that. You would insert a zero or NaN vector the length of the delay returned as the third argument of alignsignals to your signal vector, and use linspace to extend your independent (probably time) vector to the appropriate length.

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

タグ

質問済み:

2016 年 12 月 22 日

コメント済み:

2016 年 12 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by