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
Reply Paul 5/27/2010 4:48:25 PM

"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
0
Reply Wayne 5/27/2010 5:05:25 PM


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
Reply David 5/27/2010 5:07:24 PM

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

t=[0:0.1:20];
A=1;
f=1000;
y=A*sin(f*t);
plot(t,y)
0
Reply gaurav.agnihotri (3) 5/21/2012 4:49:07 PM

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

no need for the [ and ]

0
Reply Nasser 5/21/2012 6:12:47 PM

4 Replies
577 Views

(page loaded in 0.267 seconds)

Similiar Articles:













7/26/2012 3:13:42 AM


Reply: