필터 지우기
필터 지우기

Signal processing

조회 수: 5 (최근 30일)
Susan
Susan 2011년 8월 4일
Hello everyone!! I am really struggling with this, been trying different examples and methods but still can't get it right. Will appreciate anyone who could tell me a method to do it or any useful tips.. It is regarding delay time.. I created a Signal and a delayed version of the signal, also I plotted the correlated version of the two signals and I meant to be able to see it from the correlated graph the delayed time and calculate it.. I am not sure how can I find the delay time?? I found "Align Signals" from the communication toolbox and I read the documentation about it and it's exactly what I am looking for, I obtained the toolbox but unfortunately they use diagrams and channels as graphs and it is not what I am looking for, I want a way to calculate it?
N=1024; % Number of samples
f1=1; % Frequency of the sinewave
FS=200; % Sampling Frequency
n=0:N-1; % Sample index numbers
x=sin(2*pi*f1*n/FS); % Generate the signal, x(n)
t=[1:N]*(1/FS); % Prepare a time axis
subplot(3,1,1); % Prepare the figure
plot(t,x); % Plot x(n)
title('Sinwave of frequency 1000Hz [FS=8000Hz]');
xlabel('Time, [s]');
ylabel('Amplitude');
grid;
%Delayed version of the Signal..
D = -4;
y=(sin(2*pi*f1*n/FS))-D; % Generate the signal, x(n)
t=[1:N]*(1/FS); % Prepare a time axis
subplot(3,1,2); % Prepare the figure
plot(t,y); % Plot x(n)
title('Sinwave the delayed version [FS=8000Hz]');
xlabel('Time, [s]');
ylabel('Amplitude');
grid;
%Correlation between the two Signals..
Rxx=xcorr(x,y); % Estimate its autocorrelation
subplot(3,1,3); % Prepare the figure
plot(Rxx); % Plot the autocorrelation
grid;
title('Correlation between the Signal and the Delayed version !');
xlable('lags');
ylabel('Autocorrelation');

채택된 답변

Daniel Shub
Daniel Shub 2011년 8월 5일
[Rxx, lags] = xcorr(x, y)
[Y, I] = max(Rxx);
lags(I)
  댓글 수: 1
Susan
Susan 2011년 8월 5일
It produce 0 as an answer? Its not getting the right lag.. It should be -4

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2011년 8월 5일
Your code is wrong. I think you meant y is 4 samples lagging behind x. But your y is -4 (in amplitude) of x. The code below generates y as 10 samples lagging behind x. The result is -10.
N=1024; % Number of samples
f1=1; % Frequency of the sinewave
FS=200; % Sampling Frequency
t=(0:N)/FS;
x=sin(2*pi*f1*t);
subplot(3,1,1);plot(t,x);
y=[repmat(0,1,10),x(1:end-10)];
subplot(3,1,2);plot(t,y);
[Rxx, lags] = xcorr(x, y);
[Y, I] = max(Rxx);
lags(I)
  댓글 수: 3
Susan
Susan 2011년 8월 6일
Thanks for the explanation, how can I change the time so it will be obvious when I see the figure that Y is delayed version of X. at the moment they just look identical ???
Fangjun Jiang
Fangjun Jiang 2011년 8월 6일
It's hard to tell because the lag is small relative to the x-scale. I believe we mentioned AXIS([XMIN XMAX YMIN YMAX]).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by