Alright, so you’re diving into signal processing and you’ve come across Frequency Modulation (FM) one of the most popular techniques used in communication systems. Whether you’re a student trying to run a lab experiment or just curious about how FM works in MATLAB, this one’s for you!
Table of Contents
What is Frequency Modulation?
Before we get to the code, let’s quickly understand what frequency modulation is. In FM, the frequency of the carrier signal is varied in accordance with the amplitude of the input (message) signal. It’s super useful because it’s more resistant to noise compared to amplitude modulation (AM). That’s why FM is commonly used in radio broadcasting.
Now, let’s not waste time and jump into the actual code.
Basic FM in MATLAB
Here’s a simple version of FM written in MATLAB. This will generate a modulated signal based on a basic sine wave message signal.
% Frequency Modulation in MATLAB
clc;
clear all;
close all;
% Time specs
Fs = 10000; % Sampling frequency
t = 0:1/Fs:1; % Time vector for 1 sec
% Message signal
Am = 1; % Amplitude of message signal
fm = 50; % Frequency of message signal
m = Am*sin(2*pi*fm*t); % Message signal
% Carrier signal
Ac = 1; % Carrier amplitude
fc = 500; % Carrier frequency
kf = 2*pi*75; % Frequency sensitivity
% Frequency Modulated signal
s = Ac*cos(2*pi*fc*t + kf*cumsum(m)/Fs);
% Plotting
subplot(3,1,1)
plot(t, m)
title('Message Signal')
xlabel('Time')
ylabel('Amplitude')
subplot(3,1,2)
plot(t, cos(2*pi*fc*t))
title('Carrier Signal')
xlabel('Time')
ylabel('Amplitude')
subplot(3,1,3)
plot(t, s)
title('Frequency Modulated Signal')
xlabel('Time')
ylabel('Amplitude')
What This Code Does
- It creates a sine wave message signal with a frequency of 50 Hz.
- It defines a carrier signal with a much higher frequency (500 Hz).
- It uses MATLAB’s
cumsumfunction to approximate the integration of the message signal which is needed for FM. - Finally, it plots the message signal, carrier signal, and the modulated signal so you can visualize everything.
A Quick Tip
You can tweak the modulation index by playing around with the kf value. This will change how much the carrier frequency shifts depending on your message signal.
Why Use MATLAB for FM?
MATLAB is really handy for visualizing and understanding modulation techniques. You don’t have to worry about too much low-level code. Plus, it helps you focus on concepts first—which is super useful if you’re preparing for exams or projects.
Final Thoughts
This is just a basic FM example to get you started. You can build on top of this for more advanced simulations like demodulation, noise addition, or even real-time FM using audio signals.
If you want me to help with demodulation code or simulation with real audio, just say the word!







