COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### create a sine wave

• Email
• Follow

```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
```
 0

See related articles to this posting

```"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

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
```
 0

```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.
```
 0

```try this................

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

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

no need for the [ and ]

```
 0

```"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
```
 0
Reply ikted (2) 9/22/2013 3:14:09 AM

```"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
```
 0
Reply ikted (2) 9/22/2013 3:15:07 AM

6 Replies
769 Views

Similar Articles

12/6/2013 1:52:24 PM
[PageSpeed]