Thursday 20 February 2014

AM-SSB Modulation

If we analyze the AM signal in frequency domain we shall realize that the  two spectral components in the AM signal that lies at equal distances above and below the carrier frequency contain identical information because they are complex conjugates (replica) of each other. The portion above the carrier frequency is called the upper sideband and the portion below the lower sideband. This means that sending an AM-DSB signal is equivalent to sending the same information twice . This is in fact wastage of bandwidth which is the most scarce resource in communication systems. that is the reason AM-SSB (Single Side Band) techniques are develop.
AM-DSB signal in frequency domain with two side bands (Src:wikipedia)

Basically this post  is a continuation of the last post. To generate AM-SSB (AM-Single Side Band) signal we first have to generate AM_DSB (Double Side Band ) signal. There is no way to directly generate an AM-SSB signal.
Bandforms of single-sideband modulation compared to amplitude modulation. (src:wikipedia)

Generating SSB Signals: The Filter Method

The filter method is the simplest and most widely used method of generating SSB signals. The modulating signal is applied to the audio amplifier/ amplifier. The amplifier’s output is fed to one input of a balanced modulator.A crystal oscillator provides the high frequency carrier signal which is also fed into to the balanced modulator. The output of the balanced modulator is a double sideband (DSB) signal.

An SSB signal is produced by passing the DSB signal through a highly selective bandpass filter. With the filter method, it is necessary to select either the upper or the lower sideband. Section of the upper or lower sideband depends upon the total bandwidth available, and the transmitter/receiver design.

Stages involved in generating AM-SSB signal

Monday 17 February 2014

Balanced Modulator

Introduction

A balanced modulator is a circuit that generates a DSB signal, suppressing the carrier and leaving only the sum and difference frequencies at the output. The output of a balanced modulator can be further processed by filters or phase-shifting circuitry to eliminate one of the sidebands, resulting in a SSB signal.
Balanced modulator is a modulator in which the carrier and modulating signal are introduced in such a way that the output contains the two sidebands without the carrier. The term 'Balanced' represents suppressed carrier AM modulated signal.Double side band suppressed carrier modulation is simply AM without the broadcast carrier.
 Recall that the AM signal is defined by:



The carrier term in the spectrum can be eliminated by removing the dc offset from the modulating signal. A band pass filter can be used to select any one of the AM signals. The number of different output frequencies can be significantly reduced if the multiplier accepts sinewaves at the carrier input.
Removing the DC component from the input eliminates the carrier signal and creates DSBSC modulation



An analog multiplier is a type of integrated circuit that can be used as a balanced modulator. Analog multipliers are often used to generate DSB signals. The analog multiplier uses differential amplifiers operating in the linear mode. The carrier must be a sine wave and the multiplier produces the true product of two analog inputs.
simplified diagram for a modulator

Properties of Balanced modulator:

1. There is a 180 phase reversal at the point where +A(t)=+m(t) goes negative. This is typical of DSB-SC modulation. 
2. The bandwidth of the DSB-SC signal is double that of the message signal, that is, BWDSB-SC =2B (Hz). 
3. The modulated signal is centered at the carrier frequency ωc with two identical sidebands (double-sideband) – the lower sideband (LSB) and the upper sideband (USB). Being identical, they both convey the same message component. 
4. The spectrum contains no isolated carrier. Thus the name suppressed carrier. 
5. The 180 phase reversal causes the positive (or negative) side of the envelope to have a shape different from that of the message signal, This is known as envelope distortion, which is typical of DSB-SC modulation. 
6. The power in the modulated signal is contained in all four sidebands. 









Monday 10 February 2014

Line Coding ---- MATLAB code

Here I am going to post MATLAB script for different line coding schemes including RZ, NRZ, Manchester coding, 2B1Q, Differential Manchester and a few other.
It should be noted that dec2binary()  is a separate function created in MATLAB to convert the digital input into its binary counterpart


================================================================================================================================================
MATLAB CODE
================================================================================================================================================

clear all
close all
clc

scrsize = get(0,'screensize');
first = [10, (scrsize(4)/2)+40, (1265/1280)*scrsize(3), (280/800)*scrsize(4)];
second = [10, 50, (625/1280)*scrsize(3), (305/800)*scrsize(4)];
third = [(second(3)+20), 50, second(3:4)];



fprintf('Line coding assignment by Mohammad Ibrahim\n TE-47D\n');

b = input('Number of bits:          ');     % Number of bits.
N = input('Number of samples in final signal:         ');    % Number of samples in final signal.
n = 0:(N-1);                 %Index

