matlab - Delay a signal in time domain with a phase change in the frequency domain after FFT -


i have problem basic time/frequency property implemented in matlab script. property is:

im1

i've tried implement in matlab script. i've supposed sinusoidal signal 5hz of frequency value, sampling frequency equal 800hz , want delay signal 1.8 seconds. i've implemented script:

fs = 800; time_max = 4; % seconds t = 0:(1/fs):time_max; delay = 1.8; % 1 second of delay  f = 5; %hz y = sin(2 * pi * f * t);  figure subplot(2,1,1) plot(t,y); xlabel('time (s)') legend('original');  %fft size = 2^nextpow2(length(y)); y = fft(y,size);  df = fs/size; f= -fs/2:df:fs/2 - df;  k = 1:size      y(k) = y(k)*exp(-(1i*2*pi*f(k)*delay));  end  subplot(2,1,2) plot(real(ifft(y)),'r') legend('shifted'); 

and output plot :

output plot

where problem? how can achieve correct time delay?

thanks

the problem not in implementation, lies within properties of fft (respectively of dft): formula posted time delay correct, have keep in mind, doing circular shift. means signal parts 2.2s 4.0s copied beginning of output. see:

before

the signal want start @ 1.8s, 0 0.6837s there part inserted due circular shift. small calculation: input signal 1 x 3201, i.e. zero-padded 895 zeros. in seconds, 1.1187 seconds of zeros. circular shift insert last 1.8s @ beginning, i.e. 1.8 - 1.1187 = 0.86 seconds not zeros contain sine. amount see in plot.

to avoid effect, have pad input signal @ least amount of zeros delay signal. in case be

fs = 800; time_max = 4; % seconds t = 0:(1/fs):time_max; delay = 1.8; % 1 second of delay  f = 5; %hz y = sin(2 * pi * f * t); y = [y, zeros(1,delay*fs)];          % zero-pad signal amount of delay  size = 2^nextpow2(length(y)); y = fft(y,size);  df = fs/size; f= -fs/2:df:fs/2 - df;  k = 1:size     y(k) = y(k)*exp(-(1i*2*pi*f(k)*delay)); end  td = (0:size-1)/fs; yd = real(ifft(y)); 

which gives us

result


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -