Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this assignment, we use Matlab to build an FM modulator and demodulator. The

ID: 3854808 • Letter: I

Question

In this assignment, we use Matlab to build an FM modulator and demodulator. The Matlab program is given by ExampleFM.m on page 292 of the textbook. The modulating signal m(t) is triangular with amplitude (-1, +1). Run a slightly modified version of the Matlab program to generate:

The modulating signal m(t)

The FM modulated signal

The amplitude spectrum of the FM signal

The demodulated signal

The original (unmodified) Matlab program ExampleFM.m is reproduced below:

% (ExampleFM.m)

% This program uses triangl.m to illustrate frequency modulation

% and demodulation

ts=1.e-4;

t=-0.04:ts:0.04;

Ta=0.01;

m_sig=triangl((t+0.01)/Ta)-triangl((t-0.01)/Ta);

Lfft=length(t); Lfft=2ˆceil(log2(Lfft));

M_fre=fftshift(fft(m_sig,Lfft));

freqm=(-Lfft/2:Lfft/2-1)/(Lfft*ts);

B_m=100;            %Bandwidth of the signal is B_m Hz.

% Design a simple lowpass filter with bandwidth B_m Hz.

h=fir1(80,[B_m*ts]);

%

kf=160*pi;

m_intg=kf*ts*cumsum(m_sig);

s_fm=cos(2*pi*300*t+m_intg);

s_pm=cos(2*pi*300*t+pi*m_sig);

Lfft=length(t); Lfft=2ˆceil(log2(Lfft)+1);

S_fm=fftshift(fft(s_fm,Lfft));

S_pm=fftshift(fft(s_pm,Lfft));

freqs=(-Lfft/2:Lfft/2-1)/(Lfft*ts);

s_fmdem=diff([s_fm(1) s_fm])/ts/kf;

s_fmrec=s_fmdem.*(s_fmdem>0);

s_dec=filter(h,1,s_fmrec);

% Demodulation

% Using an ideal LPF with bandwidth 200 Hz

Trange1=[-0.04 0.04 -1.2 1.2];

figure(1)

subplot(211);m1=plot(t,m_sig);

axis(Trange1); set(m1,’Linewidth’,2);

xlabel(’{it t} (sec)’); ylabel(’{it m}({it t})’);

title(’Message signal’);

subplot(212);m2=plot(t,s_dec);

set(m2,’Linewidth’,2);

xlabel(’{it t} (sec)’); ylabel(’{it m}_d({it t})’)

title(’demodulated FM signal’);

figure(2)

subplot(211);td1=plot(t,s_fm);

axis(Trange1); set(td1,’Linewidth’,2);

xlabel(’{it t} (sec)’); ylabel(’{it s}_{ m FM}({it t})’)

title(’FM signal’);

subplot(212);td2=plot(t,s_pm);

axis(Trange1); set(td2,’Linewidth’,2);

xlabel(’{it t} (sec)’); ylabel(’{it s}_{ m PM}({it t})’)

title(’PM signal’);

figure(3)

subplot(211);fp1=plot(t,s_fmdem);

set(fp1,’Linewidth’,2);

xlabel(’{it t} (sec)’); ylabel(’{it d s}_{ m FM}({it t})/dt’)

title(’FM derivative’);

subplot(212);fp2=plot(t,s_fmrec);

set(fp2,’Linewidth’,2);

xlabel(’{it t} (sec)’);

title(’rectified FM derivative’);

Frange=[-600 600 0 300];

figure(4)

subplot(211);fd1=plot(freqs,abs(S_fm));

axis(Frange); set(fd1,’Linewidth’,2);

xlabel(’{it f} (Hz)’); ylabel(’{it S}_{ m FM}({it f})’)

title(’FM amplitude spectrum’);

subplot(212);fd2=plot(freqs,abs(S_pm));

axis(Frange); set(fd2,’Linewidth’,2);

xlabel(’{it f} (Hz)’); ylabel(’{it S}_{ m PM}({it f})’)

title(’PM amplitude spectrum’);

PLEASE INCLUDE PLOTS FROM MATLAB (PLEASE)

Explanation / Answer

%%% point up FM modulation and demodulation using triangle function

%%% major message signal as a triangle signal, in real life however, this

%%% could be anything like voice signal etc. that we would want to transmit

Function Example FM

Clear all;

clf;

ts = e-4; % sampling interval

t=-0.04:ts:0.04;

