The Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: about derivative with fft
Replies: 2   Last Post: Nov 23, 2014 12:24 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Ki

Posts: 21
Registered: 5/20/12
about derivative with fft
Posted: Nov 20, 2014 4:54 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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/2-1);
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/2-1);
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.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.