% Choose the input type.
input = questdlg(' Choose input', 'Input',...
    'Sine', 'Sawtooth', 'More options', 'Sine');

% Create the  input data sequence.
switch input
    case 'Sine'
        x = sin(2*pi*n/N);
    case 'Sawtooth'
        x = sawtooth(2*pi*n/N);
   
    case 'More options'
        input = questdlg(' More options', 'Input','Tangent','Sinc^2','Random','Random');
        switch input
            case 'Tangent'
                x = tan(2*pi*n/N);
            case 'Sinc^2'
                x = (sin(2*pi*n/N)./(2*pi*n/N)).^2;
            case 'Random'
                x = randn(1,N);             % Random data
                x = x/max(abs(x));          % Scale to +/- 1
        end
end

fprintf('Bits = %g, levels = %g, signal = %s.\n', b, 2^b, input);

% Signal is restricted to between -1 and +1.
x(x>=1)=(1-eps);            % Make  signal from -1 to just less than 1.
x(x<-1)=-1;

% Quantize a signal to "b" bits.
xq=floor((x+1)*2^(b-1));    % Signal is one of 2^n int values (0 to 2^n-1)
xq=xq/(2^(b-1));            % Signal is from 0 to 2 (quantized)
xq=xq-(2^(b)-1)/2^(b);      % Shift signal down (rounding)


figure(1)
subplot(1,2,1)
stem(n,x,'b');
title('Original signal')
grid on

subplot(1,2,2)
stem(xq,'r');
title('Quantized signal')
grid on

set(1,'Position', first)

levels=floor((x+1)*2^(b-1));
L = length(levels);
bits = zeros(1,L*b);
for(i = 1:L)
    z = ((i-1)*b)+1;
    bits(z:z+b-1) = dec2binary(levels(i),b);
end
n1 = 0:1/b:N-1/b;


%to show proper pulses
i1 = 1:30;
i1 = i1./i1;
bits_1 = bits;
for(i = length(bits_1)-1:-1:1)
    if(bits_1(i) == 1)
        bits_1 = [bits_1(1:i), i1, bits_1(i:end)];
    else
        bits_1 = [bits_1(1:i), i1.*0,bits_1(i:end)];
    end
end
    bits_1 = [bits_1, i1.*bits_1(end), bits_1(end)];
n2 = 0:1/(b*32):(N - (1/(b*32)));

figure
plot(n2,bits_1)
axis([n2(1) n2(end) -2 2])
title('Bitstream')
xlabel('Time')
ylabel('Amplitude')
grid on

set(2,'Position', second)


%choose line coding method
lc = questdlg(' Choose method', 'method',...
    'RZ', 'NRZ-L', 'More options', 'RZ');
switch lc
    case 'More options'
        lc = questdlg(' Choose method', 'method',...
        'NRZ-I', 'Manchester', 'More options', 'NRZ-I');
        switch lc
            case 'More options'
                lc = questdlg(' Choose method', 'method',...
                'Differential Manchester', '2B1Q', 'Differential Manchester');
        end
end

