Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.


Ki
Posts:
21
Registered:
5/20/12


about derivative with fft
Posted:
Nov 20, 2014 4:54 PM


Hi all, In a text on signal processing, it is said that we could use fft to do the derivative on a signal. So to give it a trial, I run the following code on sinusoidal function
N = 4096; % number of samples L = 2; % range of spatial function dx = 2*L/N; x = dx*(N/2:N/21); k = (pi/L)*[0:N/2, N/2+1:1];
y = sin(x); dy = real(ifft(i*k.*fft(y))); plot(x, y); hold on; plot(x, dy,'r');
it shows many noisy stuffs at the edges. By trial and error, I found that if I replace sin(x) with sin(2*pi*x), the noisy components gone and I got the smooth result like cosine. Why is that?
N = 4096; % number of samples L = 2; % range of spatial function dx = 2*L/N; x = dx*(N/2:N/21); k = (pi/L)*[0:N/2, N/2+1:1];
y = sin(2*pi*x); dy = real(ifft(i*k.*fft(y))); plot(x, y); hold on; plot(x, dy,'r');
I know that the derivative of sine should be cosine but they should have about the amplitude (1), but the resulting cosine if about 6 times higher than the original sine, so what's wrong with that? Thanks.



