4.0

4.0 | 1 rating Rate this file 3 Downloads (last 30 days) File Size: 6.9 KB File ID: #14525

Sine and cosine integrals on non-uniform grid

by Leonid

 

04 Apr 2007 (Updated 11 Apr 2007)

Calculates integrals f(x)*sin(k*x)*dx and f(x)*cos(k*x)*dx with high precision for any value of k

| Watch this File

File Information
Description

See the comments given inside the *.m files. Can be used for a Fourier transform on a non-uniform grid.

MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File  
Everyone's Tags
cosine, fourier, integration, simpson, sine
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
28 Oct 2008 T. U.  
14 Apr 2007 Bochore Guchuma

This one is a nice approach.
I have a problem of integrating mixed harmonic signals of different orders,such as integral of f(wt)=cos(wt)+sin(2*wt)+sin(7*wt) and the like.
I have tried using iterative numerical method as well as with cumtrapz method. But since a cosine signal has a value of 1 at t=0,it was difficult for me to find the initial condition for a mixed signal of different harmonic combinations!
Any help I would appreciate.
Regards,

08 Apr 2007 John D'Errico

Shaun's assessment is closely in line with mine. The help is reasonable. I'm vaguely uncomfortable with the choice of method, although a valid assessment of the method used here would force me to do a complete re-write and in-depth analysis.

For example, I'm unhappy with use of a continuous but not differentiable piecewise quadratic to approximate the function. A cubic spline would have been a very simple alternative here.

I'm also a bit worried about how the author handles large values of k*x, and I don't see why the author has chosen to use a high order Taylor series expansion when the integral is available directly.

Finally, there is a lot of unnecessarily cloned and loopy code.

You may or may not be happy with this code. Like Shaun, I can't come up with a rating that fits it.

06 Apr 2007 Shaun S

Since I don't have time to really rate this file, I will just make a couple comments. It is loopy, certain areas could be vectorized. I am not sure the user would want a second order polynomial approximating, say, a square wave. Using Taylor Expansion? Even for an analytical result, there are better ways to proceed on a sine function. Again, I did not spend too much time.

Updates
11 Apr 2007

(1) integration tests routine for -1e10<=k<=1e10 is added; (2) function for the basic Simpson's integration on a non-uniform grid is added; (3) minor changes are done (to include the case of negative k<0 and the case k=0).

11 Apr 2007

M-script of integration performance tests is extended and improved. The integration functions are not changed, except few additional comments are added inside them to better explain the numerical method used.

Contact us