MATLAB: How to go from frequency response of simple delay to impulse response.

fftifft

Lets say my transfer function is H(f)=exp(-j2pi*f*tau) where tau is delay in seconds. In time domain we know H(f) is h(t)=δ(t-tau) . How do I show this in MATLAB? Below is what I have tried using codes that were related to this question.
clear all
N=1000; f=1:1:1000; tau=5; H=exp(-1i*2*pi.*f*tau); FR_positive_frequency_only=H; FR_data = zeros(1,2*N); FR_data(1:N) = FR_positive_frequency_only; FR_data(N+1:N*2) = fliplr(FR_positive_frequency_only(1:end));
IR_data = ifft(FR_data); figure; stem(IR_data);
IR_data=ifft(ifftshift(FR_data)); figure; stem(IR_data);
Thank you for the help.

Best Answer

Fs = 2000;
N = 12000;
dF = Fs/N;
f = (-Fs/2:dF:Fs/2-dF)';
tau = 5;
H = exp(-1i*2*pi*f*tau);
h = real(ifft(ifftshift(H)));
dt = 1/Fs;
t = dt*(0:N-1)';
plot(t,h);
Related Question