Delay using FFT
显示 更早的评论
I have the following code to acurately implement time delay in any signal(wideband) in frequency domain by using the efficiency of FFT:
%****code edited (last 5 lines)****%
clc
clear all
close all
fs=10000;
f1=700;
t_duration=1;
t = 0:1/fs:t_duration-1/fs;
s = sin(2*pi*f1*t)+cos(8*pi*f1*t); %input signal
slen=length(s);
s=s';
[rn,c] = size(s);
d=0.000553239; %time delay in seconds
nfft = 2^nextpow2(2*slen); % To use max. computational efficiency of FFT
fax = fs*(-nfft/2:nfft/2-1)'/nfft; % Create frequency shift vectors(bins)
shft = exp(-j*d*2*pi*fax); % w=2*pi*fax,, Frequency function for delay
shft = ifftshift(shft); % Make axis compatable with numeric FFT
fsd = fft(s(:,1),nfft); % Take FFT
fsd = fsd.*shft; % Apply delay
dum = ifft(fsd); % Return to time domain
sd(:,1) = real(dum(1:slen)); % Trim time domain signal to required length
s1=sin(2*pi*f1*(t-d))+cos(8*pi*f1*(t-d));
plot(s1);
hold on
plot(sd,'y');
legend('mathematically delayed','delayed in frequency domain');
diff=sd'-s1; %difference signal
stem(diff);
*****question updated******
However, after carefully observing the plots obtained, I have following doubt:
I still see a problem area that is, when I compare the output 'sd' of the above algorithm with 's1'(*5 lines added at the end of code*), they should be same, but there is difference as observed in plot(diff). why? and how can I bring this difference close to zero?
Please guide.
Thank you.
采纳的回答
更多回答(1 个)
Ranim Tom
2021-12-18
0 个投票
As answer to your question: the error is due because the algorithm mathematically dealyed is technically wrong I think to compute the delay that way.
Explanation: Althought that is drue a delay operation for some signal x(t) is expressed as x(t - d), and you can directly type in matlab, but remember that x(t - d) means that the signal x(t) start after d seconds, and anything before d seconds is 0.
In matlab, when you type for example s1=sin(2*pi*f1*(t-d))+cos(8*pi*f1*(t-d)) : t - d will give a vector that starts even before 0 (give negative time values), because matlab will subtract from each value of the t vector that value d (for example 0 - 0.011 s = -0.011 s, and so on...) , and hence will compute s1 for all these values (before d seconds and even before 0)
So again altough it is naturally to think directly typing x(t - d), however in an implementation it is wrong.
I hope I answered your question.
类别
在 帮助中心 和 File Exchange 中查找有关 Mathematics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!