0
$\begingroup$

I am calculating Time period of Sine/Cos Wave with different frequencies while keeping the Sampling Frequency at 1MHz and plotting it, but in some cases the value of time period is too big,

have a look at some of the examples.

n=[0:0.1:10] %because Time period is 10

F1=100*10^3; %100KHz  and t=1*10^-5
Fs=1*10^6;  %1MHz => Sampling Frequency
T=1/Fs;    %1*10^-6

%Time period = t/T => 10

xn=cos(2*pi*(F1)*n*T)   %T=1/Fs
stem(n,xn);

ylim([-1.5 1.5]);
xlim ([0 10]); %because Time period is 10
grid on;

Here Time period = 10 which means one oscillation would take 10seconds to complete. and here is the output as i expected,

enter image description here

Similarly in second case when i changed the frequency to 10Hz while the Sampling frequency remains 1MHz the value of Time period is way too big,

n=[0:1000:100*10^3] %because Time period is 100*10^3

F1=10; %10Hz  and t=0.1
Fs=1*10^6  %1MHz
T=1/Fs;    %1*10^-6

%Time period = t/T => 100*10^3

xn=sin(2*pi*(F1)*n*T)

stem(n,xn)

ylim([-1.5 1.5])
xlim ([0 100*10^3])  %because Time period is 100*10^3
ylim ([-1 1])
grid on

and the output wave is,

enter image description here

is it the correct value or am i doing some sort mistakes calculating the time period ?

$\endgroup$
3
$\begingroup$

The equation xn=cos(2*pi*(F1)*n*T) expects n to be a sample index vector (n=0:N) where N is the total number of samples. n*T or n/Fs produces the time vector.

Here is a way to plot a single cycle:

F1 = 100e3;
Fs = 1e6;
t = 0:(1/Fs):1/F1;  %Creates time vector for a single cycle
x = cos(2*pi*F1*t);
stem(t, x);

Note that 1/F1 gives the time period of a single cycle.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.