Time vector to generate a sinusoid signal with 0.5 seconds duration , Fs =200

23 ビュー (過去 30 日間)
Mohamad
Mohamad 2020 年 10 月 22 日
編集済み: Cris LaPierre 2020 年 10 月 24 日
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
  5 件のコメント
Mohamad
Mohamad 2020 年 10 月 23 日
編集済み: Mohamad 2020 年 10 月 23 日
t1 has 101 points , this means signal duration = ( 101/Fs ) = 0.505 seconds not 0.5 seconds .
I need the signal duration to be 0.5 seconds with sampling instants at 1/Fs (0.005) .
So I think using the following will be correct , right ?
t2=linspace(0,0.5,duration*Fs+1);
Mathieu NOE
Mathieu NOE 2020 年 10 月 23 日
yes , if you prefer take the second option
t2=linspace(0,0.5,duration*Fs+1);
but the first method works also. example you just take 2 samples with dt = 0.005
first sample correspond to t = 0
second sample correspond to t = 1 * dt = 0.005
you have 2 samples for a signal duration = 0.005 (= 1 x dt)
so this is what I tried to explain

サインインしてコメントする。

採用された回答

Cris LaPierre
Cris LaPierre 2020 年 10 月 23 日
編集済み: Cris LaPierre 2020 年 10 月 24 日
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))
ans = 0.0050
t2 = linspace(0,0.5,0.5*200+1);
mean(diff(t2))
ans = 0.0050
  1 件のコメント
Mohamad
Mohamad 2020 年 10 月 23 日
Thanks a lot , now I understand it , actually I was confused because the following example from matlab to generate a signal with a sampling frequency of 1 kHz and a signal duration of 1.5 seconds :
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sampling period
L = 1500; % Length of signal
t = (0:L-1)*T; % Time vector
The example says signal duration 1.5 seconds , but I see signal duration it is 1.499 seconds .

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpectral Measurements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by