# MATLAB code for Frequency modulation (FM) with modulation index

How to generate frequency modulation (FM) in MATLAB? Before that we must know what is FM (frequency modulation). In FM, frequency of the carrier signal having high frequency is varied in accordance with the instantaneous amplitude of the modulating signal having low frequency. Frequency modulated signals are widely used in television and radio transmission systems. FM signals can be easily plotted using simple MATLAB functions. The MATLAB code is shown below, the use of particular code is also given as commented form ( %Comment field ). The given matlab program is capable of accepting two input frequencies and modulation index from the user.

Also see:

## Mathematical representation of FM Signal

Let the modulating signal be

and the carrier signal be

then the modulating signal e(t) is expressed as

where ‘m’ is the modulation index.

## MATLAB Codes

[cc lang=”Matlab”]clc;
clear all;
close all;
fm=input(‘Message Frequency=’);
fc=input(‘Carrier Frequency=’);
mi=input(‘Modulation Index=’);
t=0:0.0001:0.1;
m=sin(2*pi*fm*t);
subplot(3,1,1);
plot(t,m);
xlabel(‘Time’);
ylabel(‘Amplitude’);
title(‘Message Signal’);
grid on;

c=sin(2*pi*fc*t);
subplot(3,1,2);
plot(t,c);
xlabel(‘Time’);
ylabel(‘Amplitude’);
title(‘Carrier Signal’);
grid on;

y=sin(2*pi*fc*t+(mi.*sin(2*pi*fm*t)));%Frequency changing w.r.t Message
subplot(3,1,3);
plot(t,y);
xlabel(‘Time’);
ylabel(‘Amplitude’);
title(‘FM Signal’);
grid on;
[/cc]

## Generated FM Signal

Message Frequency=25
Carrier Frequency=400
Modulation Index=10
Hope this matlab program was helpful to you. Similarly you can find out the codes for ASK, PWM etc in this website. Also we will come up with more. So keep visiting and let us know your views through the comment boxes below.

## 18 thoughts on “MATLAB code for Frequency modulation (FM) with modulation index”

1. Enrique Rodríguez says:

Thank you so much man, it is so helpful 😀

• Baseer says:

yes very much………… Thanks

• kamali says:

thanks …it was useful…can I have a program for fm reciver with superhetrodyne architecture

2. José Lima says:

Watch out! Code above isn’t quite right, you have to use integration. Below the right one:

Ac = 1;
fc = 10;
Amod = 0.5;
fmod = 1.5;
kf = 15;
syms x
mod(x) = Amod*sin(2*pi*fmod*x);
sfm(x) = Ac*cos(2*pi*fc*x + 2*pi*kf*int(mod,x,0,x));
t = 0:1/1000:2;
hold off
plot(t,sfm(t),’k’);
hold on;
plot(t,mod(t),’r’);

• Juri Fedjaev says:

Thanks José, the code above was obviously for Phase-Modulation (PM).

• Harita says:

bt i ran the code in matlab and it worked fine! wts integration for?

3. amandeep kaur says:

hey…dats a nice thing….but as I am new to matlab…I don’t know abt the functions…I have got a project on fm modulation…so plz tell me the meaning of each line and heir function as the comments provided are not worth..plz help me out asap….thnku…

• Jaseem vp says:

Hi amandeep kaur,
Really sorry Mr.amandeep kaur, due to large volume of comments and email I could not able to explain simple basic things. The commands used in the above program are extreme basic and you may get more information by Google search for it.

4. Cristian Iordan says:

Hello, your code is great, just one issue, the modulation formula used is for a cossine modulator signal.

5. ashish tiwari says:

can i get a MATLAB program on
SIMULATION OF COMPARISON BETWEEN AM & FM…???

Also for
ENCRYPTION OF A FILE USING STANDARD ALGORITHM … by ceaser cipher method

6. Duc says:

The code above is complete false.
Its pretty weird to see how people doesnt understand at all how a frequency modulator works.

Im sorry but what you did is an apparent phase modulator.
In a frequency modulator, the modulating signal corresponds to the instantaneous frequency and not to the phase.
The instantaneous frequency is obtained by derivating the phase.
You miss an integration in your code.

….

7. keyvan says:

Hi

8. Mohammed says:

I would like to ask you have you ever done Frequency modulation (FM) by using Simulink?

9. waleed says:

I need a demodulation formula

10. Yousef Elarian says:

I agree with José Lima
Your code is actually for PM (phase modulation)

11. Emilia says:

Can you post a demodulation formula? Pleaseee