Modulation and demodulation of FM signal

        A sine carrier has three parameters: amplitude, frequency, and phase. Therefore, we can load the information of the modulated signal into the changes of these three parameters. When modulating, if the frequency of the carrier varies with the modulating signal, it is called frequency modulation (FM). And FM and PM (phase modulation) are collectively referred to as angle modulation. For angle modulation, it is no longer a linear shift of the spectrum of the original modulation signal, but a nonlinear transformation, which will generate new frequency components, so it is also called nonlinear modulation.

        Frequency modulation FM means that the instantaneous frequency offset changes proportionally with the modulating signal m(t), namely

Among them, Kf is the frequency modulation sensitivity (rad/(s·V)).

        Next will be simulated by MATLAB:

①System  parameter initialization

% 系统参数初始化
clear;clc;close all;

echo on
t0 = .15;           % signal duration
ts = 0.0005;        % sampling interval
fc = 200;           % carrier frequency
kf = 100;            % modulation index
fs = 1/ts;          % sampling frequency
t = [0:ts:t0];      % time vector
df = 0.25;          % required frequency resolution

②  Generation of modulated signal and FM modulated signal

% 调制信号和FM已调信号的产生
% message signal
m = [ones(1,t0 / (3 * ts)),-2 * ones(1,t0 / (3 * ts)),zeros(1,t0 / (3 * ts) + 1)];
int_m(1) = 0;
for i = 1 : length(t) - 1                     % integral of m
    int_m(i + 1) = int_m(i) + m(i) * ts;        % m(i) 是调制信号矩阵的幅值,按顺序将三个阶段排开对应相应的 i
    echo off ;
end
echo on ;
u = cos(2*pi * fc * t + 2*pi * kf * int_m);         % modulated signal
figure(1);
subplot(2,1,1)
plot(t,m(1 : length(t)))
axis([0 0.15 -2.1 2.1])
xlabel('Time')
title('The message signal')
subplot(2,1,2)
plot(t,u(1 : length(t)))
axis([0 0.15 -2.1 2.1])
xlabel('Time')
title('The modulated signal')

③  Spectrum of modulated signal and modulated signal

% 调制信号和已调信号的频谱
[M,m,df1] = fftseq(m,ts,df);              % Fourier transform
M = M / fs;                                 % scaling
f = [0 : df1 : df1 * (length(m) - 1)] - fs / 2;            % frequency vector
[U,u,df1] = fftseq(u,ts,df);                  % Fourier transform
U=U / fs;                                 % scaling
figure(2);
subplot(2,1,1)
plot(f,abs(fftshift(M)))
xlabel('Frequency')
title('Magnitude spectrum of the message signal')
subplot(2,1,2)
plot(f,abs(fftshift(U)))
title('Magnitude spectrum of the modulated signal')
xlabel('Frequency')

④  Demodulation of FM signal

% 信号的解调
[v,phase] = env_phas(u,ts,200);           % demodulation, find phase of u
phi = unwrap(phase);                      % Restore original phase.
dem = (1 / (2*pi * kf)) * (diff(phi) / ts);       % demodulator output, differentiate and scale phase
figure(3)
subplot(2,1,1)
plot(t,m(1:length(t)))
xlabel('Time')
title('The message signal')
subplot(2,1,2)
plot(t,dem(1:length(t)))
xlabel('Time')
title('The demodulated signal')

⑤  Four related functions, the functions are explained in the content

function [M,m,df]=fftseq(m,ts,df) 
%       [M,m,df]=fftseq(m,ts,df)
%       [M,m,df]=fftseq(m,ts)
%FFTSEQ     generates M, the FFT of the sequence m.     
%       The sequence is zero padded to meet the required frequency resolution df.
%       零填充序列,以满足所需的(输入)频率分辨率df
%       ts is the sampling interval. The output df is the final frequency resolution.
%       ts是采样间隔, 输出的df是 最终的 频率分辨率
%       Output m is the zero padded version of input m. M is the FFT.
%       输出m 是 输入m 的零填充版本                        M是FFT变化
fs = 1 / ts;
% nargin 针对当前正在执行的函数,返回函数调用中给定函数输入参数的数目。
if nargin == 2          %  [M,m,df]=fftseq(m,ts)
  n1 = 0;
else                    %  [M,m,df]=fftseq(m,ts,df)
  n1 = fs / df;
end
n2 = length(m);
% y = nextpow2(x);   2^y 为 大于等于x 的最小的二的整数次幂的数字 nextpow2(4)=2  nextpow2(5)=3
n = 2^(max(nextpow2(n1),nextpow2(n2)));
M = fft(m,n);       % Y = fft(X,n)
% 如果 X 是向量且 X 的长度小于 n,则为 X 补上尾零以达到长度 n
% 如果 X 是向量且 X 的长度大于 n,则对 X 进行截断以达到长度 n
m = [m,zeros(1,n - n2)];
df = fs / n;
function [v,phi]=env_phas(x,ts,f0)
%		[v,phi]=env_phas(x,ts,f0)
%		      v=env_phas(x,ts,f0)
% ENV_PHAS   	Returns the envelope and the phase of the bandpass signal x.
              % 返回带通信号的 包络和相位
%		f0 is the center frequency. 
%		ts is the sampling interval.

% nargin 针对当前正在执行的函数,返回函数调用中给定函数输出参数的数目。
if nargout == 2
  z = loweq(x,ts,f0);   % 返回 信号x 的低通等效值
  phi = angle(z);
end
v = abs(hilbert(x));    % 希尔伯特变换,位移 π/2
function xl=loweq(x,ts,f0)
%       xl=loweq(x,ts,f0)
%LOWEQ      returns the lowpass equivalent of the signal x
          % 返回 信号x 的低通等效值
%       f0 is the center frequency. 
%       ts is the sampling interval.
   
t = [0 : ts : ts * (length(x)-1)];  
z = hilbert(x);
xl = z.* exp(-j * 2 * pi * f0 * t);
function p=spower(x)
%       p=spower(x)
%SPOWER     returns the power in signal x
          % 返回 信号x 的功率
p = (norm(x)^2) / length(x);
% norm(x,1),x是一个向量,norm是对向量中所有值的绝对值求和
% p就是x的平均功率

After the simulation, different results can be observed through the frequency modulation sensitivity kf, which makes it easier to understand FM related content.

Guess you like

Origin blog.csdn.net/weixin_58351753/article/details/127833018