How do I plot this sine wave?
20 views (last 30 days)
I am new to matlab and I am struggling with the basics. I was asked this question in class and I'm just not sure what to do "Plot one second of a sine wave with frequency 97 Hz and phase shift 97 (in degrees). The x-axis should be time not samples". Please help.
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?
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);
% 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.