How do I plot a signal over a duration of 1 second, with a = 200 and b = 0 for t<0.1 and a = 0 and b = 400 for t >=0.1

18 views (last 30 days)
How do I produce a signal over a duration of 0.1 second at a sampling rate of 8kHz, with a = 1000 and b = 0 for t<0.05 and a = 0 and b = 1000 for t >=0.05
where the signal is x(t) = sin(2*pi*a*t) + sin(2*pi*b*t)
I have produced a similar signal prior to this, wherein a and b did not change value at certain points in time.
The similar signal:
%%Construct Signal
% f_1(t) = sin(2*pi*a*t)+sin(2*pi*b*t)
% at a sampling rate of 8kHz, for a duration of 0.1 seconds
% a= 500 Hz
% b= 1000 Hz
fs = 8000; % Sampling Rate
ts = 1/fs; % Sampling Period
t = linspace(0, 0.1, 1001);
t = t(1:end-1);
a= 500;
b= 1000;
f_1 = sin(2*pi*a*t)+sin(2*pi*b*t); % function f_1(t)
figure(1)
plot(t,f_1);

Accepted Answer

dpb
dpb on 21 Aug 2013
Edited: dpb on 21 Aug 2013
Just define a and b over the range of length(t) as well and use the 'dot' operators in the evaluation...
a = 1000 and b = 0 for t<0.05 and a = 0 and b = 1000 for t >=0.05
a=zeros(size(t)); b=a; % start w/ zero vectors
a(t<0.5)=1000; % logical addressing of
b(t>0.5)=1000; % portions to set
topi=2*pi;
f=sin(topi*a.*t)+sin(topi*b.*t);
ADDENDUM:
Your sample rate of 8 kHz is ignored in your formulation I note--if really want/need that instead of that used (altho it's marginally adequate as the plot will show) then use
t=0:ts:0.1;
instead of your linspace().

More Answers (0)

Community Treasure Hunt

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

Start Hunting!