comm2

download comm2

of 13

description

communication

Transcript of comm2

  • ECS 701 Communication Theory

    Lab Session: Wireless communication systems simulation using MATLAB

    November 2013

    1 DSB-AM Analog Modulation

    The purpose of this experiment is to simulate the communication system with double side band amplitudemodulation, and observe and analyze signals at different points in the system.

    A DSB-AM system is illustrated in Figure 1.

    Analog Baseband Signal X

    Carrier Signal

    Transmission Channel X

    Local Generated Carrier Signal

    Lowpass Filtermodulated

    signalmixedsignal

    modulatedsignal

    demodulatedsignal

    Figure 1: DSB-AM communication system block diagram

    1.1 Problem Description

    We want to use DSB-AM system to transmit an analog signal M(t) defined as

    m(t) =

    1, 0 t t03

    2, t03 < t 2t030, otherwise

    This message is modulated by carrier signal c(t) = cos2pifct. It is assumed that t0 = 0.15s and fc = 250Hz.During the experiment you will:

    Modulate the baseband signal with carrier signal. Observe the baseband analog signal, the carrier signal, and the modulated signal. Observe these signal in frequency domain. Demodulate the received signal and apply a low-pass filter to the mixed signal. observe the mixed signal, the frequency response of the filter and the demodulated signal in frequency

    domain.

    compare the original analog signal and the demodulated signal.

    1

  • 1.2 Experiment Process

    1.2.1 Initilizing the parameters

    Open a new MATLAB description file, and insert the following code.

    %% initializing basic parameters

    t0 = 0.15; % signal duration in seconds

    ts = 1/1500; % sampling interval in seconds

    fc = 250; % carrier frequency in Hz

    fs = 1/ts; % sampling frequency in Hz

    df = 0.3; % desired minimum frequency resolution

    After that, save the script and name it as DSB AM.m. Run the script by entering DSB-AM in theMATLAB command window. Observe that in the workspace, the variables are created and initialized.

    1.2.2 Simulate DSB-AM Transmitter

    In the same script file insert the following code under previous code.

    %% At transmitter side

    t= 0:ts:t0; % time vector

    % Generate base band analog signal

    base_band_signal = [ones(1,t0/(3*ts)),-2*ones(1,t0/(3*ts)),zeros(1,t0/(3*ts)+1)];

    % Generate carrier signal

    carrier = cos(2*pi*fc.*t);

    % Modulation

    modulated_signal = base_band_signal .* carrier;

    Save the script and run it again.

    1.2.3 Observe the signals in Time Domain

    To observe the signals we have by now, enter the following commands in the command window.

    2

  • figure

    subplot(3,1,1)

    plot(t, base_band_signal);

    title('Baseband analog signal');

    xlabel('Time');

    subplot(3,1,2)

    plot(t, carrier);

    title('Carrier signal');

    xlabel('Time');

    subplot(3,1,3)

    plot(t, modulated_signal);

    title('Modulated signal');

    xlabel('Time');

    1.2.4 Observe the signals in Frequency Domain

    To observe the same signals in frequency domain, we need to firstly convert the time domain signal tofrequency domain expression using FFT (Fast Fourier Transform), a function already provided by MATLAB.

    In the same script file insert the following code under previous code, and run it again.

    %% Frequency analysis at transmitter side

    % Calculate the length of FFT

    n = 2^(max(nextpow2(length(t)), nextpow2(fs/df)));

    df = fs / n; % actual frequency resolution

    f = (0 : df : df*(n-1)) - fs/2; % frequency vector

    % FFT for base band analog signal

    base_band_signal_f = fft(base_band_signal, n)/fs;

    % FFT for modulated signal

    modulated_signal_f = fft(modulated_signal, n)/fs;

    To observe the signals in frequency domain, enter the following commands in the command window.

    figure

    subplot(2,1,1)

    plot(f, fftshift(abs(base_band_signal_f)));

    title('Baseband analog signal');

    xlabel('Frequency');

    subplot(2,1,2)

    plot(f, fftshift(abs(modulated_signal_f)));

    title('Modulated signal');

    xlabel('Frequency');

    1.2.5 Simulate the DSB-AM Receiver

    In the same script file insert the following code under previous code, and run it again.

    3

  • %% At receiver side

    % Locally generated reference carrier signal (same as carrier)

    carrier_reference = carrier;

    % coherrent detection

    mixed_signal = modulated_signal .* carrier_reference;

    % design ideal low pass filter to mixed_signal

    cut_off_frequency = 150; % cut off frequency of the filter in Hz

    cut_off_frequency_n = floor(cut_off_frequency / df); %cut off frequency index

    low_pass_filter_f = zeros(1, length(f)); % frequency response of the filter

    low_pass_filter_f(1:cut_off_frequency_n) = 2*ones(1, cut_off_frequency_n);

    low_pass_filter_f(length(low_pass_filter_f)-

    cut_off_frequency_n+1:length(low_pass_filter_f)) = 2*ones(1, cut_off_frequency_n);

    % apply the low pass filter to mixed signal in frequency domain

    mixed_signal_f = fft(mixed_signal, n)/fs;

    demodulated_signal_f = mixed_signal_f .* low_pass_filter_f;

    demodulated_signal = real(ifft(demodulated_signal_f))*fs;

    1.2.6 Observe the signals at the receiver

    We will observe the following signals in frequency domain:

    Mixed signal Frequency response of the low-pass filter Demodulated signal

    Enter the following commands in the command window

    subplot(3,1,1)

    plot(f, mixed_signal_f)

    plot(f, fftshift(abs(mixed_signal_f)))

    subplot(3,1,2)

    plot(f, fftshift(abs(low_pass_filter_f)))

    subplot(3,1,3)

    plot(f, fftshift(abs(demodulated_signal_f)))

    1.2.7 Comparison of original signal and demodulated signal

    To compare the original signal with the demodulated signal, enter the following commands in the commandwindow. Note the difference between the two, why?

    figure

    subplot(2,1,1)

    plot(t, base_band_signal)

    subplot(2,1,2)

    plot(t, demodulated_signal(1:length(t)))

    The simulation of the DSB-AM communication system is completed.

    4

  • 2 LSSB-AM analog Modulation

    The purpose of this experiment is to simulate the communication system with lower single side bandamplitude modulation, and observe and analyze signals at different points in the system.

    A LSSB-AM system is illustrated in Figure 1. Note the difference between LSSB-AM system andDSB-AM system.

    Analog Baseband Signal X

    Carrier Signal

    Transmission Channel X

    Local Generated Carrier Signal

    Lowpass Filtermixedsignal

    LSSBSignal

    demodulatedsignal

    Lowpass FilterLSSB

    SignalDSB

    Signal

    Figure 2: LSSB-AM communication system block diagram

    2.1 Problem Description

    We want to use LSSB-AM system to transmit an analog signal M(t) defined as

    m(t) =

    1, 0 t t03

    2, t03 < t 2t030, otherwise

    This message is modulated by carrier signal c(t) = cos2pifct. It is assumed that t0 = 0.15s and fc = 250Hz.During the experiment you will:

    Simulate transmitter of LSSB-AM system. Observe the baseband analog signal, the carrier signal, and the LSSB-AM signal. Observe these signal in frequency domain. Demodulate the received signal and apply a low-pass filter to the mixed signal. observe the mixed signal, the frequency response of the filter and the demodulated signal in frequency

    domain.

    compare the original analog signal and the demodulated signal.

    2.2 Experiment Process

    2.2.1 Initilizing the parameters

    Open a new MATLAB description file, and insert the following code.

    %% initializing basic parameters

    t0=.15; % signal duration

    ts=1/1500; % sampling interval

    fc=250; % carrier frequency

    fs=1/ts; % sampling frequency

    df=0.25; % desired freq.resolution

    5

  • After that, save the script and name it as LSSB AM.m. Run the script by entering LSSB-AM in theMATLAB command window.

    2.2.2 Simulate LSSB-AM Transmitter

    In the same script file insert the following code under previous code.

    %% at Transmitter side

    % time vector

    t=0:ts:t0;

    % Generate base band analog signal

    base_band_signal = [ones(1,t0/(3*ts)),-2*ones(1,t0/

    (3*ts)),zeros(1,t0/(3*ts)+1)];

    % Generate carrier signal

    carrier = cos(2*pi*fc.*t);

    % Modulate signal as DSB-AM first

    dsb_signal = base_band_signal.*carrier;

    % Apply low pass filter to the DSB-AM signal

    % Calculate the length of FFT

    n = 2^(max(nextpow2(length(t)), nextpow2(fs/df)));

    % Actual frequency resolution

    df = fs / n;

    % Frequency Vector

    f = (0 : df : df*(n-1)) - fs/2;

    % FFT on the DSB_signal

    dsb_signal_f = fft(dsb_signal, n)/fs;

    % calculate the location of the carrier frequency in the

    frequency vector

    fc_index = ceil(fc/df);

    % design ideal low pass filter for transmitter

    low_pass_filter_f = zeros(1, length(f));

    low_pass_filter_f(1:fc_index) = ones(1, fc_index);

    low_pass_filter_f(length(low_pass_filter_f)-

    fc_index+1:length(low_pass_filter_f)) = ones(1, fc_index);

    % pass the DSB-AM signal through the filter

    lssb_signal_f = dsb_signal_f .* low_pass_filter_f;

    % calculate the time domain LSSB signal

    lssb_signal = real(ifft(lssb_signal_f))*fs;

    Save the script and run it again.

    2.2.3 Observe frequency response of LPF and compare DSB-AM signal and LSSB-AM signal

    We want to observe the process of converting a DSB-AM signal to a LSSB-AM signal using a Low PassFilter. Note by doing this how the spectrum occupation is reduced.

    To do this, enter the following commands in the command window.

    6

  • subplot(3,1,1)

    plot(f, fftshift(abs(dsb_signal_f)));

    title('DSB-AM signal');

    xlabel('Frequency');

    subplot(3,1,2)

    plot(f, fftshift(abs(low_pass_filter_f)))

    title('Frequency Response of Low-Pass Filter');

    xlabel('Frequency');

    subplot(3,1,3)

    plot(f, fftshift(abs(lssb_signal_f)));

    title('LSSB-AM signal');

    xlabel('Frequency');

    2.2.4 Observe the base band signal, carrier signal, and the modulated LSSB-AM signal intime domain

    We want to see these signals in time domain. Note the difference of DSB and LSSB signals in time domain.Enter the following commands in the command window.

    figure

    subplot(3,1,1)

    plot(t, base_band_signal)

    title('Baseband analog signal');

    xlabel('Time');

    subplot(3,1,2)

    plot(t, carrier)

    title('Carrier signal');

    xlabel('Time');

    subplot(3,1,3)

    plot(t, lssb_signal(1:length(t)))

    title('LSSB-AM signal');

    xlabel('Time');

    2.2.5 Simulation of the receiver side for LSSB

    In the script file LSSB-AM.m, insert the following code under previous code. After that, save the scriptfile and run it again.

    7

  • %% At the Receiver Side % Locally generated reference carrier signal (length must be the same as % the received LSSB-AM signal carrier_reference = cos(2*pi*fc*(0:ts:ts*(length(lssb_signal)-1))); % coherent receiving mixed_signal = lssb_signal .* carrier_reference; % design ideal low pass filter to mixed_signal % cut off frequency of the filter in Hz cut_off_frequency = 150; %cut off frequency index cut_off_frequency_n = floor(cut_off_frequency / df); % frequency response of the filter low_pass_filter_f = zeros(1, length(f)); low_pass_filter_f(1:cut_off_frequency_n) = 4*ones(1, cut_off_frequency_n); low_pass_filter_f(length(low_pass_filter_f)-cut_off_frequency_n+1:length(low_pass_filter_f)) =

    4*ones(1, cut_off_frequency_n); % apply the low pass filter to mixed signal in frequency domain mixed_signal_f = fft(mixed_signal, n)/fs; demodulated_signal_f = mixed_signal_f .* low_pass_filter_f; % calculate time domain demodulated signal demodulated_signal = real(ifft(demodulated_signal_f))*fs;

    2.2.6 Observe the signals at the receiver

    We will observe the following signals in frequency domain:

    Mixed signal Frequency response of the low-pass filter Demodulated signal

    Note how these signals are different from the DSB case.Enter the following commands in the command window

    subplot(3,1,1)

    plot(f, mixed_signal_f)

    plot(f, fftshift(abs(mixed_signal_f)))

    subplot(3,1,2)

    plot(f, fftshift(abs(low_pass_filter_f)))

    subplot(3,1,3)

    plot(f, fftshift(abs(demodulated_signal_f)))

    8

  • 2.2.7 Comparison of original signal and demodulated signal

    To compare the original signal with the demodulated signal, enter the following commands in the commandwindow.

    figure

    subplot(2,1,1)

    plot(t, base_band_signal)

    subplot(2,1,2)

    plot(t, demodulated_signal(1:length(t)))

    The simulation of the LSSB-AM communication system is completed.

    9

  • 3 FM Analog Modulation

    The purpose of this experiment is to simulate the communication system with frequency modulation, andobserve and analyze signals at different points in the system.

    An analog FM system is illustrated in Figure 3.

    Analog SignalMatched

    FilterRecovered

    Data

    Carrier Signal

    IntegratorPhase

    ModulatorDifferenciator

    Figure 3: Analog frequency modulation system block diagram

    3.1 Problem Description

    We want to transmit , using a FM commnication system, short piece of triangular analog signal.The the carrier used to modulate the data has frequency fc = 200Hz. And the frequency modulation

    index equals to 160pi.During the experiment you will:

    Simulate the transmitter for FM communication. Examine what a signal looks like when it is frequency modulated. Examine the spectrum of the modulated signal.

    3.2 Experiment Process

    3.2.1 Initilizing the parameters

    Open a new MATLAB description file, and insert the following code.

    %% Initialize parametersfs = 10e3; %sampling frequencyts = 1./fs; %sampling intervalst = -0.04:ts:0.04; % Time vectorTa = 0.01; %Time period of source signalfc = 200; %Carrier Freqneucy

    After that, save the script and name it as FM.m. Run the script by entering FM in the MATLABcommand window.

    3.2.2 Simulation of FM transmitter

    At a FM transmitter, you will firstly need to generate a baseband analog signal. In this case we aregenerating a triangular wave signal. Here we use the indirect method to modulate the original basebandsignal into a FM signal. The baseband signal is firstly integrated over time using an integrator, and then

    10

  • the output of the integrator is used to control the phase of the carrier signal, with a phase modulator. TheFM equation used in here is:

    f(t) = Acos

    [c + kf

    t

    v () d

    ].

    Insert the following code to the MATLAB script and save and run it.

    %% genetate message signalt1 = -0.02:ts:0; t2 = 0:ts:0.02;m1 = 1 - abs((t1 + Ta)/Ta); % plot(t1, m1), peak of the triangular pulse at t = -Ta = -0.01m1 = [zeros([1 200]), m1, zeros([1 400])];m2 = 1 - abs((t2 - Ta)/Ta); % plot(t2, m2), peak of the triangular pulse at t = Ta = 0.01m2 = [zeros([1 400]), m2, zeros([1 200])];msg = m1 - m2; % message signal, total 801 points, plot(t, msg) %% MODULATIONkf = 160*pi; %modulation indexm_int = ts*cumsum(msg); % Integrating Msgfm = cos(2*fc*pi*t + kf*m_int); % fm = cos(2*pi*fc*t + integral(msg))

    3.2.3 Examine the baseband signal and modulated signal

    We will firstly look at the signal in time domain.

    %% Plotting signal in time domainfigure;subplot(2,1,1);plot(t, msg);title('Message Signal');xlabel('{\it t} (sec)');ylabel('m(t)');grid;

    subplot(2,1,2);plot(t, fm);title('FM');xlabel('{\it t} (sec)');ylabel('FM');grid;

    Now we will examine the spectrum characteristics of a frequency modulated analog signal. Enter thefollowing commands in the command window.

    11

  • %% Finding frequency Response of Signals NFFT = length(t);NFFT = 2^ceil(log2(NFFT));f = (-NFFT/2:NFFT/2-1)/(NFFT*ts); mF = fftshift(fft(msg, NFFT)); % Frequency Response of Message SignalfmF = fftshift(fft(fm, NFFT)); % Frequency Response of FM Signal

    %% Plotting Freq Response of Signalsfigure;subplot(2,2,1);plot(f, abs(mF));title('Freq Response of MSG');xlabel('f(Hz)');ylabel('M(f)');grid;axis([-600 600 0 200]); subplot(2,2,2);plot(f, abs(fmF));title('Freq Response of FM');grid;xlabel('f(Hz)');ylabel('C(f)');axis([-600 600 0 300]);

    3.3 Simulation of FM receiver

    Insert the following code to the Matlab script.

    %% DEMODULATION % step1: Using Differentiatordem = diff(fm); dem = [0, dem]; % make length(dem) = length(fm)rect_dem = abs(dem); % obtain positive frequency part% step2: low pass filterN = 80; % Order of FilterWn = 0.01; % Pass Band Edge Frequency.b = fir1(N, Wn); % Return Numerator of Low Pass FIR filtera = 1; % Denominator of Low Pass FIR Filterrec = filter(b, a, rect_dem);

    3.4 Comparing recovered signal with the original signal

    Now we will plot the recovered signal together with the original signal to compare the them. Enter thefollowing commands in the command window.

    12

  • figure;subplot(2,1,1);plot(t, msg);title('Message Signal');xlabel('{\it t} (sec)');ylabel('m(t)');grid;

    subplot(2,1,2);plot(t, rec);title('Recovered Signal');hold on; yLim = get(gca, 'ylim'); plot([t(N/2) t(N/2)], yLim, 'r:', 'LineWidth', 2); hold off;xlabel('{\it t} (sec)');ylabel('m(t)');grid;

    First DraftB. Zhong. Dec 2012.RevisionB. Zhong. Oct 2013.

    13