Sampling Cosine MATLAB

Discussion in 'Programmer's Corner' started by battlehands, Aug 17, 2011.

  1. battlehands

    Thread Starter New Member

    Jul 29, 2011
    13
    0
    I need to take 27 uniformly distributed samples from a cosine fuction over the interval (-pi/2, pi/2).

    Any ideas?
     
  2. steveb

    Senior Member

    Jul 3, 2008
    2,433
    469
    I would start by defining a vector

    x=1:27

    Then scale and shift this as follows

    t=-pi/2+pi*(x-1)/26

    then take the cosine

    Cs_t=cos(t)

    This assumes you want to include the endpoints in the vectors, but you didn't say specifically you had to do that.
     
  3. guitarguy12387

    Active Member

    Apr 10, 2008
    359
    12
    Alternatively:

    cos(linspace(-pi/2, pi/2, 27));
     
  4. steveb

    Senior Member

    Jul 3, 2008
    2,433
    469
    Very cool ! Thanks.
     
Loading...