# sine wave plot

11.298 views (last 30 days)
aaa on 24 Apr 2012
Answered: wilfred nwakpu on 1 Feb 2020 at 19:04
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?

Ahmed Grera on 3 Sep 2017
How many cycles do you need in drawing?
Govinda Nahak on 2 Oct 2017
in sine function in MATLAB it is always sin(wt). here frequency w is in radian/sec not f (in HZ) so w will give you the no.of the cycle.
suppose w=1 it is one cycle and so on
if you want to use the sin(2*pi*60*t) you can use the sind(2*pi*9.545*t). why i use the 9.545 bcz we should convert the f to w in the time interval of 2*pi.
How can we make it 3 phase system? for 50 Hz and 230 V peak to peak

Rick Rosson on 24 Apr 2012
%%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

Rajasekaran on 14 Mar 2013
Nauman Hafeez on 28 Dec 2018
How to calculate Fs for a particular frequency signal?
I am generating a stimulating signal using matlab for my impedance meter and it gives me different results on different Fs.

Mike Mki on 29 Nov 2016
Dear Mr. Rick, Is it possible to create knit structure in Matlab as follows:

Robert on 28 Nov 2017
aaa,
What goes wrong: by multiplying time vector t by 2*pi*60 your discrete step size becomes 0.1*2*pi*60=37.6991. But you need at least two samples per cycle (2*pi) to depict your sine wave. Otherwise you'll get an alias frequency, and in you special case the alias frequency is infinity as you produce a whole multiple of 2*pi as step size, thus your plot never gets its arse off (roundabout) zero.
Using Rick's code you'll be granted enough samples per period.
Best regs
Robert

omphile hahilton on 3 Mar 2015
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

soumyendu banerjee on 1 Nov 2019
%% if Fs= the frequency u want,
x = -pi:0.01:pi;
y=sin(Fs.*x);
plot(y)

wilfred nwakpu on 1 Feb 2020 at 19:04
%%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;