Ta=0.01;

% Use triangle function to generate message signal

m_sig=triangle((t+0.01)/Ta)-triangle((t-0.01)/Ta);

%Lm_sig=length(m_sig1);

Lfft=length(t);   % defining DFT (or FFT) size

Lfft=2^ceil(log2(Lfft)) % making Lfft a power of 2 since this makes the Lfft algorithm work fast

M_fre=fftshift(fft(m_sig,Lfft)) % i.e. calculating the frequency domain message signal,

                                 % fft algorithm calculates points from ) to Lfft-1, therefore we use fftshift on this

                                 % result to order samples from -Lfft/2 to Lfft/2 -1

freqm=(-Lfft/2:Lfft/2-1)/(Lfft*ts) % important the frequency axis for the frequency domain DSB modulated signal

B_m=100; % bandwidth of the signal is B_m Hz

h=fir1(80,[B_m*ts]) % defining a simple lowpass filter with bandwidth B_m Hz

kf=160*pi;

m_intg=kf*ts*cumsum(m_sig);

s_fm=cos(2*pi*300*t+m_intg)

s_pm=cos(2*pi*300*t+m_sig)

Lfft=length(t);   % defining DFT (or FFT) size

Lfft=2^ceil(log2(Lfft)+1) % increasing Lfft by factor of 2

S_fm=fftshift(fft(s_fm,Lfft)); % obtaining frequency domain modulated signal

S_pm=fftshift(fft(s_pm,Lfft)); % obtaining frequency domain modulated signal

freqs=(-Lfft/2:Lfft/2-1)/(Lfft*ts); % Defining the frequency axis for the frequency domain DSB modulated signal

%%% Demodulation

% Using an ideal low pass filter with bandwidth 200 Hz

s_fmdem=diff([s_fm(1) s_fm])/ts/kf

s_fmrec=s_fmdem.*(s_fmdem>0);

s_dec=filter(h,1,s_fmrec)

Trange=[-0.04 0.04 -1.2 1.2] % axis ranges for signal, this specifies the range of axis for the plot, the first two parameters are range limits for x-axis, and last two parameters are for y-axis

Frange=[-600 600 0 300] % axis range for frequency domain plots

figure(1)

subplot(211); m1=plot(t,m_sig)

axis(Trange) % set x-axis and y-axis limits

xlabel('{it t}(sec)'); ylabel('{it m}({it t})')

title('Message signal')

subplot(212); m2=plot(t,s_dec)

xlabel('{it t}(sec)'); ylabel('{it m}_d({it t})')

title('Demodulated FM signal')

figure(2)

subplot(211); td1=plot(t,s_fm)

axis(Trange) % set x-axis and y-axis limits

title('FM signal')

xlabel('{it t}(sec)'); ylabel('{it s}_{ m FM}({it t})')

subplot(212); td1=plot(t,s_pm)

axis(Trange) % set x-axis and y-axis limits

title('PM signal')

xlabel('{it t}(sec)'); ylabel('{it s}_{ m PM}({it t})')

figure(3)

subplot(211); fp1=plot(t,s_fmdem)

%axis(Trange) % set x-axis and y-axis limits

xlabel('{it t}(sec)'); ylabel('{it d s}_{ m FM}({it t})')

title('FM Derivative')

subplot(212); fp2=plot(t,s_fmrec)

%axis(Trange) % set x-axis and y-axis limits

xlabel('{it t}(sec)'); %ylabel('{it d}_{ m PM}({it t})')

title('rectified FM Derivative')

figure(4)

subplot(211); fd1=plot(freqs,abs(S_fm))

axis(Frange) % set x-axis and y-axis limits

xlabel('{it f}(Hz)'); ylabel('{it S}_{ m FM}({it f})')

title('FM Amplitude Spectrum')

subplot(212); fd2=plot(freqs,abs(S_pm))

axis(Frange) % set x-axis and y-axis limits

xlabel('{it f}(Hz)'); ylabel('{it S}_{ m PM}({it f})')

title('PM Amplitude Spectrum')

%%% Defining triangle function used in above code

% triangle(t)=1-|t| , if |t|<1

% triangle(t)=0 , if |t|>1

function y = triangle(t)

y=(1-abs(t)).*(t>=-1).*(t<1); % i.e. setting y to 1 -|t| if |t|<1 and to 0 if not

%end

%%% example usage

% t=-5:.1:5

% y=triangle(t)

% stem(t,y)