Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
create a sine wave

Subject: create a sine wave

From: Paul

Date: 27 May, 2010 16:48:25

Message: 1 of 7

Hi,

I have to create a sine wave with an amplitude of 1, frequency of 10 kHz for a period of 0.2 sec. Using a sampling frequency of 20 kHz.

i have the following (which I think should work):
t=[0:1/20000:0.2];
A=1;
f=10000;
y=A*sin(2*pi*f*t);
plot(t,y)

but the figure looks bad, can someone tell me what I do wrong?

with kind regards

Subject: create a sine wave

From: Wayne King

Date: 27 May, 2010 17:05:25

Message: 2 of 7

"Paul " <pvankaam86@hotmail.com> wrote in message <htm7op$ss3$1@fred.mathworks.com>...
> Hi,
>
> I have to create a sine wave with an amplitude of 1, frequency of 10 kHz for a period of 0.2 sec. Using a sampling frequency of 20 kHz.
>
> i have the following (which I think should work):
> t=[0:1/20000:0.2];
> A=1;
> f=10000;
> y=A*sin(2*pi*f*t);
> plot(t,y)
>
> but the figure looks bad, can someone tell me what I do wrong?
>
> with kind regards

Hi, increase your sampling rate (decrease your sampling interval)

 t = [0:1/30000:0.2];
 A = 1;
 f =10000;
 y = A*sin(2*pi*f*t);
 plot(t(1:100),y(1:100))

Wayne

Subject: create a sine wave

From: David Young

Date: 27 May, 2010 17:07:24

Message: 3 of 7

It looks OK to me. You expect y to be zero everywhere, and so it is, apart from some arithmetic rounding errors. (If you sample a pure 10kHz signal at 20kHz, and you start at 0 phase, you sample the zero-crossings.)

If you want to sample the signal at its peaks and troughs, you could change the phase by pi/2.

Subject: create a sine wave

From: Gaurav

Date: 21 May, 2012 16:49:07

Message: 4 of 7

try this................

t=[0:0.1:20];
A=1;
f=1000;
y=A*sin(f*t);
plot(t,y)

Subject: create a sine wave

From: Nasser M. Abbasi

Date: 21 May, 2012 18:12:47

Message: 5 of 7

On 5/21/2012 11:49 AM, Gaurav wrote:
> try this................
>
> t=[0:0.1:20];

no need for the [ and ]

Subject: create a sine wave

From: Iktedar

Date: 22 Sep, 2013 03:14:09

Message: 6 of 7

"Nasser M. Abbasi" wrote in message <jpe0is$a59$1@speranza.aioe.org>...
> On 5/21/2012 11:49 AM, Gaurav wrote:
> > try this................
> >
> > t=[0:0.1:20];
>
> no need for the [ and ]

Sampling phase can be ignored as log as the sampling frequency is > 2xNyquist.
Also, the waveform will be periodic in N samples where N is an integer fraction > 2xNyquist. For example, for a ratio fs= 21/4 (5.25 which is greater than 2xNyquist), the samples will repeat every 21 samples. Below are the samples using fs = (21*10000/4) and sampling phase 0.

-0.1490 -0.9749 -0.5633 0.5633 0.9749 0.1490 -0.8660 -0.7818

  Columns 52433 through 52440

    0.2948 0.9972 0.4339 -0.6802 -0.9309 -0.0000 0.9309 0.6802

  Columns 52441 through 52448

   -0.4339 -0.9972 -0.2948 0.7818 0.8660 -0.1490 -0.9749 -0.5633

  Columns 52449 through 52456

    0.5633 0.9749 0.1490 -0.8660 -0.7818 0.2948 0.9972 0.4339

  Columns 52457 through 52464

   -0.6802 -0.9309 0.0000 0.9309 0.6802 -0.4339 -0.9972 -0.2948

  Columns 52465 through 52472

    0.7818 0.8660 -0.1490 -0.9749 -0.5633 0.5633 0.9749 0.1490

  Columns 52473 through 52480

   -0.8660 -0.7818 0.2948 0.9972 0.4339 -0.6802 -0.9309 0.0000

  Columns 52481 through 52488

    0.9309 0.6802 -0.4339 -0.9972 -0.2948 0.7818 0.8660 -0.1490

  Columns 52489 through 52496

   -0.9749 -0.5633 0.5633 0.9749 0.1490 -0.8660 -0.7818 0.2948

  Columns 52497 through 52501

    0.9972 0.4339 -0.6802 -0.9309 -0.0000

Subject: create a sine wave

From: Iktedar

Date: 22 Sep, 2013 03:15:07

Message: 7 of 7

"Nasser M. Abbasi" wrote in message <jpe0is$a59$1@speranza.aioe.org>...
> On 5/21/2012 11:49 AM, Gaurav wrote:
> > try this................
> >
> > t=[0:0.1:20];
>
> no need for the [ and ]

Sampling phase can be ignored as log as the sampling frequency is > 2xNyquist.
Also, the waveform will be periodic in N samples where N is an integer fraction > 2xNyquist. For example, for a ratio fs= 21/4 (5.25 which is greater than 2xNyquist), the samples will repeat every 21 samples. Below are the samples using fs = (21*10000/4) and sampling phase 0.

-0.1490 -0.9749 -0.5633 0.5633 0.9749 0.1490 -0.8660 -0.7818

  Columns 52433 through 52440

    0.2948 0.9972 0.4339 -0.6802 -0.9309 -0.0000 0.9309 0.6802

  Columns 52441 through 52448

   -0.4339 -0.9972 -0.2948 0.7818 0.8660 -0.1490 -0.9749 -0.5633

  Columns 52449 through 52456

    0.5633 0.9749 0.1490 -0.8660 -0.7818 0.2948 0.9972 0.4339

  Columns 52457 through 52464

   -0.6802 -0.9309 0.0000 0.9309 0.6802 -0.4339 -0.9972 -0.2948

  Columns 52465 through 52472

    0.7818 0.8660 -0.1490 -0.9749 -0.5633 0.5633 0.9749 0.1490

  Columns 52473 through 52480

   -0.8660 -0.7818 0.2948 0.9972 0.4339 -0.6802 -0.9309 0.0000

  Columns 52481 through 52488

    0.9309 0.6802 -0.4339 -0.9972 -0.2948 0.7818 0.8660 -0.1490

  Columns 52489 through 52496

   -0.9749 -0.5633 0.5633 0.9749 0.1490 -0.8660 -0.7818 0.2948

  Columns 52497 through 52501

    0.9972 0.4339 -0.6802 -0.9309 -0.0000

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us