Week 9 Matlab project, ELEN420/Prof. Kraimeche In this assignment, we use Matlab
ID: 2084588 • Letter: W
Question
Week 9 Matlab project, ELEN420/Prof. Kraimeche
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’);
Explanation / Answer
%%% Illustrate FM modulation and demodulation using triangl function %%% Defining 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 ExampleFM clear all; clf; ts=1e-4; % sampling interval t=-0.04:ts:0.04; Ta=0.01; % Use triangl function to generate message signal m_sig=triangl((t+0.01)/Ta)-triangl((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 fft 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, hence we use fftshift on this % result to order samples from -Lfft/2 to Lfft/2 -1 freqm=(-Lfft/2:Lfft/2-1)/(Lfft*ts) % Defining 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')
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.