switch lc
    case 'RZ'
        %RZ ------------------------------------------------------
        bits_rz = bits_1;
        for(i = 1:length(bits_rz))
            if(bits_rz(i) == 0)
                bits_rz(i) = -1;
            end
        end
        for(i = 1:32:(length(bits_1)))
            bits_rz(i+16:i+31) = zeros(1,16);
        end
   
        figure
        plot(n2,bits_rz)
        axis([n2(1) n2(end) -2 2])
        title('RZ (1 = high; 0 = low)')
        xlabel('Time')
        ylabel('Amplitude')
        grid on
       
    case 'NRZ-L'
        %NRZ-L ---------------------------------------------------
        bits_nrzl = bits_1;
        for(i = 1:length(bits_nrzl))
            if(bits_nrzl(i) == 0)
                bits_nrzl(i) = 1;
            else
                bits_nrzl(i) = -1;
            end
        end


        figure
        plot(n2,bits_nrzl)
        axis([n2(1) n2(end) -2 2])
        title('NRZ-L (1 = low; 0 = high) ')
        xlabel('Time')
        ylabel('Amplitude')
        grid on
       
    case 'NRZ-I'
        % NRZ-I ---------------------------------------------------
        bits_nrzi = ones(1,length(bits_1));
        for(i = 1:length(bits))
            if(bits(i) == 1)
                bits_nrzi((i*32 - 31):end) = -1.*bits_nrzi((i*32 - 31):end);
            end
        end

        figure
        plot(n2,bits_nrzi)
        axis([n2(1) n2(end) -2 2])
        title('NRZ-I (1 = transition; 0 = no transition')
        xlabel('Time')
        ylabel('Amplitude')
        grid on
       
    case 'Manchester'
        %Manchester -----------------------------------------------
        bits_man = ones(1,length(bits_1));
        for(i = 1:length(bits))
            if(bits(i) == 1)
                bits_man((i*32 - 31):(i*32)) = [ones(1,16), -1.*ones(1,16)];
            else
                bits_man((i*32 - 31):(i*32)) = [-1.*ones(1,16), ones(1,16)];
            end
        end

        figure
        plot(n2,bits_man)
        axis([n2(1) n2(end) -2 2])
        title('Manchester (1 = transition high to low; 0 = transition low to high')
        xlabel('Time')
        ylabel('Amplitude')
        grid on

    case 'Differential Manchester'
        %Differential Manchester ----------------------------------
        bits_dman = ones(1,length(bits_1));
        if(bits(1) == 1)
                bits_dman((i*32 - 31):(i*32)) = [ones(1,16), -1.*ones(1,16)];
        else
                bits_dman((i*32 - 31):(i*32)) = [-1.*ones(1,16), ones(1,16)];
        end
   
        for(i = 2:length(bits))
            if(bits(i) == 1)
                prev = -1;
            else
                prev = 1;
                bits_dman((i*32 - 31):(i*32)) = [-1.*ones(1,16), ones(1,16)];
            end
            bits_dman((i*32 - 31):(i*32)) = prev.*bits_dman(((i-1)*32 - 31):((i-1)*32));
        end

        figure
        plot(n2,bits_dman)
        axis([n2(1) n2(end) -2 2])
        title('Differential Manchester (1 = transition; 0 = no transition)')
        xlabel('Time')
        ylabel('Amplitude')
        grid on
       
    case '2B1Q'
        % 2B1Q ----------------------------------------------------
        bits_2b1q = bits_1;
        for(i = 1:64:length(bits_2b1q))
            x = bits_2b1q(i)*10 + bits_2b1q(i+32);
       
            switch x
                case 00
                    bits_2b1q(i:i+63) = -2;
                case 01
                    bits_2b1q(i:i+63) = -1;
                case 10
                    bits_2b1q(i:i+63) = 1;
                case 11
                    bits_2b1q(i:i+63) = 2;
            end
        end

        figure
        plot(n2,bits_2b1q)
        axis([n2(1) n2(end) -3 3])
        title('2B1Q (two bits coupled, 00 = -2; 01 = -1; 10 = 1; and 11 = 2)')
        xlabel('Time')
        ylabel('Amplitude')
        grid on
       
end

set(3,'Position', third)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function [c] = dec2binary(a,b)

c = zeros(1,b);
j = 0;
for(i = (b-1):-1:0)
    j = j+1;
    if (a-(2^i) == floor(a-(2^i)) && a-(2^i) >= 0)
        c(j) = 1;
        a = a - (2^i);
    else
        c(j) = 0;
    end
end

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Difference between convolution and correlation?

Correlation is a statistical measure of how similar or different two waveforms , signals or random processes are. Correlation is used to compare the similarity of two signals, the result is a signal that shows this similarity and reaches its maximum at the time when the two signals match best. Correlation can be used to measure the delay of a certain system. From mathematical point of view correlation is:

E[x(t)y(t)]=∫x(Θ)y(t+Θ)dΘ

Convolution is the operation / transformation that governs the input and output relationship in Linear and Time Invariant system. It is an integral that expresses the amount of overlap of one function as it is shifted over another function. It is used to compute the output of a certain LTI system when a certain input signal is applied to it and its impulse response is known. So we can also say that convolution is kind of a filtering operation. The convolution of two function is:

x(t)*y(t)=∫x(Θ)y(t-Θ)Dθ

Convolution is specifically used for the multiplication of continuous and discrete time signal in time domain and valid for LTI system but correlation is matching and comparison of signal. In the case of a matched filter, correlation and convolution becomes the same.

Matched Filter -- MATLAB code

% matched Filter Code;
clc
clear all
close all

x1=1:12;
l=length(x1);
x2=ones(1,l);
x3=-x2;
n=0:l-1;
x4=sin(2*pi*n/l);


figure;
subplot(411);
stem(x1);
subplot(412);
stem(x2);
subplot(413);
stem(x3);
subplot(414)
stem(x4)

P1=sum(x1.^2);
P2=sum(x2.^2);
P3=sum(x3.^2);
P4=sum(x4.^2);

