简体   繁体   中英

MATLAB - FM Modulation

I am trying to Frequency modulate a sine signal using Matlab. I have written the following code for the same:

fc = 5000; %Carrier Frequency
fs = 1000; %Signal Frequency
t = 0:0.00001:0.002;
x = sin(2*pi*fs*t);
dev = 50;
subplot(2,1,1);
plot(t,x);
y = fmmod(x,fc,fs,dev);
subplot(2,1,2);
plot(t,y);

It is able to display the first plot command but not the second one. It throws an error: `fmmod' undefined near line 10 column 5 . What is wrong in the above code?

The following function will generate a FM modulated signal - it's not as good (flexible, etc) as fmmod but if you don't have the Comm System Toolbox this may be a good alternative.

function [s t] = makeFM( x, Fc, Fs, strength )
% for a signal x that modulates a carrier at frequency Fc
% produce the FM modulated signal
% works for 1 D input only
% no error checking

x = x(:);

% sampling points in time:
t = ( 0 : numel( x ) - 1 )' / Fs;

% integrate input signal
integratedX = cumsum( x ) / Fs;
s = cos( 2 * pi * ( Fc * t  + strength * integratedX ));   

Put this in your path and call it with similar arguments to the fmmod function (but without optional parameters):

fc = 5000; %Carrier Frequency
fs = 1000; %Signal Frequency
t = 0:0.00001:0.002;
x = sin( 2*pi*fs*t );
dev = 50;
subplot(2,1,1);
plot(t,x);
y = makeFM(x, fc, 2.5*fc, dev); % note sampling frequency must be > carrier frequency!
subplot(2,1,2);
plot(t,y);

Let me know how that works for you.

I guess this is more simple approach

 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 wrt Message subplot(3,1,3); plot(t,y); xlabel('Time'); ylabel('Amplitude'); title('FM Signal'); grid on; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM