Friday, March 30, 2012

Display string on scrren in assembly language using 8086


assume cs:code,ds:data
data segment
org 2000h
msg db "MICROPROCESSORLAB",0DH,0AH,"$"
data ends

code segment
start:
mov ax,data
mov ds,ax
lea dx,msg
mov ah,09h
int 21h
mov ah,4ch
int 21h
code ends
end start

Thursday, March 29, 2012

Find the string for polindrome or not using 8086 program in assembly language


assume cs:code,ds:data,es:data
data segment
org 2000h
msg1 db "enter your string",0dh,0ah,"$"
msg2 db "It is palindrom",0dh,0ah,"$"
msg3 db "It is not palindrom",0dh,0ah,"$"
msg4 db "Do you wish to continue y/n",0dh,0ah,"$"
org 4000h
strg1 db 50h dup(0h)
        org 6000h
strg2 db 50h dup(0h)
data ends

code segment
start:
mov ax,data
mov ds,ax
mov es,ax
lea si,strg1
lea di,strg2
mov bx,0h
lea dx,msg1
mov ah,09h
int 21h
next_char:
mov ah,01h
        int 21h
cmp al,0dh
je rev_string
inc bx
stosb
jmp next_char
rev_string:
mov cx,bx
dec di
nxt_byte:
mov al,[di]
mov [si],al
inc si
dec di
loop nxt_byte
lea si,strg1
lea di,strg2
mov cx,bx
cld
rep cmpsb
je palin
lea dx,msg3
mov ah,09h
int 21h
jmp next
palin:
lea dx,msg2
mov ah,09h
int 21h
next:
lea dx,msg4
mov ah,09h
int 21h
mov ah,01h
int 21h
cmp al,'y'
je start
cmp al,'n'
je terminate
        jmp next
terminate:
mov ah,4ch
int 21h
code ends
end start


Find the factorial of a given number using 8086 program in assembly language


ASSUME  CS:CODE, DS:DATA, SS:STACK1
DATA SEGMENT
NUM DW 05H
FACT DW 0H
DATA ENDS
STACK1 SEGMENT
STK DW 100H DUP(0H)
TOP_STACK LABEL WORD
STACK1 ENDS
CODE SEGMENT
START:  MOV AX, DATA
        MOV DS, AX
        MOV AX, STACK1
        MOV SS, AX
        LEA SP, TOP_STACK
        MOV AX, NUM
        CALL FACTO1
        MOV AH, 4CH
        INT 21H
        FACTO1 PROC NEAR
        CMP AX, 01H
        JE GO
        PUSH AX
        DEC AX
        CALL FACTO1
        POP AX
        MUL FACT
        MOV FACT, AX
        RET
GO:     MOV FACT,01H
        RET
        FACTO1 ENDP
        CODE ENDS
        END START
     

Finding the number of even and odd numbers in a given series in assembly language using 8086



ASSUME  CS:CODE, DS:DATA
DATA    SEGMENT
        ORG 5000H
SERIES  DB 35H,66H,11H,12H,22H,56H,8H,2H,1H,9H
COUNT   DB 0AH
ODDCOUNT DB 00H
EVENCOUNT DB 00H
DATA    ENDS
CODE    SEGMENT
START:  MOV AX, DATA
        MOV DS, AX
        LEA SI, SERIES
        MOV CL, COUNT
NEXT:   MOV AX, [SI]
        ROR AX, 01
        JNC EVENV
        INC ODDCOUNT
        JMP OTHER
EVENV:   INC EVENCOUNT
OTHER:  INC SI
        DEC CL
        JNZ NEXT
        MOV AH, 4CH
        INT 21H
CODE    ENDS
        END START


Data transfer in reverse direction in assembly language in 8086


assume cs:code,ds:data
data segment
org 2000h
array1 db 01h,02h,03h,04h,05h,06h,07h,08h,09h,0ah
org 4000h
array2 db 10d dup(0h)
data ends
code segment
start:mov ax,data
mov ds,ax
mov si,2000h
mov di,4009h
mov cx,10d
go:mov al,[si]
mov [di],al
inc si
dec di
dec cx
jnz go
mov ah,4ch
int 21h
code ends
end start

Addition of two numbers in assembly language using 8086


ASSUME CS:CODE, DS:DATA
DATA    SEGMENT
        ORG 3000H
        NUM1 DB 22H
        NUM2 DB 32H
        SUM DB 00H