%Normalizing Signals
x1=x1./sqrt(P1);
x2=x2./sqrt(P2);
x3=x3./sqrt(P3);
x4=x4./sqrt(P4);

SNR=input('Enter The desired value of SNR in dBs:');
N0=10^(-SNR/10);

%generating noise signal of desired SNR
noise=sqrt(N0/l).*randn(1,l);

%Received Signal

r1=x1+noise;
r2=x2+noise;
r3=x3+noise;
r4=x4+noise;

%Matched Filter
M1=filter(fliplr(x1),1,r1);
M2=filter(fliplr(x2),1,r2);
M3=filter(fliplr(x3),1,r3);
M4=filter(fliplr(x4),1,r4);
figure;subplot(411);
plot(M1);
subplot(412);
plot(M2);
subplot(413);
plot(M3);
subplot(414);
plot(M4)

%correlation
X1=xcorr(r1,x1);
X2=xcorr(r2,x2);
X3=xcorr(r3,x3);
X4=xcorr(r4,x4);


figure;subplot(411);
plot(X1);
subplot(412);
plot(X2);
subplot(413);
plot(X3);
subplot(414);
 plot(X4)

Saturday 8 February 2014

Pulse Shaping Filter and Matched Filter

Introduction

In a digital communication system, digital information can be sent on a carrier through changes in its fundamental characteristics such as: phase, frequency, and amplitude. In a physical channel, these transitions can be made smooth by implementing different types of transmit filters. In fact, the use of a filter plays an important part in a communications channel because it is effective at eliminating spectral leakage, reducing channel width, and eliminating interference from adjacent symbols (Inter Symbol Interference, ISI).In bandlimited channels, intersymbol interference (ISI) can be caused by multi-path fading as signals are transmitted over long distances and through various mediums. More specifically, this characteristic of the physical environment causes some symbols to be spread beyond their given time interval. As a result, they can interfere with the following or preceding transmitted symbols. One solution to this problem is the application of the pulse shaping filter . By applying this filter to each symbol that is generated, we are able to reduce channel bandwidth while reducing ISI. In addition, it is common to apply a match filter on the receiver side to minimize these affects.

Pulse Shaping Filter

In communications systems, two important requirements of a wireless communications channel demand the use of a pulse shaping filter. These requirements are: 1) generating bandlimited channels, and 2) reducing inter symbol interference (ISI) from multi-path signal reflections. Both requirements can be accomplished by a pulse shaping filter which is applied to each symbol. In fact, the sinc pulse, shown below, meets both of these requirements because it efficiently utilizes the frequency domain to utilize a smaller portion of the frequency domain, and because of the windowing affect that it has on each symbol period of a modulated signal. A sinc pulse is shown below along with an FFT spectrum of the given signal.
Time Domain and Frequency Domain spectrum of Pulse Shaping Filter 

Matched Filter

In signal processing, a matched filter is obtained by correlating a known signal, or template, with an unknown signal to detect the presence of the template in the unknown signal. This is equivalent to convolving the unknown signal with a conjugated time-reversed version of the template. The matched filter is the optimal linear filter for maximizing the signal to noise ratio (SNR) in the presence of additive stochastic noise.It is well known, that the optimum receiver for an AWGN channel is the matched filter receiver.
The matched filter for a linearly modulated signal using pulse shape p(t)is shown below.

Matched filter schematic
The slicer determines which symbol is “closest” to the matched filter output.
Its operation depends on the symbols being used and the a priori probabilities.
while the pulse shaping filter serves the purpose of generating signals such that each symbol period does not overlap, the matched filter is important to filter out what signal reflections do occur in the transmission process. Because in multipath propogation model a direct-path signal arrives at the receiver before a reflected signal does, it is possible for the reflected signal to overlap with a subsequent symbol period. 

Complete matched filter

Raised Cosine/ Root Raised Cosine Filter

In signal processing, a root-raised-cosine filter (RRC), sometimes known as square-root-raised-cosine filter (SRRC), is frequently used as the transmit and receive filter in a digital communication system to perform matched filtering. This helps in minimizing intersymbol interference (ISI). To have minimum ISI (Intersymbol interference), the overall response of transmit filter, channel response and receive filter has to satisfy Nyquist ISI criterion. 
Mathematical equation used to define raised cosine filter is :

Mathematical expression for raised cosine filter
In this equation, α is the rolloff factor, which determines the sharpness of the frequency response. In addition, R is the number of samples per symbol.
Raised-cosine filter is the most popular filter response satisfying this criterion. Half of this filtering is done on the transmit side and half of this is done on the receive side. On the receive side, the channel response, if it can be accurately estimated, can also be taken into account so that the overall response is Raised-cosine filter.The combined response of two such filters is that of the raised-cosine (RC) filter.

