Plot problem

2 ビュー (過去 30 日間)
Susan
Susan 2011 年 8 月 24 日
Dear all, I have my code for calculating delay time for signals.. I have two signals and I calculated the delay time.I plotted both signals in the graph using subplot.When I run it I get the delay time, If the delay is positive then Y (second signal) must be the delayed signal otherwise X is delayed one. I am trying to plot the delayed signal on the same graph as the one that is not delayed. So I used if-statement to represent the two cases, e.g if delay is 5 then I need to plot (Y+5)on the same plot as X. My difficulty is by saying in the if-statement that if it positive add it to Y AND plot it in the same graph ?
x = sample1(:,1);
X = (x).';
y = sample2(:,1);
Y = (y).';
figure;
clf
subplot(3,1,1);
[xi,f]=ksdensity(X);
plot(f,xi);
line(repmat(X,2,1),repmat([0;0.1*max(xi)],1,length(X)),'color','r' );
subplot(3,1,2);
[xi,f]=ksdensity(Y);
plot(f,xi);
line(repmat(Y,2,1),repmat([0;0.1*max(xi)],1,length(Y)),'color','r' );
[Rxx,lags] = xcorr(X,Y);
[Z,delay] = max(Rxx);
lags(delay);
% If the delay is positive then Y is the delayed Signal, otherwise is X the delayed Signal.
if delay>0
hold
[xi,f]=ksdensity(Y+delay);
plot(f,xi);
else
hold
[xi,f]=ksdensity(X+delay);
plot(f,xi);
end
Thank you
  1 件のコメント
Fangjun Jiang
Fangjun Jiang 2011 年 8 月 24 日
You made the same mistake as last time. delay is in time axis. What is the point adding time delay to the magnitude of the signal?

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

採用された回答

Walter Roberson
Walter Roberson 2011 年 8 月 24 日
Something like,
sp1 = subplot(3,1,1);
[xi,f]=ksdensity(X);
plot(f,xi);
line(repmat(X,2,1),repmat([0;0.1*max(xi)],1,length(X)),'color','r' );
sp2 = subplot(3,1,2);
[xi,f]=ksdensity(Y);
plot(f,xi);
line(repmat(Y,2,1),repmat([0;0.1*max(xi)],1,length(Y)),'color','r' );
[Rxx,lags] = xcorr(X,Y);
[Z,delay] = max(Rxx);
lags(delay);
if delay>0
hold(sp1,'on');
[xi,f]=ksdensity(Y+delay);
plot(sp1,f,xi);
else
hold(sp2,'on');
[xi,f]=ksdensity(X+delay);
plot(sp2,f,xi);
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDigital Filter Design についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by