Thursday, March 15, 2012

Delta modulation Using MATLAB

DeltaModulation:
                We all know that every digital technique requires the process known as sampling. Delta modulation is also no exception from this. But in delta modulation we use the sampling rates very much greater than the Nyquist rate. This is called as oversampling. Over sampling provides the high correlation between the adjacent samples of the sampled signal. This provides the chance for us to implement the simple quantization technique to construct the encoded signal for the incoming signal. We can describe the DM as the process of approximating the incoming signal as the staircase approximation of the over sampled version of the incoming signal. The process of DM includes the finding of the difference between the incoming signal and the approximated signal. Then the difference is quantized into the two levels only they are ±Δ corresponding to the positive and negative differences between the incoming and approximated signal. At any instance if the approximated signal lies below the actual value of the incoming signal then the approximation value is raised by Δ. In case the approximation lies above the actual value of the incoming signal then its value will be diminished by Δ. The condition posed here is the values of the samples present side by side do not change too rapidly, and the stair case approximation lies within the ±Δ of the input signal.

Mathematical representation:
                Take the variables as the m(n), mq(n), e(n), eq(n). the conventions fallows as m(n) represents the sampled incoming signal, mq(n) denotes the stair case approximated incoming signal, e(n) stands for error signal representing the difference between the present sample of the incoming signal and the latest approximation to it, eq(n) is the quantized version of e(n). And we all know sgn(x) is the signum function of x. at last the output of the quantizer is encoded to produce the DM signal. Here the notations fallowed are discrete time notations because we applying the operations on the sampled version of the incoming signal which is in discrete nature.

e(n)=m(n)-mq(n-1)
eq=Δ.sgn(e(n))
mq(n)=mq(n-1)+eq(n)
Δ=(2*pi*am)/(fm*fs)
Fm is the message signal frequency and fs is the sampling frequency, and Δ is the step size.
Matlab commands:
1.       Sign(x)
This is the matlab command for the signum function of x but on the paper we represent it as sgn(x)
Y = sign(X) returns an array Y the same size as X, where each element of Y is:
1 if the corresponding element of X is greater than zero
0 if the corresponding element of X equals zero
      -1 if the corresponding element of X is less than zero

2.       Stairs(x)
This command plots the stair case approximated signal of x similar to plot command in matlab but plot gives smooth curve. stairs(Y) draws a stairstep graph of the elements of Y.
stairs(mq,'red'): this command plot the graph with the color indicated we can use any color built in matlab.

3.       Hleg=legend(‘string1’,’string2’)
This command places a text in abox at the top right corner of the grph. legendplaces a legend on various types of graphs (line plots, bar graphs, pie charts, etc.). For each line plotted, the legend shows a sample of the line type, marker symbol, and color beside the text label you specify. When plotting filled areas (patch or surface objects), the legend contains a sample of the face color next to the text label.
Algorithm:
The program is simple so no need to explain the algorithm. As you go through the program you can understand the logic and flow of steps.

Program:

t=[0:0.01:1]    %t is the time we are considering for our calculation. Even signal time period is 1 second
m=sinc(2*pi*t) %genrates the sinc pulse with the time period of t
subplot(211) %opens the figure window and splits it into two parts horizontally
hold on    %all the graphs drawn after this command will be plotted on the first part of the figure
plot(m,'*black') %plotting the sinc pulse with the *'s
title('sinc pulse') %putting the title for the graph drawn earlier
xlabel('time')%specifies the xlabel for our graph
ylabel('amplitude')%specifies the ylabel for our figure
d=2*pi/100 %d is the step size we are dividing the total time period into 100 parts of same size

%Logic to calculate the delta modulation signal
%We have total 100 samples over the time period of t
%When the delta modulation we consider error signal is same as the sampled version of the incoming signal
%and we will quantize the error signal
%mq is the star case approximates signal and is is equal to the previous time frame step approximation plus the quantized error signal for the current sample
for n=1:1:100
    if n==1
        e(n)=m(n)
        eq(n)=d*sign(e(n))
        mq(n)=eq(n)
    else
        e(n)=m(n)-mq(n-1)
        eq(n)=d*sign(e(n))
        mq(n)=mq(n-1)+eq(n)
    end
end

%draw the quantized version of the signal on the graph of original signal
stairs(mq,'black')
hleg=legend('original signal','stair case approximated signal')
hold off

%Deltma Modulation of Sine wave
subplot(212)
hold on
m1=sin(2*pi*t)
plot(m1,'black')
title('sin wave')
xlabel('time')
ylabel('amplitude')
d=2*pi/100
for n=1:1:100
    if n==1
        e1(n)=m1(n)
        eq1(n)=d*sign(e1(n))
        mq1(n)=eq1(n)
    else
        e1(n)=m1(n)-mq1(n-1)
        eq1(n)=d*sign(e1(n))
        mq1(n)=mq1(n-1)+eq1(n)
    end
end
stairs(mq1,'black')
hleg=legend('original signal','stair case approximated signal')
hold off




Other Analog to Digital Modulation Techniques

5 comments:

  1. how the for loop in ur code works ??please give an expalnation

    ReplyDelete
    Replies
    1. For loop is used to iterate through the time period. The time period is one second and it is divided into 100 equal intervals to calculate the quantized version of the original signal.

      Delete
  2. if demodulation is included too, it will be very helpful

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete

DC motor control with Pulse Width Modulation Part 1

DC Motor intro DC motor is a device which converts electrical energy into kinetic energy. It converts the DC power into movement. The typica...