Signal processing
9 次查看(过去 30 天)
显示 更早的评论
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');
0 个评论
采纳的回答
更多回答(1 个)
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 个评论
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]).
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!