Palindrom
Palindrom

Reputation: 443

Matlab sin wave plotting

I am newbie on matlab sorry if the question is so silly. I search about it but I could not understand the issue clearly.

I want to work with interval int=(-20:20) which has 41 element on sin wave. when I plot sin(int) it is ploting well but when I try to plot sin(50*int) evenif there must be a lot of change of y value than sin(int) there is not. When I change int=(-100:100) has 201 element, still same wrong plotting. I only take real plot when I change int=(-10:0.1:10) has again 201 element

What is the reason behind?

Upvotes: 0

Views: 244

Answers (2)

eigenchris
eigenchris

Reputation: 5821

What you're describing is a signal processing problem called aliasing.

Basically, if you don't sample a sine wave often enough, the discretized sine wave can appear to have a lower frequency than the actual continuous wave did:

enter image description here

To fix this problem you must sample at least twice as often as the frequency of the signal. (See the sampling theorem.)

sin(x) has a frequency of 1 rad/s so you must sample at least as often as 2 rad/s = 0.318 Hz, or about 1 sample for every 3 units.

int=(-20:20) satisfies this requirement with a sampling rate of 1 Hz = 6.28 rad/s > 2 rad/s.

50*int, or -1000:50:1000 does not, as it has a sampling rate of 1/50 Hz = 0.1257 rad/s < 2 rads/s.

Upvotes: 5

Martin J.H.
Martin J.H.

Reputation: 2205

You are looking at something called "aliasing". sin is a periodic function with a period of 2*pi (because it's in radian, not in degrees). In some of your plots your "x-values" (which you don't really plot, which is not so good) are further apart than half a period.

Take a look at the following plots:

figure;
hold all;
plot(int2, sin(int2), 'o-');
plot(int1, sin(int1), 'o-');


figure;
hold all;
plot(50*int2, sin(50*int2), 'o-');
plot(50*int1, sin(50*int1), 'o-');

You'll see that in both figures, the points of int2 coincide with points of int1. In the second plot, however, linear interpolation between the few points of int1 paints a sine-wave that is not really there.

Upvotes: 3

Related Questions