What this "t=0:0.0001:0.1;" statement represent and how this syntax work in the given program?
40 views (last 30 days)
Show older comments
%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);
Answers (2)
Idin Motedayen-Aval
on 6 May 2025
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 Comment
Walter Roberson
on 6 May 2025
Edited: Walter Roberson
on 6 May 2025
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))
nm5 = nominal(mismatches(1:5))
am5-nm5
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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!