Plotting a Sine wave in MATLAB

184 Ansichten (letzte 30 Tage)
AluminiumMan
AluminiumMan am 15 Mär. 2023
Kommentiert: Sam Chak am 15 Mär. 2023
Hi, I am trying to plot a sine wave in matlab. The purpose is to use in an electrical context so for plotting 3 phase AC signals and circuits with resistors, capacitors and inductors etc in circuit. We are also supposed to be using complex numbers in this context so just getting my head around it.
We were given an equation A(t)=Am*Sin(wt+θ)
Where A is the signal, t is time, Am is the amplitude of the signal, w is 2*pi*f, and θ is the phase shift.
How can I plot each of these variables into a MATLAB sinewave plot? I have seen some example sine wave plots online but its not clear how to control each of these variables to get the exact sine wave plot that I want?
How can I also contorl things like frequency, total length of time of the sine wave signal, time period of a single sinewave etc. I want to have total control over all of the characteristics of my sine wave.

Antworten (1)

Sam Chak
Sam Chak am 15 Mär. 2023
Bearbeitet: Sam Chak am 15 Mär. 2023
The first example of the plot() function doc exactly shows how to plot a sine wave.
Tend = 10; % simulation time (duration)
t = 0:0.01:Tend;
Am = 1; % parameter 1 : amplitude
p = Tend/2; % parameter 2a: period (time for 1-cycle)
f = 1/p; % parameter 2b: frequency
w = 2*pi*f; % parameter 2c: angular frequency
th = pi/2; % parameter 3 : phase (in radian)
y = Am*sin(w*t + th); % sine wave that becomes a 'cosine' after shifted 90°
plot(t, y, 'linewidth', 1.5), grid on
xlabel('t (sec)')
  2 Kommentare
AluminiumMan
AluminiumMan am 15 Mär. 2023
Ok so for t, 0 is your start time, Tend is your end time (presumably you need to replace this with a value???) and the 0.01 is your sample rate for your signal? So you need to specify how regularly you have samples for your signal?
Sam Chak
Sam Chak am 15 Mär. 2023
I copied the code from multiple examples involving plotting sine wave and inserted your sine formula.
0.01 is the fundamental sample time (not sample rate), also commonly known as step size in MATLAB.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by