Asked by yofiandi yosmansyah
on 10 Jan 2013

hi guys i have a question which is how to write the matlab code for a messages signal

m(t) = 1 when 0=<t=<0.05 -9 when 0.05=<t=<0.1 else is 0

pls help me and thanks

*No products are associated with this question.*

Answer by Walter Roberson
on 11 Jan 2013

Define your vector t of times. Then,

m = zeros(size(t)); m(t > 0 & t < 0.05) = 1; m(t >= 0.05 & t <= 0.01) = -9;

Note this would be only one pulse.

Related Content

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
## 15 Comments

## Walter Roberson (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58474#comment_121934

You did not ask a question ?

## yofiandi yosmansyah (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58474#comment_121939

what i mean is what is the matlab code to create that message signal m(t)..thanks

## Walter Roberson (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58474#comment_121942

You do not define m(t) for t <= 0 or t >= 0.1 ?

## yofiandi yosmansyah (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58474#comment_121945

oh ya, the m(t) for t<0 and t>0.1 is equal to 0

## Amith Kamath (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58474#comment_121948

I suppose you mean:

but it would definitely help if you are clearer about what you want to modulate, and what 'message' is?

## yofiandi yosmansyah (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58474#comment_121951

so i had given the carrier c(t)=cos(2pi*fc*t) and the message signal m(t)={1, for 0=<t=<0.05 and -9, for 0.05=<t=<0.5 and 0 for elsewhere} then i need to plot the m(t) signal, the c(t) and the modulated signal s(t). so far i only can answer to plot the c(t) signal which i found the matlab code to be like :

now i cant proceed to the next stage which are plotting m(t) still havent got one and s(t)the modulated signal which i cant find it without the m(t)signal.

## yofiandi yosmansyah (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58474#comment_121954

so the problem i have face now is to generate the message signal m(t) which i believed it will looks like a rectangular wave with amplitude 1 and -9.. still,I cant find the matlab code. T_T

## Amith Kamath (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58474#comment_121956

So I understand you can use the same 'fs' for m(t), with t already defined. What I don't understand is how you could have one signal ranging from 0:0.03 and another from 0:0.1 and 'modulate' it. I assume you want to do m(t)*c(t), right?

## yofiandi yosmansyah (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58474#comment_121958

the first range when i put 0:1/fs:0.03 its because i want to plotting the nice cosine-wave because when i out 0:1/fs:0.1 the graph doesn't look really good. correct me if i'm wrong.. and btw i tried the m(t) that been given by you and the graph is look weird like just a horizontal line,,isnt its supposed to be a square-wave with peak to peak -9 to 1? correct me if i'm wrong again..thanks :)

## Amith Kamath (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58474#comment_121959

You must be attempting to do this:

If not, I'm not really sure I understand your question! :)

## yofiandi yosmansyah (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58474#comment_121960

m(t) still didnt generate a rectangular pulses with amplitude 1 and -9.. but really thanks for help and fast feedback..i really appreciate it :)

## Walter Roberson (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58474#comment_121965

You say "rectangular pulses", but the m(t) you define would have only one pulse.

## yofiandi yosmansyah (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58474#comment_121996

oke..im sorry i was very sleep so i didnt see it clearly.. well the m(t) became 2 from t= 0 until t=0.05 and become -9from t=0.05 onward. but when t<0 and t>0.1 its supposed have a zero value. so how to make that m(t) yah? m(t) = { 1 when 0=<t=<0.05 -9 when 0.05=<t=<0.1 0 when t= elsewhere }

## yofiandi yosmansyah (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58474#comment_122002

thats it is..thanks bro for the help..i really appreciate it..btw how to plot the amplitude spectra ya??

## Walter Roberson (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58474#comment_122004

stairs() to plot.