Signal processing
Afficher commentaires plus anciens
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');
Réponse acceptée
Plus de réponses (1)
Fangjun Jiang
le 5 Août 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 commentaires
Daniel Shub
le 5 Août 2011
Thank you for that. I had looked at my answer again, but couldn't figure out how I made a mistake. I think my answer follow on what Susan had done, but I didn't check to see that what she had done was correct.
Susan
le 6 Août 2011
Fangjun Jiang
le 6 Août 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]).
Catégories
En savoir plus sur Correlation and Convolution dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!