Friday 7 February 2014

Channel Equalization

Introduction

In digital communication systems, the data signals are transmitted through linearly analog channels with distortions, such as telephone lines, cables and wireless radios. In point to point communication two major sources of channel distortion in digital communication systems are multi-path propagation and limited band-width. Linear channel distortion leads to inter-symbol interference (ISI) at the receiver end, which generally leads to high error rate in symbol detection and estimation. The channel has to be estimated or equalized for the coherent detection of the transmitted signal. Channel equalization and channel estimation is used in this regard depending on the system model and feasibility.
typical communication system model

The main purpose of equalization is to reduce intersymbol interference to allow recovery of the transmit symbols. It may be a simple linear filter or a complex algorithm. Channel equalization is a simple way of mitigating the detrimental effects caused by a frequency-selective and/or dispersive communication link between sender and receiver. The equalizer is a transversal filter which tries to approximate an inverse channel so that it nullifies the effect of the channel when the received data passes through it. The ultimate goal of these techniques is to try to estimate or equalize within overhead, processing power and time. he following equalizer types are commonly used in digital communications:
Linear Equalizer: processes the incoming signal with a linear filter
MMSE equalizer: designs the filter to minimize E[|e|2], where e is the error signal, which is the filter output minus the transmitted signal.
Zero Forcing Equalizer: approximates the inverse of the channel with a linear filter.
Decision Feedback Equalizer: augments a linear equalizer by adding a filtered version of previous symbol estimates to the original filter output.
Blind Equalizer: estimates the transmitted signal without knowledge of the channel statistics, using only knowledge of the transmitted signal's statistics.
Adaptive Equalizer: is typically a linear equalizer or a DFE. It updates the equalizer parameters (such as the filter coefficients) as it is processes the data. Typically, it uses the MSE cost function; it assumes that it makes the correct symbol decisions, and uses its estimate of the symbols to compute e, which is defined above.
Viterbi Equalizer: Finds the maximum likelihood (ML) optimal solution to the equalization problem. Its goal is to minimize the probability of making an error over the entire sequence.
BCJR Equalizer: uses the BCJR algorithm (also called the Forward-backward algorithm) to find the maximum a posteriori (MAP) solution. Its goal is to minimize the probability that a given bit was incorrectly estimated.
Turbo equalizer: applies turbo decoding while treating the channel as a convolutional code.

Classification of Equalizers



Thursday 6 February 2014

Manchester Coding

Line Coding

Manchester Coding

Manchester coding consists of combining the NRZ-L and RZ schemes.In Manchester encoding , the duration of the bit is divided into two halves. The voltage remains at one level during the first half and moves to the other level during the
second half. In other words we can say that every symbol has a level transition in the middle: from high to low or low to high , depending on the values of the bit/symbol. It uses only two voltage levels.
  • A ‘One’ is +ve in 1st half and -ve in 2nd half.
  • A ‘Zero’ is -ve in 1st half and +ve in 2nd half.
or viceversa.
The transition at the centre of every bit interval is used for synchronization at the receiver. Manchester encoding is called self-synchronizing. Synchronization at the receiving end can be achieved by locking on to the the transitions, which indicate the middle of the bits
Manchester Line Coding Scheme

Advantages:

  1. No DC component.
  2. Does not suffer from signal droop (suitable for transmission over AC coupled lines).
  3. Easy to synchronise.
  4. Is Transparent.

Disadvantages: 

  1. Because of the greater number of transitions it occupies a significantly large bandwidth. 
  2. Does not have error detection capability.

These characteristic make this scheme unsuitable for use in Wide Area Networks. However, it is widely used in Local Area Networks such as Ethernet and Token Ring.

Differential Manchester

Differential Manchester coding consists of combining the NRZ-I and RZ schemes.Every symbol has a level transition in the middle. But the level at the beginning of the symbol is determined by the symbol value. One symbol causes a level change the other does not.
  • A'ONE' is represented by absence of transition at the beginning of  bit/symbol interval
  • A 'ZERO' is represented by presence of transition at the beginning of bit/symbol interval
In differential Manchester the middle transition is only used for self synchronization and clocking information.

Comparison Between Manchester and Differential Manchester Line Coding Schemes
Modulation rate for Manchester and Differential Manchester is twice the data rate so these schemes are inefficient encoding for long-distance applications.The minimum bandwidth of Manchester and differential Manchester is 2 times that of NRZ. The is no DC component and no baseline wandering. None of these codes has error detection