Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I am attempting to graph some 64 sample'd basis functions in MatLab, and getting inconsistent results -- which is to say, I'm getting results that are still sinusoidal, but don't have the frequency they ought.

Here's a graph of what is supposed to be my c8 basis function:

enter image description here

Unfortunately, it only has 7 peaks, which indicates that I seem to have botched the frequency somehow. I'm assuming my problem lies somewhere within how I'm trying to graph in matlab, and not an error in the function itself.

Here's my code:

n = linspace(0, 2*pi*8, 64) 
x = cos(2*pi*8*n/64)
plot(n,x)

I'm inclined to believe x has the correct formula, but I'm at a loss as to how else to formulate an 'n' to graph it with. Why am I getting a result with the incorrect frequency?

share|improve this question
    
I seem to be missing something. The result of linspace() already returns 64 rational multiples of $\pi$ between $0$ and $16\pi$. Then within the cosine, you multiply these rational multiples of $\pi$ with $\pi/4$. It seems you're not evaluating what you think you're evaluating. –  J. M. Sep 16 '11 at 1:19
    
@J.M. - Yes, I know I've made a mistake somewhere. I'm trying to identify it. –  Raven Dreamer Sep 16 '11 at 1:23

1 Answer 1

up vote 1 down vote accepted

You're plotting the function $\cos n\pi/4$, which has period $8$, and thus $8$ full periods from $0$ to $64$, but you're only substituting values from $0$ to $16\pi$. Since $16\pi\approx50$, you're missing a bit less than two of the periods. From what it seems you're trying to do, you should be plotting the function from $0$ to $64$, i. e. replace 2*pi*8 by 64 in the first line.

share|improve this answer
    
Wonderful. I knew it was something silly and stupid. -_- –  Raven Dreamer Sep 16 '11 at 4:37
    
@Raven: A clue that your linspace() expression was faulty was that your n consists of $(0,16\pi/63,\dots,16\pi)$. Replacing the n in cos(2*pi*8*n/64) with, for example, 16*pi/63 gives you something with a pi^2 within the cosine... –  J. M. Sep 16 '11 at 4:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.