Generating time vector and sinusoids
13 views (last 30 days)
Show older comments
I have an assignment to plot 2 sinusoids and i got stuck. My task is: Generate a time vector (tt) to cover a range of t that will exhibit approximately two cycles of the 4000 Hz sinusoids defined in the next part. If we use T to denote the period of the sinusoids, define the starting time of the vector tt to be equal to −T, and the ending time as +T. Then the two cycles will include t = 0. Finally, make sure that you have at least 25 samples per period of the sinusoidal wave. In other words, when you use the colon operator to define the time vector, make the increment small enough to generate 25 samples per period. Afterwards Generate two 4000 Hz sinusoids with arbitrary amplitude and time-shift. x1(t) = A1 cos(2π(4000)(t − tm1)) and x2(t) = A2 cos(2π(4000)(t − tm2))
A1 being 18, A2 being 1.2A1. tm1 being (37.2/11)T and tm2 being -(-41.3/27)T where T is period and t is time vector
My code is:
if true
% code
end
A1=18;
A2=1.2*18;
f = 4000; % sinusoid freq
T = 1/f; % period
fs = T/25; % time step
tt = -T:fs:T; % time vector
tm1=(37.2/11)*T;
tm2=-(41.3/27)*T;
X1=A1*cos(2*pi*(4000))*(tt-tm1);
subplot(3,1,1);
plot(tt,X1),grid on
title('Sinusoid #1')
hold on
X2=A2*cos(2*pi*(4000))*(tt-tm2);
subplot(3,1,2)
plot(tt,X2),grid on
When i run this script i do not get any sinusoids, just straight lines on the graph. What am i doing wrong? Thanks for your time
0 Comments
Accepted Answer
Torsten
on 23 Oct 2015
X1=A1*cos(2*pi*(4000)*(tt-tm1));
instead of
X1=A1*cos(2*pi*(4000))*(tt-tm1);
Same for X2.
Best wishes
Torsten.
More Answers (2)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!