Why is matlab giving me a single answer when I divide by a vector?

58 Views Asked by At

I'm attempting to do a stem plot of $\frac{sin(k2D\pi)}{k\pi}$ in matlab.

Following is my procedure:

x = linspace(-50,50);
D = 1/8;
Y = (sin(x*2*pi*D))/(x*pi);
stem(Y)

But rather than giving me what I would expect(Fourier Series coefficients for a square wave with duty cycle D), I get a single delta. I checked Y, and it's saying it's equal to 1.9987e-04, rather than a vector like I would expect.

If I remove the /(x*pi) from Y, I get a vector like I would expect. What's wrong with my syntax?

1

There are 1 best solutions below

3
On BEST ANSWER

To perform pointwise divison of two vectors, use the $./$ operator instead of the $/$ operator:

Y = (sin(x*2*pi*D)) ./ (x*pi);