sinc + cos function plot

Respectively, codes, matlab plot, and graphing site plot.
Even though I made same argument, matlab plot gives wrong plot. What's wrong? I need your help.

3 Comments

The graphing site is clearly wrong: the red curve is just sinc() without any cos() component.
Please post code as regular text highlighed by the CODE button. We can't run images.
I figured out what's wrong. I thought sinc at matlab gives sin(x)/x but basically it gives sin(pi x)/pi x. Here, I wanna plot former one, which is unnormalized one, but I don't know how to, either.... Haha

Sign in to comment.

 Accepted Answer

Delete pi from below line
% delete pi from the below line
a = (-4:0.001:4);
p = 10;
f = p*sinc(a) + cos(a)
f = 1×8001
-0.6536 -0.6569 -0.6602 -0.6634 -0.6667 -0.6699 -0.6732 -0.6765 -0.6797 -0.6830 -0.6862 -0.6895 -0.6928 -0.6960 -0.6993 -0.7025 -0.7058 -0.7091 -0.7123 -0.7156 -0.7189 -0.7221 -0.7254 -0.7287 -0.7319 -0.7352 -0.7384 -0.7417 -0.7450 -0.7482
plot(a,f)

5 Comments

Thank you. It works but can you explain me why? I cant' find the reason.
The cos still needs the pi
a = (-4:0.001:4)*pi;
p = 10;
f = p*sinc(a/pi) + cos(a)
f = 1×8001
1.0000 0.9975 0.9950 0.9925 0.9899 0.9874 0.9848 0.9822 0.9796 0.9771 0.9744 0.9718 0.9692 0.9666 0.9639 0.9613 0.9586 0.9559 0.9532 0.9505 0.9478 0.9451 0.9424 0.9396 0.9369 0.9341 0.9313 0.9285 0.9257 0.9229
plot(a,f)
By definition sinc can be written as (sinx / x) , so if you apply in the equation, you would get a result as shown below,
% delete pi from the below line
a = (-4:0.001:4)*pi;
p = 10;
f = p*sin(a)./a + cos(a)
f = 1×8001
1.0000 0.9975 0.9950 0.9925 0.9899 0.9874 0.9848 0.9822 0.9796 0.9771 0.9744 0.9718 0.9692 0.9666 0.9639 0.9613 0.9586 0.9559 0.9532 0.9505 0.9478 0.9451 0.9424 0.9396 0.9369 0.9341 0.9313 0.9285 0.9257 0.9229
plot(a,f)
In your code, you have multiplied or included pi in x-vector, but did not divide it. The graph which you want to obtain is actually sin(pi*x)/ (pi*x)
Note however
x = 0
x = 0
sinc(x)
ans = 1
sin(x)./x
ans = NaN
Stephen23
Stephen23 on 13 May 2023
Edited: Stephen23 on 13 May 2023
"By definition sinc can be written as (sinx / x) "
Except in the field of digital signal processing where it is commonly defined as
sin(pi*x) / (pi*x)
which is the definition that SINC uses, SINC being part of the Signal Processing toolbox:
"In the context of digital signal processing, we often use an alternative form in which the independent variable is multiplied by π":
" The sinc function is defined as: sinc(a) = sin(πa)/(πa)":

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Asked:

on 13 May 2023

Edited:

on 13 May 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!