DATA    ENDS
CODE    SEGMENT
        ASSUME CS:CODE, DS:DATA
START:  MOV AX, DATA
        MOV DS, AX
        MOV AL, NUM1
        MOV BL, NUM2
        ADD AL, BL
        MOV SUM, AL
        MOV AH, 4CH
        INT 21H
CODE ENDS
        END START

Monday, March 26, 2012

Data transfer in forward direction in assembly language using 8086


assume cs:code,ds:data
data segment
org 2000h
array1 db 01h,02h,03h,04h,05h,06h,07h,08h,09h,0ah
org 4000h
array2 db 50d dup(0h)
data ends
code segment
start:mov ax,data
mov ds,ax
mov si,2000h
mov di,4000h
mov cx,10d
go:mov al,[si]
mov [di],al
inc si
inc di
dec cx
jnz go
mov ah,4ch
int 21h
code ends
end start

Data Over laping in assembly language using 8086


assume cs:code,ds:data
data segment
org 2000h
array db 01h,02h,03h,04h,05h,06h,07h,08h,09h,0ah
data ends
code segment
start:mov ax,data
mov ds,ax
mov si,2009h
mov di,200eh
mov cx,10d
go:mov al,[si]
mov [di],al
dec si
dec di
dec cx
jnz go
mov ah,4ch
int 21h
code ends
end start


LCD INTERFACING using 8051/89c51 using TOPView Simulator




2 lines 16 characters, 8 bits, port line selection EN - P3.2,RS - P3.1,RW - P3.3


$MOD51
 EN EQU P3.2
RS EQU P3.1
RW EQU P3.3
ORG 0000H
MOV A,#38H
LCALL LCD_COMD
MOV A,#0EH
LCALL LCD_COMD
MOV A,#06H
LCALL LCD_COMD
MOV A,#01H
LCALL LCD_COMD
MOV A,#'E'
LCALL LCD_TEXT
MOV A,#'C'
LCALL LCD_TEXT
MOV A,#'E'
LCALL LCD_TEXT
LOOP:SJMP LOOP
LCD_COMD:CLR C
LCALL WRITE
RET
LCD_TEXT:SETB C
LCALL WRITE
RET
WRITE:SETB EN
CLR RW
MOV RS,C
MOV P1,A
CLR EN
LCALL DELAY
RET
DELAY: MOV R0,#56
LOOP2: MOV R1,#255
LOOP1: DJNZ R1,LOOP1
             DJNZ R0,LOOP2
RET
END

INTERFACING OF 2 DIGIT SEVENSEGMENT DISPLAY THROUGH 7447 In 89c51/8051 with topview simulator


NOTE: When initializing the external modules set these settings
NON Multiplexed, green or red, common cathode, BCD.
Port line selections:
Number digits -2,
Control line and port line:
CONNECT PORT1.0 TO 1.4 BITS TO DIGIT2 AND PORT 1.4 TO 1.7 TO DIGIT1

$MOD51
ORG 0000H
        SJMP MAIN
ORG 0030H
MAIN: MOV A,#00H
AGAIN:MOV P 1,A
        LCALL DELAY
       ADD A,#01
        DA A
        SJMP AGAIN
;DELAY ROUTINE
        ORG 0040H
DELAY:         MOV R2,#0FFH
UP1:    MOV R1,#0FFH
UP2:   NOP
       NOP
       NOP
        DJNZ R1,UP2
        DJNZ R2,UP1
        RET
        END

INTERFACE OF LEDS TO GET THE TOGGLE OPERATION in 8051/89c51 in topview simulator


$mod51
mov a,#0aah
repeat: mov p1,a
         cpl a
        lcall delay
        sjmp repeat
delay:mov r2,#0ffh
back:mov r1,#0ffh
up1:nop
nop
djnz r1,up1
djnz r2,back
ret
end

Sunday, March 25, 2012

Finding the compliment of numbers using 89c51 microcontroller and topview simulator


$mod51
Org 0000h
mov dptr,#0100h
movx a,@dptr
cpl a
inc dptr
movx @dptr,a
stop:sjmp stop
end

Division of two numbers using 89c51 microcontroller


$mod51
org 0000h
mov dptr,0100h
movx a,@dptr
inc dptr
movx b, @dptr
div a,b
inc dptr
movx @dptr,a
mov a,b
inc dptr
movx @dptr,a
stop:sjmp stop
end

