Signal processing

5 visualizaciones (últimos 30 días)
Susan
Susan el 4 de Ag. de 2011
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');

Respuesta aceptada

Daniel Shub
Daniel Shub el 5 de Ag. de 2011
[Rxx, lags] = xcorr(x, y)
[Y, I] = max(Rxx);
lags(I)
  1 comentario
Susan
Susan el 5 de Ag. de 2011
It produce 0 as an answer? Its not getting the right lag.. It should be -4

Iniciar sesión para comentar.

Más respuestas (1)

Fangjun Jiang
Fangjun Jiang el 5 de Ag. de 2011
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 comentarios
Susan
Susan el 6 de Ag. de 2011
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 el 6 de Ag. de 2011
It's hard to tell because the lag is small relative to the x-scale. I believe we mentioned AXIS([XMIN XMAX YMIN YMAX]).

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by