Time delay Calculation using FFT-Based Algorithm
Ältere Kommentare anzeigen
Hello,
I'm implementing in MATLAB a cross-correlation algorithm based on the FFT. I don't want to use the built in function "xcorr". I'm doing the cross-correlation to determine the time delay of two generated sine signals. This is what I have done in coding so far:
close all;
clear all;
%%Signal Generation
Fs = 1000;
Ts = 1/Fs;
fc = 60;
V = 0.1; % Window Stop Time
ActTD = 0.008; % Actual Time Delay
t = 0:Ts:V-Ts;
x = sin(2*pi*fc*t);
y = sin(2*pi*fc*(t-ActTD));
%%Spectra of Input Signals
%Correlation Length
corrLength=length(x)+length(y)-1;
%Input Signal-1 Spectra
X=fft(x,corrLength);
%Input Signal-2 Spectra
Y=fft(y,corrLength);
%%Cross Correlation in Frequency Domain
%Hadamard Product
Z=X.*(conj(Y));
%Inverse Fast Fourier Transform
z=fftshift(ifft(Z));
%Time Axis
Ly=length(z);
tz=0:Ts:(Ly-1)*Ts;
TD=max(abs(z))*Ts % Calculated Time Delay
%%Plot Section
%Original and delayed signal
plot(t,x,'r',t,y,'b');
legend('Original','Delayed');
% Cross Correlated Signal
figure
plot(tz,z);
xlabel('Time in seconds');
ylabel('Magnitude');
title('Cross Correlated Signal');
grid
As you can see, I'm adding a delay to a generated signal. The actual time delay is in line 10, but when I run the code, I'm not getting the actual time delay. It should be at least close to that value. The algorithm is based on the circular cross-correlation method. Any idea what I could be doing wrong? Maybe that is not the proper way to add delay to a signal?
There are few examples online, but most of them are by adding random delay. I want something I could control so I can know that this is actually working how is supposed to.
Any help or suggestion will be appreciated, Thanks!
Akzeptierte Antwort
Weitere Antworten (1)
Ilker CIBLAK
am 8 Nov. 2020
0 Stimmen
Hi there,
I am a mechanical engineering student which has no knowledge on signal processing. Dispite this, I need to build an algorithm on matlab that computes time delay between two data arrays (or signals). So, can anyone explain me what the variables fc and V ,@ signal generation part, correspond to ?
Kategorien
Mehr zu Correlation and Convolution finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!