Multiplication of two numbers using 89c51 microcontroller


$mod51
org 0000h
mov dptr,0100h
movx a,@dptr
inc dptr
movx b, @dptr
mul a,b
inc dptr
movx @dptr,a
mov a,b
inc dptr
movx @dptr,a
stop:sjmp stop
end

Substraction of two numbers using 89c51 microcontroller


$mod51
org 0000h
mov dptr,#0100h
movx a,@dptr
inc dptr
movx b,@dptr
clr c
subb a,b
inc dptr
movx @dptr,a
clr a
addc a,#00h
inc dptr
movx @dptr,a
stop:sjmp stop
end

Addition of two numbers using 89c51 microcontroller


$mod51
org 0000h
mov dptr,#0100h
movx a,@dptr
inc dptr
movx b,@dptr
add a,b
inc dptr
movx @dptr,a
clr a
addc a,#00h
inc dptr
movx @dptr,a
stop:sjmp stop
end

Program to display the entered string on screen using 8086


                  ASSUME CS:CODE,DS:DATA
                DATA    SEGMENT
                        ORG     2000H
            INPUT       DB      “ENTER THE STRING”,0DH,0AH,“$”
        OUTPUT          DB      “THE ENTERED STRING IS:” ,0DH,0AH,“$”
         S_LENTH        DB      0
        BUFFER          DB      80 DUP(0)
                DATA  ENDS
                CODE    SEGMENT
              START: MOV AX,DATA
                        MOV DS,AX
                        XOR CL,CL
                        LEA DX,INPUT
                        MOV AH,09H
                        INT 21H
                        LEA BX,BUFFER
            REPEAT:     MOV AH,01H
                        INT 21H
                        CMP AL,0DH
                        JZ EXIT
                        INC CL
                        MOV [BX],AL
                        INC BX
                        JMP REPEAT
               EXIT:    MOV S_LENTH,CL
                        LEA BX,BUFFER
                        ADD BL,CL
                        MOV AL,’$’
                        MOV [BX],AL
                        LEA DX,OUTPUT
                        MOV AH,09H
                        INT 21H
                        LEA DX,BUFFER
                        MOV AH,09H
                        INT 21H
                        MOV AH,4CH
                        INT 21H
                        CODE    ENDS
                        END START


you can display message on screen by entering the program name and by pressing enter

finding the given string as a palindrome or not. using 8086


              ASSUME CS:CODE,DS:DATA
                    DATA   SEGMENT
                           ORG   2000H
                 STRING    DB    “MPMC LAB$”
              S_LENTH      EQU    $-STRING-1
                    MSG1   DB    “THE GIVEN STRING IS A PALINDROME$”
                    MSG2   DB    “THE GIVEN STRING IS NOT A PALINDROME$”
                    DATA  ENDS
                    CODE   SEGMENT
                   START: MOV AX,DATA
                           MOV DS,AX
                           LEA DX,MSG2
                           MOV CX,S_LENTH
                           LEA SI,STRING
                           MOV DI,SI
                           ADD DI,S_LENTH-1
                           SHR CX,1
                   BACK:   MOV AL,[SI]
                           CMP AL,[DI]
                           JNZ NEXT
                           INC SI
                           DEC DI
                           LOOP BACK
                           LEA DX,MSG1
                    NEXT: MOV AH,09H
                           INT 21H
                           MOV AH,4CH
                           INT 21H
                           CODE  ENDS
                           END START

Saturday, March 24, 2012

Factorial of a given number with macro using 8086

FACTORIAL MACRO
                                    XOR CX,CX
                                    XOR AX,AX
                                    INC AX
                                    MOV CL,NUMBER
                                    CMP CL,0
                                    JE GO
               REPEAT:              MUL CX
                                    LOOP REPEAT
                          GO:       MOV FACT,AX
                                    ENDM

                                    ASSUME CS:CODE,DS:DATA

                          DATA      SEGMENT

                                    ORG       2000H

                    NUMBER          DB         08H

                          FACT      DW         0

                          DATA  ENDS

                          CODE      SEGMENT

                        START: MOV AX,DATA

                                    MOV DS,AX

                                    FACTORIAL

                                    MOV AH,4CH

                                    INT 21H

                          CODE      ENDS

                                    END START

