Modulate and demodulate a sinusoidal signal. Plot the demodulated signal and compare it to the original signal.
Set the example parameters.
fs = 100; % Sample rate (Hz) ts = 1/fs; % Sample period (s) fd = 25; % Frequency deviation (Hz)
Create a sinusoidal input signal with duration 0.5s and frequency 4 Hz.
t = (0:ts:0.5-ts)'; x = sin(2*pi*4*t);
Create an FM modulator System object™.
MOD = comm.FMModulator('SampleRate',fs,'FrequencyDeviation',fd);
FM modulate the input signal and plot its real part. You can see that the frequency of the modulated signal changes with the amplitude of the input signal.
y = step(MOD,x); plot(t,[x real(y)])
Demodulate the FM modulated signal.
DEMOD = comm.FMDemodulator('SampleRate',fs,'FrequencyDeviation',fd); z = step(DEMOD,y);
Plot the input and demodulated signals. The demodulator output signal exactly aligns with the input signal.
plot(t,x,'r',t,z,'ks') legend('Input Signal','Demod Signal') xlabel('Time (s)') ylabel('Amplitude')