1
$\begingroup$

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?

  • 0
    @J.M. - Yes, I know I've made a mistake somewhere. I'm trying to identify it.2011-09-16

1 Answers 1

1

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.

  • 0
    @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...2011-09-16