Hexadecimal to BCD conversion using 8086

                      ASSUME CS:CODE,DS:DATA
                             DATA      SEGMENT
                                       ORG      2000H
                        HEXA           DB        55H, 99H, 77H, 22H
                     A_LENTH           EQU       $-ARRAY
                   DECI_NO             DB        12D DUP (0)
                   BCD_NO              DW       4 DUP (0)
                             DATA  ENDS
                             CODE      SEGMENT
                            START: MOV AX,DATA
                                       MOV DS,AX
                                       LEA SI,HEXA
                                       LEA DI,DECI_NO
                                       MOV CX,A_LENTH
                        BACK:          XOR AX,AX
                                       MOV AL,[SI]
                                       MOV BL,64H
                                       DIV BL
                                       MOV [DI],AL
                                       INC DI
                                       MOV AL,AH
                                       XOR AH,AH
                                       MOV BH,0AH
                                       DIV BH
                                       MOV [DI],AL
                                       INC DI
                                       MOV [DI],AH
                                       INC SI
                                       INC DI
                                       LOOP BACK
                                       CALL UP2P
                                       MOV AH,4CH
                                       INT 21H
                UP2P             PROC  NEAR
                                 MOV CH,A_LENTH
                                 LEA DI,DECI_NO
                                 LEA BP,BCD_NO
CONTINUE:                        XOR AX,AX
                                 MOV AH,[DI]
                                 INC DI
                                 MOV AL,[DI]
                                 MOV CL,4
                                 SHL AL,CL
                                 INC DI
                                 ADD AL,[DI]
                                 MOV DS:BP,AX
                                 INC DI
                                 INC BP
                                 INC BP
                                 DEC CH
                                 JNZ CONTINUE
                                 RET
                UP2P             ENDP
                                 CODE             ENDS
                                 END START

Circular Convolution using fft Matlab

x1=input('enter the first sequence')
x2=input('enter the second seqquence')
N1=length(x1)
N2=length(x2)
if N1>N2
    x2=[x2,zeros(N2-N1)]      %padding zeros to make lengths of two sequences equal
end
if N2>N1
    x1=[x1,zeros(N2-N1)]
end
N=max(N1,N2)
X1=fft(x1,N);
X2=fft(x2,N);
X3=X1.*X2
x3=ifft(X3)
subplot(2,2,1);
stem(x1);
xlabel('n---->');
ylabel('amplitude');
title('first sequence');
subplot(2,2,2)
stem(x2)
xlabel('n---->');
ylabel('amplitude');
title('second sequence');
subplot(2,2,3)
stem(x3)
xlabel('n----->');
ylabel('amplitude');
title('circular convolution');

Decimation in frequency FFT using Matlab

x=input('enter the sequence')
N=length(x)  
 s=log2(N)
 for m=s-1:-1:0
     for p=0:1:((2^m)-1)
        for k=p:(2^(m+1)):N-1
             b=x(k+1)
             t=(exp(-pi*1i*p/(2^m)))
             x(k+1)=b+x(k+(2^m)+1)
             x(k+(2^m)+1)=(b-x(k+(2^m)+1))*t
         end
     end 
 end
y=bitrevorder(x)

Thursday, March 22, 2012

pulsecode modulation using matlab/PCM using Matlab


Pulse code Modulation:
                By observing the name we think this is a modulation process but in reality this a one type of A to D conversion mechanism i.e. analog to digital conversion technique. Beside this technique we have lot of methods like delta modulation, differential pulse code modulation, adaptive delta modulation, adaptive differential pulse code modulation etc in digital communications. There is always a trade of between all these methods we compare all these based on the bit rate, circuit implementation, and bandwidth. PCM uses lot of operations to convert analog signal to digital signal so the technique is complex.  At the receiver side we employ sampling, quantizing, encoding. Generally the two process named as encoding and quantizing are done in the same circuit known as analog to digital converter i.e. A to D converter. The operations done in the receiver circuit are regeneration of the received signal, decoder, and reconstruction or regeneration. All these operations are performed on the quantized samples. All these operations are done in the same circuit which is digital to analog converter i.e. D to A converter. We know that in the process of transmission we face lot of problems with atmospheric noise and distortion and filtering action of the channel. To combat all these effects we employ regenerating repeaters in the channel to reconstruct and re transmit the coded pulses which are in the way to the receiver. This is time to deal all the processes used in the PCM.  A PCM stream is a digital representation of an analog signal, in which the magnitude of the analog signal is sampled regularly at uniform intervals, with each sample being quantized to the nearest value within a range of digital steps. . This is the standard form used for digital audio in computers, CD and DVD formats. PCM has two properties namely sampling rate and bit depth we all know about sampling rate bit depth refers to the number of digital values that the each sample can take. Quantization error is the main drawback of PCM.

