CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 1
Colorado Technical University EE 443 – Communication 1
Lab 2: MATLAB Project – Coherent Detection September 2010
Loren K. Schwappach
ABSTRACT: This lab report was completed as a course requirement to obtain full course credit in EE443, Communication 1 at Colorado Technical University. Given a message and a carrier signal, this lab report uses MATLAB to demonstrate the process of coherent detection of a message signal from a modulated signal. All of the code mentioned in this lab report was saved as a MATLAB m-file for convenience, quick reproduction, and troubleshooting of the code. All of the code below can also be found at the end of the report as an attachment, as well as all figures.
If you have any questions or concerns in regards to this laboratory assignment, this laboratory report, the process used in designing the indicated circuitry, or the final conclusions and recommendations derived, please send an email to [email protected]. All computer drawn figures and pictures used in this report are of original and authentic content.
I. INTRODUCTION
MATLAB is a powerful program and is useful in the
visualization of mathematics, physics, and applied
engineering. In this lab exercise MATLAB will be used to
demonstrate modulation and coherent detection. Given the
following:
(1)
(2)
Use MATLAB to investigate the effects of an
oscillator’s synchronization with the carrier signal in the
coherent detection process.
Coherent detection is a process used to recover DSB-
SC signals by first multiplying the signal by a local oscillator
signal with the same frequency and phase as the original
carrier signal and low pass filtering the result.
II. PROCEDURE / RESULTS
To demonstrate all of the signals and local oscillator
synchronization effects, the MATLAB code provided at the
conclusion of this report was utilized, and can be saved as an
m-file. Furthermore, all of the images in this section can be
found at the end of this report in an easier to read format.
First the message signal (1) above and the cosine
signal (2) above were created and graphed in MATLAB, as
illustrated by figures 1 and 2.
Figure 1: m(t) = 5cos(2pi*36t)+2sin(2pi*180t).
Figure 2: c(t) = 10cos(2pi*1500t).
Next the message and carrier signals were multiplied
together resulting in the modulated DSB-SC signal c(t) as
illustrated in the time and frequency domains by figures 3,4,
and 5 below.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 2
Figure 3: DSB-SC Modulated Signal s(t) in the time
domain.
Figure 4: DSB-SC Modulated Signal S(f) in the frequency
spectrum (2-sided spectrum).
Figure 5: DSB-SC Modulated Signal S(f) in the frequency
spectrum (positive spectrum).
You can see by figures 5 and 6 that DSB-SC
modulation results in shifting the message signal both above
(Upper SB) and below (Lower SB) the carrier signal while
suppressing the carrier signal as required by DSB-SC
modulation.
Next, the DSB-SC signal is multiplied by a local
oscillator synchronized both in phase and frequency of the
original carrier signal c(t) this results in the demodulated
output signal as shown by figures 6, 7, and 8.
Figure 6: DSB-SC Demodulated Signal v(t) in the time
domain.
Figure 7: DSB-SC demodulated Signal V(f) in the
frequency spectrum (2-sided spectrum).
Figure 8: DSB-SC Demodulated Signal Y(f) in the
frequency spectrum (positive spectrum).
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 3
You can now see the shape of the original message
signal m(t) as the maximum positive amplitude, and minimum
negative amplitude of v(t) in figure 6. Figures 7 and 8
illustrate that demodulated result puts the message signal m(t)
back to its original frequency position. The original signal can
now be recovered using a LP filter to eliminate the high
frequency components.
Next to verify the effects of an out of synchronization
local oscillator, the local oscillator is first moved out of
frequency with the carrier frequency (by .01% and 2%), next
the local oscillator is moved out of phase with the carrier
phase (by 45º , 90º, and 180º). The results are shown by
figures 9-23 below.
Figure 9: DSB-SC (.01% Out of Sync LO) Demodulated
Signal v(t) in the time domain.
Figure 10: DSB-SC (.01% Out of Sync LO) demodulated
Signal V(f) in the frequency spectrum (2-sided spectrum).
Figure 11: DSB-SC (.01% Out of Sync LO) Demodulated
Signal Y(f) in the frequency spectrum (positive spectrum).
Figure 12: DSB-SC (2% Out of Sync LO) Demodulated
Signal v(t) in the time domain.
Figure 13: DSB-SC (2% Out of Sync LO) demodulated
Signal V(f) in the frequency spectrum (2-sided spectrum).
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 4
Figure 14: DSB-SC (2% Out of Sync LO) Demodulated
Signal V(f) in the frequency spectrum (positive spectrum).
You can see from figures 9-14 that a small error in
frequency synchronization can (2% error (LO=1.47 kHz)) can
completely eliminate signal recovery. However message
recover can still occur with a very small error in frequency
(<= .01% error (LO=1.49985 kHz).
Several additional LO frequencies were tested by
changing the LO error and it was determined that anything
greater than .01% error would eliminate recovery of the
message signal.
Thus, frequency synchronization is extremely
important for coherent detection and should be limited to very
small % error =<.01%.
Next the effects of phase synchronization are
examined and the results are shown by figures 15-23 below.
Figure 15: DSB-SC (45º Out of Phase LO) Demodulated
Signal v(t) in the time domain.
Figure 16: DSB-SC (45º Out of Phase LO) demodulated
Signal V(f) in the frequency spectrum (2-sided spectrum).
.
Figure 17: DSB-SC (45º Out of Phase LO) Demodulated
Signal V(f) in the frequency spectrum (positive spectrum).
Figure 18: DSB-SC (90º Out of Phase LO) Demodulated
Signal v(t) in the time domain.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 5
Figure 19: DSB-SC (90º Out of Phase LO) demodulated
Signal V(f) in the frequency spectrum (2-sided spectrum).
Figure 20: DSB-SC (90º Out of Phase LO) Demodulated
Signal V(f) in the frequency spectrum (positive spectrum).
Figure 21: DSB-SC (180º Out of Phase LO) Demodulated
Signal v(t) in the time domain.
Figure 22: DSB-SC (180º Out of Phase LO) demodulated
Signal V(f) in the frequency spectrum (2-sided spectrum).
Figure 23: DSB-SC (180º Out of Phase LO) Demodulated
Signal V(f) in the frequency spectrum (positive spectrum).
From figures 15-23 above, it is observed that an
increase in the LO phase compared to the carrier phase will
gradually attenuate the signal (0º to <90º), until the signal is
fully attenuated (90 º). There after the signal will be inverted
(>90º to 180º), attenuate the inverted signal (>180º to 270º),
and un-invert and increase to max amplitude (270º to 360º).
Thus the maximum frequency deviation that will
permit signal recovery by the local oscillator is an increase or
decrease in phase of the local oscillator by 90 degrees (fully
attenuated).
The final and bonus part of this lab was to apply a
MATLAB command that could filter the DSB-SC
demodulated output. This is the final step of the coherent
detection process. This was achieved using the “butter”
function to create a low pass third order Butterworth filter
transfer function at 500 Hz, and the “lsim” function to apply
the transfer function to the demodulated time domain output.
The results are shown by figures 24-26 below.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 6
Figure 24: DSB-SC Filtered Demodulated Signal v(t) in the
time domain.
Figure 25: DSB-SC Filtered demodulated Signal V(f) in
the frequency spectrum (2-sided spectrum).
Figure 26: DSB-SC Filtered Demodulated Signal V(f) in
the frequency spectrum (positive spectrum).
Figure 24 demonstrates successfully that coherent
detection can indeed be used for the recovery of a message
signal from a DSB-SC modulated signal. Comparing figure
24 to Figure 1, the v(t) is indeed the message signal m(t) with
an increased magnitude. For example: 34Vpp versus 8Vpp.
For the final part of this lab, the process of coherent
detection and filtering is investigated using MATLAB’s
Simulink tool set. This was accomplished for a sinusoidal
input and a square wave input respectively.
For the input sinusoidal wave two sinusoidal inputs
were added summed resulting in the sinusoidal input used
previously in MATLAB (1). This sinusoidal input was then
modulated (multiplied) by the carrier input previously used in
MATLAB (2). The resultant DSB-SC modulated wave s(t) is
then demodulated (multiplied) by a local oscillator
synchronous in frequency and phase with the original carrier
frequency c(t)’. The final demodulated output is then filtered
to remove the unwanted harmonics restoring our original
message signal m(t).
All of these processes are illustrated in the time and
frequency domain using Simulink.
Figure 27: Simulink investigation of coherent detection
and filtering (sinusoidal input), Overall view.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 7
Figure 28: Simulink investigation of coherent detection
and filtering (sinusoidal input), zoomed for input view.
Figure 29:Simulink investigation of coherent detection and
filtering (sinusoidal input), zoomed for filtering view.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 8
Figure 30: m1(t) = 5cos(2pi*38t).
Figure 31: m1(t) = 2sin(2pi*180t).
Figure 32: m(t) = 5cos(2pi*36t)+2sin(2pi*180t). Notice the
Simulink resultant wave is the same as the result from
MATLAB.
Figure 33: Modulated DSB-SC wave s(t). Notice result
matches MATLAB plot. m(t)*c(t)=s(t).
Figure 34: Demodulated wave v(t). Notice Result matches
MATLAB plot. s(t)*c(t)’ = v(t). The 1st process of
coherent detection is complete. Still need to remove
unwanted harmonics.
Figure 35: Filtered demodulated wave v(t). Notice
resultant wave looks like our original message m(t). This
was accomplished using a 1st order LP Butterworth at
200Hz. The final process of coherent detection is now
complete.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 9
Figure 36: Filtered demodulated wave v(t). Notice
resultant wave looks somewhat like our original message
m(t). This was accomplished using a 1st order LP
Butterworth at 500Hz. Notice the output still contains
several undesired harmonics, the 200Hz LP produced
cleaner results. The final process of coherent detection is
now complete.
Figure 37: Filtered demodulated wave v(t). Notice
resultant wave looks very much like our original message
m(t). This was accomplished using a 5th order LP
Butterworth at 200Hz. This appears to be the best filter
selection. The final process of coherent detection is now
complete.
Figure 38: M(f) frequency spectrum. Notice there are no
harmonics.
Figure 39: Modulated DSB-SC signal S(f) frequency
spectrum.
Figure 40: Demodulated (unfiltered) signal V(f). Notice
the original message is back with several higher frequency
harmonics above 1.5 kHz. We can obtain a scaled
amplitude m(t) by filtering out these high frequency
harmonics.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 10
Figure 41: Demodulated (filtered) signal V(f). Used a 1
st
order LP Butterworth at 200Hz. Notice the harmonics are
now being attenuated.
Figure 42: Demodulated (filtered) signal V(f). Used a 1
st
order LP Butterworth at 500Hz. Notice the harmonics are
not as attenuated as they were in figure 41. Thus Figure
41 provided a better cutoff frequency for the LP filter.
Figure 43: Demodulated (filtered) signal V(f). Used a 5th
order LP Butterworth at 200Hz. Notice the harmonics
extremely attenuated now, providing a very clean copy of
our original message signal. The final stage of coherent
detection is complete.
Next coherent detection and filtering were verified
using a square wave input. For the square wave input a pulse
wave of 5 amplitude, 50% duty cycle, and a period of 20ms
was used. Thereafter the same process used for the sinusoidal
wave was used. However, the final filters required
modification to allow enough LF component sinusoidal waves
(Approx 10*frequency of square wave) in for producing the
output square wave. This is because the input square wave is
actually made up of several sinusoidal harmonics, and without
these harmonics.
Figure 44: Simulink investigation of coherent detection
and filtering (square wave input), Overall view.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 11
Figure 45: Simulink investigation of coherent detection
and filtering (square wave input), zoomed for input view.
Figure 46: Simulink investigation of coherent detection
and filtering (square wave input), zoomed for filtering
view.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 12
Figure 47: m(t) – square wave in time domain.
Figure 48: DSB-SC modulated wave, s(t).
Figure 49: Unfiltered demodulated wave, v(t).
Figure 50: Filtered demodulated wave, v(t). Filtered using
a 1st order Butterworth LP at 50 Hz. Notice we have lost
the square wave’s shape by filtering at too low of a
frequency. Need to increase the LP cutoff to retrieve the
harmonics required by our square wave (A good number
is 10*the highest frequency).
Figure 51: Filtered demodulated wave, v(t). Filtered using
a 1st order Butterworth LP at 500 Hz. Notice we have
retrieved the square wave’s shape by filtering at 500Hz but
the order of our Butterworth is still to low. We need a
higher order filter to provide a cleaner square wave
output.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 13
Figure 52: Filtered demodulated wave, v(t). Filtered using
a 3rd order Butterworth LP at 500 Hz. Notice we have
retrieved the square wave’s shape and cleaned out the high
frequency noise. This is the best of the three filter designs
used. The process of coherent detection is now complete.
Figure 53: M(f) frequency spectrum. Notice the square
wave is made up of several components, thus a good low
pass filter must take these components into account. This
is why the best design used a 3rd
order Butterworth at 500
Hz.
Figure 54: Modulated DSB-SC signal S(f) frequency
spectrum.
Figure 55: Demodulated (unfiltered) wave, v(t).
Figure 56: Demodulated (filtered) wave, V(f). Used a 1
st
order LP Butterworth at 50Hz, too low to correctly
reproduce square wave.
Figure 57: Demodulated (filtered) wave, V(f). Used a 1
st
order LP Butterworth at 500Hz, the square wave shape is
now there but high frequency harmonics are still creating
a problem.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 14
Figure 58: Demodulated (filtered) wave, V(f). Used a 3rd
order LP Butterworth at 500Hz, the square wave shape is
now there and the high frequency harmonic noise has been
eliminated. This is the best of the three filter designs used.
The process of coherent detection is now complete.
III. CONCLUSIONS
MATLAB is a great utility for representing complex
concepts visually and can easily be manipulated to show
signals in various formats. This lab project was successful in
demonstrating MATLABs powerful features in a quick and
easy method, and demonstrating how MATLAB can be used
for analyzing complex processes like coherent detection and
filtering visually.
This lab illustrated that for coherent detection to
work, the local oscillator needs to be in synchronization with
the carrier in both phase and frequency. For coherent
detection the maximum frequency deviation from the carrier
had to be less than .01% of the carrier and less than +-90
degrees in phase with the carrier as shown through MATLAB.
Finally, the importance of low pass filtering was
explored, and from it the importance of using good nth order
filters at a frequency capable of retrieving the original
message. The sinusoidal filter proved was easy to design
since only the max frequency needed consideration. The
square wave filter design however required further analysis,
and it was observed that a cutoff frequency of 10 times the
square waves frequency was needed.
This was a great lab and thoroughly explored the
concepts of coherent detection.
REFERENCES
[1] Haykin, S., “Analog and Digital Communications 2nd
Edition” John Wiley & Sons, Haboken, NJ, 2007.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 15
Figure 59: m(t) = 5cos(2pi*36t)+2sin(2pi*180t).
Figure 60: c(t) = 10cos(2pi*1500t).
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 16
Figure 61: DSB-SC Modulated Signal s(t) in the time domain.
Figure 62: DSB-SC Modulated Signal S(f) in the frequency spectrum (2-sided spectrum).
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 17
Figure 63: DSB-SC Modulated Signal S(f) in the frequency spectrum (positive spectrum).
Figure 64: DSB-SC Demodulated Signal v(t) in the time domain.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 18
Figure 65: DSB-SC demodulated Signal V(f) in the frequency spectrum (2-sided spectrum).
Figure 66: DSB-SC Demodulated Signal Y(f) in the frequency spectrum (positive spectrum).
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 19
Figure 67: DSB-SC (.01% Out of Sync LO) Demodulated Signal v(t) in the time domain.
Figure 68: DSB-SC (.01% Out of Sync LO) demodulated Signal V(f) in the frequency spectrum (2-sided spectrum).
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 20
Figure 69: DSB-SC (.01% Out of Sync LO) Demodulated Signal Y(f) in the frequency spectrum (positive spectrum).
Figure 70: DSB-SC (2% Out of Sync LO) Demodulated Signal v(t) in the time domain.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 21
Figure 71: DSB-SC (2% Out of Sync LO) demodulated Signal V(f) in the frequency spectrum (2-sided spectrum).
Figure 72: DSB-SC (2% Out of Sync LO) Demodulated Signal V(f) in the frequency spectrum (positive spectrum).
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 22
Figure 73: DSB-SC (45º Out of Phase LO) Demodulated Signal v(t) in the time domain.
Figure 74: DSB-SC (45º Out of Phase LO) demodulated Signal V(f) in the frequency spectrum (2-sided spectrum).
.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 23
Figure 75: DSB-SC (45º Out of Phase LO) Demodulated Signal V(f) in the frequency spectrum (positive spectrum).
Figure 76: DSB-SC (90º Out of Phase LO) Demodulated Signal v(t) in the time domain.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 24
Figure 77: DSB-SC (90º Out of Phase LO) demodulated Signal V(f) in the frequency spectrum (2-sided spectrum).
Figure 78: DSB-SC (90º Out of Phase LO) Demodulated Signal V(f) in the frequency spectrum (positive spectrum).
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 25
Figure 79: DSB-SC (180º Out of Phase LO) Demodulated Signal v(t) in the time domain.
Figure 80: DSB-SC (180º Out of Phase LO) demodulated Signal V(f) in the frequency spectrum (2-sided spectrum).
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 26
Figure 81: DSB-SC (180º Out of Phase LO) Demodulated Signal V(f) in the frequency spectrum (positive spectrum).
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 27
Figure 82: Simulink investigation of coherent detection and filtering (sinusoidal input), Overall view.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 28
Figure 83: Simulink investigation of coherent detection and filtering (sinusoidal input), zoomed for input view.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 29
Figure 84:Simulink investigation of coherent detection and filtering (sinusoidal input), zoomed for filtering view.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 30
Figure 85: m1(t) = 5cos(2pi*38t).
Figure 86: m1(t) = 2sin(2pi*180t).
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 31
Figure 87: m(t) = 5cos(2pi*36t)+2sin(2pi*180t). Notice the Simulink resultant wave is the same as the result from
MATLAB.
Figure 88: Modulated DSB-SC wave s(t). Notice result matches MATLAB plot. m(t)*c(t)=s(t).
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 32
Figure 89: Demodulated wave v(t). Notice Result matches MATLAB plot. s(t)*c(t)’ = v(t). The 1
st process of coherent
detection is complete. Still need to remove unwanted harmonics.
Figure 90: Filtered demodulated wave v(t). Notice resultant wave looks like our original message m(t). This was
accomplished using a 1st order LP Butterworth at 200Hz. The final process of coherent detection is now complete.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 33
Figure 91: Filtered demodulated wave v(t). Notice resultant wave looks somewhat like our original message m(t). This
was accomplished using a 1st order LP Butterworth at 500Hz. Notice the output still contains several undesired
harmonics, the 200Hz LP produced cleaner results. The final process of coherent detection is now complete.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 34
Figure 92: Filtered demodulated wave v(t). Notice resultant wave looks very much like our original message m(t). This
was accomplished using a 5th order LP Butterworth at 200Hz. This appears to be the best filter selection. The final
process of coherent detection is now complete.
Figure 93: M(f) frequency spectrum. Notice there are no harmonics.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 35
Figure 94: Modulated DSB-SC signal S(f) frequency spectrum.
Figure 95: Demodulated (unfiltered) signal V(f). Notice the original message is back with several higher frequency
harmonics above 1.5 kHz. We can obtain a scaled amplitude m(t) by filtering out these high frequency harmonics.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 36
Figure 96: Demodulated (filtered) signal V(f). Used a 1
st order LP Butterworth at 200Hz. Notice the harmonics are now
being attenuated.
Figure 97: Demodulated (filtered) signal V(f). Used a 1
st order LP Butterworth at 500Hz. Notice the harmonics are not
as attenuated as they were in figure 41. Thus Figure 41 provided a better cutoff frequency for the LP filter.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 37
Figure 98: Demodulated (filtered) signal V(f). Used a 5th order LP Butterworth at 200Hz. Notice the harmonics
extremely attenuated now, providing a very clean copy of our original message signal. The final stage of coherent
detection is complete.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 38
Figure 99: Simulink investigation of coherent detection and filtering (square wave input), Overall view.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 39
Figure 100: Simulink investigation of coherent detection and filtering (square wave input), zoomed for input view.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 40
Figure 101: Simulink investigation of coherent detection and filtering (square wave input), zoomed for filtering view.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 41
Figure 102: m(t) – square wave in time domain.
Figure 103: DSB-SC modulated wave, s(t).
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 42
Figure 104: Unfiltered demodulated wave, v(t).
Figure 105: Filtered demodulated wave, v(t). Filtered using a 1
st order Butterworth LP at 50 Hz. Notice we have lost the
square wave’s shape by filtering at too low of a frequency. Need to increase the LP cutoff to retrieve the harmonics
required by our square wave (A good number is 10*the highest frequency).
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 43
Figure 106: Filtered demodulated wave, v(t). Filtered using a 1st order Butterworth LP at 500 Hz. Notice we have
retrieved the square wave’s shape by filtering at 500Hz but the order of our Butterworth is still to low. We need a higher
order filter to provide a cleaner square wave output.
Figure 107: Filtered demodulated wave, v(t). Filtered using a 3rd order Butterworth LP at 500 Hz. Notice we have
retrieved the square wave’s shape and cleaned out the high frequency noise. This is the best of the three filter designs
used. The process of coherent detection is now complete.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 44
Figure 108: M(f) frequency spectrum. Notice the square wave is made up of several components, thus a good low pass
filter must take these components into account. This is why the best design used a 3rd
order Butterworth at 500 Hz.
Figure 109: Modulated DSB-SC signal S(f) frequency spectrum.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 45
Figure 110: Demodulated (unfiltered) wave, v(t).
Figure 111: Demodulated (filtered) wave, V(f). Used a 1
st order LP Butterworth at 50Hz, too low to correctly reproduce
square wave.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 46
Figure 112: Demodulated (filtered) wave, V(f). Used a 1
st order LP Butterworth at 500Hz, the square wave shape is now
there but high frequency harmonics are still creating a problem.
Figure 113: Demodulated (filtered) wave, V(f). Used a 3rd order LP Butterworth at 500Hz, the square wave shape is now
there and the high frequency harmonic noise has been eliminated. This is the best of the three filter designs used. The
process of coherent detection is now complete.
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 47
%---------------------------
% MATLAB CODE
%---------------------------
function Lab2 = Comm1Lab2() %Function name for calling in MATLAB % Colorado Technical University % EE 443 - Communications I % Lab 2 - MATLAB Project - Coherent Detection % By Loren K. Schwappach % Uses centeredFFT() for obtaining a two-sided spectrum
%---------------------------
% Generating Carrier, Message and Modulated wave fc = 1500; ac = 10; cPhi = 0; fm1 = 36; %frequency of the first sinusodial wave am1 = 5; %amplitude of the first sinusodial wave fm2 = 180; %frequency of the second sinusodial wave am2 = 2; %amplitude of the second sinusodial wave fs = 10*fc; %sampling frequency ts = 1/fs; %sampling interval t = 0:ts:1-ts; %time vector m = (am1*cos(2*pi*fm1*t) + am2*cos(2*pi*fm2*t)); %composite message wave c = ac*cos(2*pi*fc*t + cPhi); %carrier wave st = m.*c;
% Plot of Message in Time Domain timePlot = figure; %gives graph window a name and keeps it available plot (t(1:500),m(1:500)); %plots sinusodial wave in time domain title('Message - Time domain'); xlabel('Time (s)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([0,27.5e-3,-8,8]); %defines axis [x(min),x(max),y(min),y(max)]
% Plot of Carrier in Time Domain timePlot = figure; %gives graph window a name and keeps it available plot (t(1:200),c(1:200)); %plots sinusodial wave in time domain title('Carrier - Time domain'); xlabel('Time (s)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([2e-3,6e-3,-10,10]); %defines axis [x(min),x(max),y(min),y(max)]
% Plot of Modulated Wave in Time Domain timePlot = figure; %gives graph window a name and keeps it available plot (t(1:500),st(1:500)); %plots sinusodial wave in time domain title('DBS-SC Modulated Signal - Time domain'); xlabel('Time (s)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([6.5e-3,21e-3,-80,80]); %defines axis [x(min),x(max),y(min),y(max)]
% Plot of Modulated Wave in Frequency Domain [Sf,SfRange] = centeredFFT(st,fs); %Uses centeredFFT function freqPlot = figure; %gives graph window a name and keeps it available stem(SfRange,Sf); %Creates stem graph for magnitude spectrum
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 48
title('DBS-SC Modulated - 2 Sided Spectrum') xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([-2000,2000,-1,13]); %defines axis [x(min),x(max),y(min),y(max)]
% Plot of Modulated Wave in Frequency Domain - Close Up freqPlot = figure; %gives graph window a name and keeps it available stem(SfRange,Sf); %Creates stem graph for magnitude spectrum title('DBS-SC Modulated - Pos Spectrum Closeup') xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([1200,1800,-1,13]); %defines axis [x(min),x(max),y(min),y(max)]
% ---------------------------------------------
% In Phase & Freq Demod Segment % Plot of Demodulated Wave in Time Domain cPhib = cPhi; %In phase with carrier fcb = fc; %In frequency with carrier r = cos(2*pi*fcb*t+cPhib).*st; %Multiplies LO with s(t) timePlot = figure; %gives graph window a name and keeps it available plot (t(1:500),r(1:500)); %plots sinusodial wave in time domain title('DBS-SC Demodulated Signal - Time domain'); xlabel('Time (s)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([0,27.5e-3,-80,80]); %defines axis [x(min),x(max),y(min),y(max)]
% Plot of Demodulated Wave in Frequency Domain [Rf,RfRange] = centeredFFT(r,fs); %Uses centeredFFT function freqPlot = figure; %gives graph window a name and keeps it available stem(RfRange,Rf); %Creates stem graph for magnitude spectrum title('DBS-SC DeModulated - 2 Sided Spectrum') xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([-500,500,-1,13]); %defines axis [x(min),x(max),y(min),y(max)]
% Plot of Demodulated Wave in Frequency Domain - Close Up freqPlot = figure; %gives graph window a name and keeps it available stem(RfRange,Rf); %Creates stem graph for magnitude spectrum title('DBS-SC DeModulated - Pos Spectrum Closeup') xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([0,200,-1,13]); %defines axis [x(min),x(max),y(min),y(max)]
% ---------------------------------------------
% Out of Freq Demod Segment % Plot of Out of Freq Demodulated Wave in Time Domain FreqOffset = .9999; % .01% error cPhib = cPhi; %In phase with carrier fcb = fc*FreqOffset; %Out of frequency with carrier r = cos(2*pi*fcb*t+cPhib).*st; timePlot = figure; %gives graph window a name and keeps it available plot (t(1:500),r(1:500)); %plots sinusodial wave in time domain
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 49
title('DBS-SC (Out of Freq) Demodulated Signal - Time domain'); xlabel('Time (s)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([0,27.5e-3,-80,80]); %defines axis [x(min),x(max),y(min),y(max)]
% Plot of Out of Freq Demodulated Wave in Frequency Domain [Rf,RfRange] = centeredFFT(r,fs); %Uses centeredFFT function freqPlot = figure; %gives graph window a name and keeps it available stem(RfRange,Rf); %Creates stem graph for magnitude spectrum title('DBS-SC (Out of Freq) DeModulated - 2 Sided Spectrum') xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([-500,500,-1,13]); %defines axis [x(min),x(max),y(min),y(max)]
% Plot of Out of Freq Demodulated Wave in Frequency Domain - Close Up freqPlot = figure; %gives graph window a name and keeps it available stem(RfRange,Rf); %Creates stem graph for magnitude spectrum title('DBS-SC (Out of Freq) DeModulated - Pos Spectrum Closeup') xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([0,200,-1,13]); %defines axis [x(min),x(max),y(min),y(max)]
%---------------------------
% Out of Freq Demod Segment % Plot of Out of Freq Demodulated Wave in Time Domain FreqOffset = .98; cPhib = cPhi; %In phase with carrier fcb = fc*FreqOffset; %Out of frequency with carrier r = cos(2*pi*fcb*t+cPhib).*st; timePlot = figure; %gives graph window a name and keeps it available plot (t(1:500),r(1:500)); %plots sinusodial wave in time domain title('DBS-SC (Out of Freq) Demodulated Signal - Time domain'); xlabel('Time (s)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([0,27.5e-3,-80,80]); %defines axis [x(min),x(max),y(min),y(max)]
% Plot of Out of Freq Demodulated Wave in Frequency Domain [Rf,RfRange] = centeredFFT(r,fs); %Uses centeredFFT function freqPlot = figure; %gives graph window a name and keeps it available stem(RfRange,Rf); %Creates stem graph for magnitude spectrum title('DBS-SC (Out of Freq) DeModulated - 2 Sided Spectrum') xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([-500,500,-1,13]); %defines axis [x(min),x(max),y(min),y(max)]
% Plot of Out of Freq Demodulated Wave in Frequency Domain - Close Up freqPlot = figure; %gives graph window a name and keeps it available stem(RfRange,Rf); %Creates stem graph for magnitude spectrum title('DBS-SC (Out of Freq) DeModulated - Pos Spectrum Closeup') xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([0,200,-1,13]); %defines axis [x(min),x(max),y(min),y(max)]
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 50
% ---------------------------------------------
% Out of Phase Demod Segment % Plot of Out of Phase Demodulated Wave in Time Domain PhiOffset = (45)*(pi/180); %1 degree off phase cPhib = cPhi+PhiOffset; %In phase with carrier fcb = fc; %Out of frequency with carrier r = cos(2*pi*fcb*t+cPhib).*st; timePlot = figure; %gives graph window a name and keeps it available plot (t(1:500),r(1:500)); %plots sinusodial wave in time domain title('DBS-SC (Out of Phase) Demodulated Signal - Time domain'); xlabel('Time (s)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([0,27.5e-3,-80,80]); %defines axis [x(min),x(max),y(min),y(max)]
% Plot of Out of Phase Demodulated Wave in Frequency Domain [Rf,RfRange] = centeredFFT(r,fs); %Uses centeredFFT function freqPlot = figure; %gives graph window a name and keeps it available stem(RfRange,Rf); %Creates stem graph for magnitude spectrum title('DBS-SC (Out of Phase) DeModulated - 2 Sided Spectrum') xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([-500,500,-13,13]); %defines axis [x(min),x(max),y(min),y(max)]
% Plot of Out of Phase Demodulated Wave in Frequency Domain - Close Up freqPlot = figure; %gives graph window a name and keeps it available stem(RfRange,Rf); %Creates stem graph for magnitude spectrum title('DBS-SC (Out of Phase) DeModulated - Pos Spectrum Closeup') xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([0,200,-13,13]); %defines axis [x(min),x(max),y(min),y(max)]
% ---------------------------------------------
% Out of Phase Demod Segment % Plot of Out of Phase Demodulated Wave in Time Domain PhiOffset = (90)*(pi/180); %2 degrees off phase cPhib = cPhi+PhiOffset; %In phase with carrier fcb = fc; %Out of frequency with carrier r = cos(2*pi*fcb*t+cPhib).*st; timePlot = figure; %gives graph window a name and keeps it available plot (t(1:500),r(1:500)); %plots sinusodial wave in time domain title('DBS-SC (Out of Phase) Demodulated Signal - Time domain'); xlabel('Time (s)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([0,27.5e-3,-80,80]); %defines axis [x(min),x(max),y(min),y(max)]
% Plot of Out of Phase Demodulated Wave in Frequency Domain [Rf,RfRange] = centeredFFT(r,fs); %Uses centeredFFT function freqPlot = figure; %gives graph window a name and keeps it available stem(RfRange,Rf); %Creates stem graph for magnitude spectrum title('DBS-SC (Out of Phase) DeModulated - 2 Sided Spectrum') xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 51
grid; %turns on grid axis([-500,500,-13,13]); %defines axis [x(min),x(max),y(min),y(max)]
% Plot of Out of Phase Demodulated Wave in Frequency Domain - Close Up freqPlot = figure; %gives graph window a name and keeps it available stem(RfRange,Rf); %Creates stem graph for magnitude spectrum title('DBS-SC (Out of Phase) DeModulated - Pos Spectrum Closeup') xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([0,200,-13,13]); %defines axis [x(min),x(max),y(min),y(max)]
% ---------------------------------------------
% Out of Phase Demod Segment % Plot of Out of Phase Demodulated Wave in Time Domain PhiOffset = (180)*(pi/180); %3 degrees off phase cPhib = cPhi+PhiOffset; %In phase with carrier fcb = fc; %Out of frequency with carrier r = cos(2*pi*fcb*t+cPhib).*st; timePlot = figure; %gives graph window a name and keeps it available plot (t(1:500),r(1:500)); %plots sinusodial wave in time domain title('DBS-SC (Out of Phase) Demodulated Signal - Time domain'); xlabel('Time (s)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([0,27.5e-3,-80,80]); %defines axis [x(min),x(max),y(min),y(max)]
% Plot of Out of Phase Demodulated Wave in Frequency Domain [Rf,RfRange] = centeredFFT(r,fs); %Uses centeredFFT function freqPlot = figure; %gives graph window a name and keeps it available stem(RfRange,Rf); %Creates stem graph for magnitude spectrum title('DBS-SC (Out of Phase) DeModulated - 2 Sided Spectrum') xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([-500,500,-13,13]); %defines axis [x(min),x(max),y(min),y(max)]
% Plot of Out of Phase Demodulated Wave in Frequency Domain - Close Up freqPlot = figure; %gives graph window a name and keeps it available stem(RfRange,Rf); %Creates stem graph for magnitude spectrum title('DBS-SC (Out of Phase) DeModulated - Pos Spectrum Closeup') xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([0,200,-13,13]); %defines axis [x(min),x(max),y(min),y(max)]
% ---------------------------------------------
% Filterted In Phase & Freq Demod Segment % Plot of Filtered Demodulated Wave in Time Domain cPhib = cPhi; %In phase with carrier fcb = fc; %In frequency with carrier r = cos(2*pi*fcb*t+cPhib).*st; %Multiplies LO with s(t) [b_num,b_den] = butter(3,2*pi*500,'s'); %3rd order butter xfer fn Filtered_r = lsim(b_num,b_den,r,t); %applies filter to signal timePlot = figure; %gives graph window a name and keeps it available plot (t(1:500),Filtered_r(1:500)); %plots sinusodial wave in time domain title('DBS-SC Filtered Demodulated Signal - Time domain');
CTU: EE 443 – Communications 1: Lab 2: MATLAB Project – Coherent Detection 52
xlabel('Time (s)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([0+(1.1e-3),27.5e-3+(1.1e-3),-37,35]); %defines axis
[x(min),x(max),y(min),y(max)]
% Plot of Filtered Demodulated Wave in Frequency Domain [Rf,RfRange] = centeredFFT(Filtered_r,fs); %Uses centeredFFT function freqPlot = figure; %gives graph window a name and keeps it available stem(RfRange,Rf); %Creates stem graph for magnitude spectrum title('DBS-SC Filtered DeModulated - 2 Sided Spectrum') xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([-500,500,-13,13]); %defines axis [x(min),x(max),y(min),y(max)]
% Plot of Filtered Demodulated Wave in Frequency Domain - Close Up freqPlot = figure; %gives graph window a name and keeps it available stem(RfRange,Rf); %Creates stem graph for magnitude spectrum title('DBS-SC Filtered DeModulated - Pos Spectrum Closeup') xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([0,200,-13,13]); %defines axis [x(min),x(max),y(min),y(max)]
% end Comm1Lab2
% ***************************************************************************
% *************************************************************************** % Additional MATLAB m.file for better FFT % *************************************************************************** % *************************************************************************** function [X,freq]=centeredFFT(x,Fs) %this is a custom function that helps in plotting the two-sided spectrum %x is the signal that is to be transformed %Fs is the sampling rate
N=length(x);
%this part of the code generates that frequency axis if mod(N,2)==0 k=-N/2:N/2-1; % N even else k=-(N-1)/2:(N-1)/2; % N odd end T=N/Fs; freq=k/T; %the frequency axis
%takes the fft of the signal, and adjusts the amplitude accordingly X=fft(x)/N; % normalize the data X=fftshift(X); %shifts the fft data so that it is centered
% ***************************************************************************