1,550 views (last 30 days)

Show older comments

Rik
on 13 Jan 2021

Geoff Hayes
on 17 Nov 2016

t = 0:0.01:1;

f = 15;

a = 4;

y = a*sin(2*pi*f*t);

plot(t,y);

Though ten samples (your t) may not be enough to accurately represent the sine wave (that you are attempting), so try

Fs = 1000;

t = linspace(0,1-1/Fs,Fs);

f = 15;

a = 4;

y = a*sin(2*pi*f*t);

plot(t,y);

Junyoung Ahn
on 16 Jun 2020

clear;

clc;

close;

f=15; %frequency [Hz]

t=(0:1/(f*100):1);

a=4; %amplitude [V]

phi=0; %phase

y=a*sin(2*pi*f*t+phi);

plot(t,y)

xlabel('time(s)')

ylabel('amplitude(V)')

Jos (10584)
on 17 Nov 2016

This is the general formula of a sine wave. If leave it to you to fill in the numbers.

y = Amplitude * sin(2*pi*f*t + phase)

cesar moreno
on 4 Feb 2021

If you need to load the generated data into an array of length N

then,

int k (the index of the array)

int N (the number of points in the data array)

The ARRAY holds values of type FLOAT example: array is called data[N] each location is a FLOAT

y = Amplitude * sin(2*pi*f*t + phase)

for k = 0 to N (load one location at a time)

data[k] = Amplitude * sin( ((2*pi*f*k)/N) + phase )

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

Start Hunting!