What this "t=0:0.0001:0.1;" statement represent and how this syntax work in the given program?

40 次查看(过去 30 天)
%FM generation
clc;
clear all;
close all;
fc=input('Enter the carrier signal freq in hz,fc=');
fm=input('Enter the modulating signal freq in hz,fm =');
m=input('Modulation index,m= ');
t=0:0.0001:0.1;
c=cos(2*pi*fc*t);%carrier signal
M=sin(2*pi*fm*t);% modulating signal
subplot(3,1,1);plot(t,c);
ylabel('amplitude');xlabel('time index');title('Carrier signal');
subplot(3,1,2);plot(t,M);
ylabel('amplitude');xlabel('time index');title('Modulating signal');
y=cos(2*pi*fc*t-(m.*cos(2*pi*fm*t)));
subplot(3,1,3);plot(t,y);
ylabel('amplitude');xlabel('time index');title('Frequency Modulated signal');
fs=10000;
p=fmdemod(y,fc,fs,(fc-fm));
figure;
subplot(1,1,1);plot(p);

回答(2 个)

KSSV
KSSV 2019-2-26
编辑:KSSV 2019-2-26
t=0:0.0001:0.1
The above line generates an array with first element as 0 and last element as 0.1, where each sucessive elements have a common difference of 0.0001. It is a Arithmetic preogression.

Idin Motedayen-Aval
It is creating a time vector that is used in the next two lines to generate the sine and cosine functions, and then in plotting those functions. As the previous answer said: start at time 0, go up to 0.1, in steps on 0.0001.
Another way to think of it: it's time vector with a sampling time of 0.0001s (0.1ms), or a sampling frequency of 10kHz. This corresponds to "fs = 10000;" near the end of the program.
  1 个评论
Walter Roberson
Walter Roberson 2025-5-6
编辑:Walter Roberson 2025-5-6
Quibble:
time vector with a sampling time of 0.0001 could imply that the vector is like (0:1000)*0.0001 -- time 0/10000, 1/10000, 2/10000 and so on .
But that is not actually the case. The actual vector is 0, 0+0.0001, 0+0.0001+0.0001, 0+0.0001+0.0001+0.0001, and so on
actual = 0:0.0001:0.1;
nominal = (0:1000)*0.0001;
mismatches = find(actual~=nominal);
format long g
am5 = actual(mismatches(1:5))
am5 = 1×5
0.0506 0.0511 0.0523 0.0528 0.054
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
nm5 = nominal(mismatches(1:5))
nm5 = 1×5
0.0506 0.0511 0.0523 0.0528 0.054
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
am5-nm5
ans = 1×5
1.0e+00 * 6.93889390390723e-18 6.93889390390723e-18 6.93889390390723e-18 6.93889390390723e-18 6.93889390390723e-18
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
The actual vector has accumulated floating point round-off; the nominal vector does not have accumulated floating point round-off
@KSSV's description of arithmetic progression was correct; describing it in terms of sampling times is not completely accurate.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by