# How do I plot this sine wave?

60 views (last 30 days)

Show older comments

Niamh Mc Devitt
on 22 Oct 2013

Commented: Image Analyst
on 22 Oct 2013

##### 0 Comments

### Accepted Answer

sixwwwwww
on 22 Oct 2013

Edited: sixwwwwww
on 22 Oct 2013

Dear Niamh, you can do the following way:

time = -1:0.01:1;

frequency = 97;

phase = 97;

phase_in_rad = degtorad(phase);

y = sin(2 * pi * frequency * time + phase_in_rad);

plot(time, y), xlabel('Time'), ylabel('Sine wave')

Do you need it or something else?

##### 2 Comments

Image Analyst
on 22 Oct 2013

Edited: Image Analyst
on 22 Oct 2013

### More Answers (1)

Image Analyst
on 22 Oct 2013

Edited: Image Analyst
on 22 Oct 2013

Hopefully this was just a question asked verbally in class and not an actual homework assignment. Wouldn't it just be something like this:

% Make 1000 samples in the range 0 to 1 second.

t = linspace(0, 1, 1000);

% Assign period and phase shift of 97 degrees.

period = 1/97; % 97 hertz = period of 1/97 of a second.

phaseShift = 97 * pi/180; % In radians.

y = sin(2*pi*t/period - phaseShift));

plot(t,y, 'bo-', 'LineWidth', 2);

grid on;

% Enlarge figure to full screen.

set(gcf, 'units','normalized','outerposition',[0 0 1 1]);

Of course with 97 periods across the screen of width 1920 pixels, you won't see much - it will be all smashed together horizontally. You might want to plot fewer periods.

##### 0 Comments

### See Also

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!