12 views (last 30 days)

Hi , please I'm confused with the following time vectors t1 and t2 to generate 0.5 second duration sinusoid signal :

Vector t1 has equally spaced samples at Ts intervals , but the signal x1 has duration equal to ( duration+Ts ) seconds , I checked x1 length .

Vector t2 has equally spaced samples not Ts intervals , signal x2 dutaion = ( duration ) secons excatly , which time vector is correct ?

%% Generates a sine wave of 0.5 second duration

F0=10; % Sinusoid frequency in Hz

Fs=200; % sampling frequency samples / sec

duration=0.5; % signal duration is seconds

Ts=1/Fs; % sampling Interval

t1=0:Ts:duration; % time vector with equally spaced samples at Ts intervals

t2=linspace(0,duration,duration*Fs); % time vector with samples not at Ts intervals

x1=sin(2*pi*F0*t1); % signal duration = ( duration+Ts ) seconds , length = 101 points

x2=sin(2*pi*F0*t2); % signal duration = ( duration ) secons , length = 100 points

Cris LaPierre
on 23 Oct 2020

Edited: Cris LaPierre
on 24 Oct 2020

When using linspace, don't forget to account for 0. For example, how many numbers are there between 0 and 10? 11.

You should add 1 to your calculated number of points. This way, the colon operator and linspace give the same result, and both t1 and t2 are vectors with 101 points.

t1 = 0:1/200:0.5;

mean(diff(t1))

t2 = linspace(0,0.5,0.5*200+1);

mean(diff(t2))

Opportunities for recent engineering grads.

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

Start Hunting!
## 5 Comments

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/622313-time-vector-to-generate-a-sinusoid-signal-with-0-5-seconds-duration-fs-200#comment_1079588

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/622313-time-vector-to-generate-a-sinusoid-signal-with-0-5-seconds-duration-fs-200#comment_1079588

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/622313-time-vector-to-generate-a-sinusoid-signal-with-0-5-seconds-duration-fs-200#comment_1080468

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/622313-time-vector-to-generate-a-sinusoid-signal-with-0-5-seconds-duration-fs-200#comment_1080468

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/622313-time-vector-to-generate-a-sinusoid-signal-with-0-5-seconds-duration-fs-200#comment_1080758

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/622313-time-vector-to-generate-a-sinusoid-signal-with-0-5-seconds-duration-fs-200#comment_1080758

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/622313-time-vector-to-generate-a-sinusoid-signal-with-0-5-seconds-duration-fs-200#comment_1081198

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/622313-time-vector-to-generate-a-sinusoid-signal-with-0-5-seconds-duration-fs-200#comment_1081198

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/622313-time-vector-to-generate-a-sinusoid-signal-with-0-5-seconds-duration-fs-200#comment_1081908

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/622313-time-vector-to-generate-a-sinusoid-signal-with-0-5-seconds-duration-fs-200#comment_1081908

Sign in to comment.