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

New to MATLAB?

sine wave plot

Asked by aaa

aaa (view profile)

on 24 Apr 2012
Latest activity Answered by omphile hahilton

omphile hahilton (view profile)

on 3 Mar 2015 at 8:25

Hi,

I am having some trouble plotting a sine wave and i'm not sure where i am going wrong.

i have

t = [0:0.1:2*pi]
a = sin(t);
plot(t,a)

this works by itself, but i want to be able to change the frequency. When i run the same code but make the change

a = sin(2*pi*60*t)

the code returns something bad. What am i doing wrong? How can i generate a sin wave with different frequencies?

0 Comments

aaa

aaa (view profile)

Products

No products are associated with this question.

2 Answers

Answer by Rick Rosson

Rick Rosson (view profile)

on 24 Apr 2012
Accepted answer

Please try:

   %% Time specifications:
   Fs = 8000;                   % samples per second
   dt = 1/Fs;                   % seconds per sample
   StopTime = 0.25;             % seconds
   t = (0:dt:StopTime-dt)';     % seconds
   %% Sine wave:
   Fc = 60;                     % hertz
   x = cos(2*pi*Fc*t);
   % Plot the signal versus time:
   figure;
   plot(t,x);
   xlabel('time (in seconds)');
   title('Signal versus Time');
   zoom xon;

HTH.

Rick

1 Comment

Rajasekaran

Rajasekaran (view profile)

on 14 Mar 2013

Thanks for your reply & detailed answer.

Rick Rosson

Rick Rosson (view profile)

Answer by omphile hahilton

omphile hahilton (view profile)

on 3 Mar 2015 at 8:25

I would like to generate the product of 2 sine waves at frequencies 697Hz and 1209Hz and sample them and then generate the spectrum of the signal. then play the sine wave through my soundcard speakers help me..........thanks in advanced

0 Comments

omphile hahilton

omphile hahilton (view profile)

Contact us