Ammar
Ammar

Reputation: 1233

create an m file for sin signa

I am trying to create an m-file function for a sine signal with input tmin, tmax, time-period, amplitude, but I don't know how to to begin. I am a newbie with Matlab.

My Sine function has the following code

function  y=sin(x)

y=sin(x); 

In the command window, I type plot(mysine(x)); to get the sine signal, but this is all I know.

How do you set the tmin, tmax, time-period, amplitude ?

I want to have something like this

[x] = mysine(-10,10,0.25,2);
plot(x);

Upvotes: 0

Views: 133

Answers (1)

Fantastic Mr Fox
Fantastic Mr Fox

Reputation: 33904

This is a very simple question which isn't really to do with programming and I suspect it is homework.

if sine has the following form:

a*sin(b*x+c)+d

a affects the amplitude
b affects the time-period
c affects the phase
d affects the amplitude offset

Basically what you are wanting to do is this:

plot(tmin:timePeriod:tmax, amplitude*sin(tmin:timePeriod:tmax))

which will produce something like this:

enter image description here

Which is the sine form you are looking for I believe.

As a function:

function x = mysine(tmin, tmax, timePeriod, amplitude)
     x = plot(tmin:timePeriod:tmax, amplitude*sin(tmin:timePeriod:tmax))
end

Upvotes: 2

Related Questions