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

### create a sine wave

• 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

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

4 Replies
577 Views

Similiar Articles:

7/26/2012 3:13:42 AM