Sampling:
Digital communications requires sampling which is first step in all A to D converters. The sampling is done according to the Nyquist criterion. We may define the process of sampling as a band-limited signal of finite energy, which has no frequency components higher than W hertz, may be completely recovered from the knowledge of its samples taken at the rate of 2W per second. The other definition is a band-limited signal of finite energy, which has no frequency components higher than W hertz, is completely described by specifying the values of the signal at instants of time separated by  seconds. We use these to definitions at the receiver and transmitter. The sampling rate 2W is called the Nyquist rate. And its inverse is called the Nyquist interval. To make the signal as the band limited signal we incorporate the low pass filter at the beginning of the transmitter known as the anti-aliasing filter which stops or attenuates the high frequency components which lie outside the desired frequency band. Then the filtered signal is sampled at a rate higher than the Nyquist rate. A circuit known as the sample and hold circuit is used in sampling to produce the flat top sampling. Flat top sampling provides us to use simple quantizing strategy. Over sampling is used to reduce the distortion in most of the analog to digital converters.

Quantizing:
                Quantization in DSP represents the process which maps the large set values to a single value. A circuit which performs this operation is called the quantizer. This process is also introduces some errors in the signal this is called quantization error or rounding of error. This is a non linear process because this is many to one mapping function. Quantized sample has discrete nature in both time and amplitude. Quantizers are of two types namely uniform and non uniform. In uniform quantization step size is constant while in non uniform quantization step size is varied according to the amplitude of the signal. To perform non uniform quantization one needs to pass the signal into the compressor and then into the uniform quantizer. Non uniform quantization takes care of both high and small variations in the amplitude levels of the signal. we have two laws to perform the quantization they are A-law and µ-law. In the receiver we perform the inverse operation of the quantizer in this we send the received signal into the expander. The device which can perform both operations of expansion and compression is called compander.

Encoding:
                Encoding is done to transmit the signal obtained by the combined effect of the sampling and quantizing over the channel which has undesired characteristics. The signal obtained from the sampling and quantizing is not suitable for transmission as it is over a telephone line i.e. copper pair or radio or microwave link. To combat with the channel impairments we use encoding process. For this we use different types of coding techniques. Encoding process is a one to one representation. A particular arrangement of symbols used in a code to represent a single value of the discrete set is called a code word or character. In a binary code each symbol may be represented by the any two levels of presence of pulse or absence of pulse. Binary wave is robust to noise and easy to regenerate. For example in a binary code each sample is represented with the n number of bits then we can represent the total of 2n discrete levels.

Program:
clear all
close all
clc
t=[0:0.01:3]             %  time
x=sinc(2*pi*t)              %  mesaage signal

%%%%    compressing the signal using mu law one way of quantizing     %%%%

c=compand(x,255,1,'mu/compressor')      %%% the value for mu used here is 255 here 1 represents the maximim value of messagesignal

%%%%    encoding the signal after quantizing   %%%%%

e=uencode(c,3)

%%%%    decodong the signal after receiving   %%%%%

d=udecode(e,3)   %the quantizing levels are 3 if levels are increased the origional and received signal are highly correlate try for 8 instead of 3

%%%%    expanding the received signal    %%%%%

o=compand(d,255,1,'mu/expander')

%%%%%%%     plotting the graphs     %%%%%

figure(1)
hold on                  %for plotting figures on same window for comparision purpose
plot(x,'--red')
plot(o,'black')
hleg=legend('origional signal','received signal using companding')
hold off

%%%%%%%     pcm with out companding     %%%%%%%%

e1=uencode(x,3)
d1=udecode(e1,3)

%%%%%%%%%%%%%%%%%           plotting figures      %%%%%%%%%%%%

figure(2)                   %%% in this case same step size is constant so tracking the origional signal exatly failed
hold on
plot(x,'-.red')
plot(d1,'green')
hleg=legend('origional signal','received signal without companding')
hold off


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

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...