% Create an array of 1000 time instants, in steps of 0.001 s.
time=[0:999]*0.001;
% Create a carrier signal at frequency f
f=20; % Hz 
% Create an in-phase carrier 
Icarrier=cos(2*pi*f*time);
% create a quadrature carrier
Qcarrier=sin(2*pi*f*time);
% Modulation index
m=16*pi;
% create a modulating signal at frequency g
g=1; % Hz 
modulatingsignal = sin(2*pi*g*time);
% Frequency modulation
modulation=-m/(2*pi*g)*cos(2*pi*g*time);
% Create the modulated signal
Isignal=cos(2*pi*f.*time + modulation);
Qsignal=sin(2*pi*f.*time + modulation);
% Plot the carriers and modulating signal
subplot(2,1,1);
plot(time,Icarrier);
hold on;
plot(time,Qcarrier,'--r');
hold on;
plot(time,modulatingsignal,':k');
% Annotations
title('I, Q(--) and Modulation(:)');
ylabel('Amplitude (V)');
subplot(2,1,2);
plot(time,Isignal);
hold on;
plot(time,Qsignal,'--r');
% Annotations
title('I and Q Frequency Modulation');
xlabel('Time (s)');
ylabel('Amplitude (V)');