📄 fmod.m
字号:
function [outfm, phase] = fmod(msg, fc, fs, Ac, kf, flag)
% FMOD() - This function performs frequency modulation, FM. The %
% integration of the message signal is perform here. %
% %
% t %
% Equation: s(t) = Ac*cos(wc*t + 2pi*kf * SUM m(t) ) %
% 0 %
% msg - message signal vector (see note %
% fc - carrier frequency %
% fs - sampling rate for digitizing %
% Ac - amplitude of carrier %
% kf - modulation index %
% %
% Note: If the message is sampled at a lower frequency, say 8 kHz, it %
% must be interpolated to the sampling rate supplied here before %
% calling this function. %
%-------------------------------------------------------------------------%
%*************************************************************************%
% Filename FMOD.M %
% %
%
%*************************************************************************%
t = 0:1/fs:(length(msg)-1)/fs; % number of samples %
phase = 0;
ph_count= 0;
if (flag == 0)
for x = 0 : 1/fs : (length(msg)-1)/fs
ph_count= ph_count+ 1;
%if mod(x, 1000000/fs) == 0
if mod(x, (0.25*length(msg))/fs ) == 0
phase(ph_count) = (rand()*2*pi);
%phase = phase + (2*pi/4);
%if phase > (2*pi)
% phase = phase - (2*pi);
%end
else
phase(ph_count) = phase(ph_count-1);
end
end
end
%figure
%plot(t,phase);
%pause
if(nargin < 5)
kf = (fc/fs) * (2*pi)/(max(max(abs(msg)))); %modulation index %
end;
outfm = Ac * sin( 2*pi*fc*t + 2*pi*kf * cumsum(msg) + phase); %Generates FM modulated signal
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -