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.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
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,
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
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
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)]
% 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
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');
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)]
% *************************************************************************** % 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