manual

50
1. (a) GENERATION OF AM, DSBSC & SSB-SC WAVES AIM: To generate amplitude modulated, double side band and single side band suppressed carrier using MAT LAB Program. EQUIPMENT REQUIRED: 1. Personal Computer With MATLAB 2007 r 1. AMPLITUDE MODULATION FORMULA Vm(t) = Vm Sin ωmt Vc(t) = Vc Sin ωct Vam = Vc + Vm = Vc(1+Vm/Vc sin ωmt) Vam = Vc(1+Ma Sin ωmt) Instantaneous amplitude of modulated signal is Vam(t) = Vc Sin ωct + maVc/2 cos(ωc- ωm)t - maVc/2 * cos(ωc+ ωm)t Where, Vm- amplitude of modulating signal Vc – amplitude of carrier signal Vam – amplitude of carrier signal after modulation Ma – modulation index Wm –angular frequency of modulating signal Wc – angular frequency of carrier signal Vam (t) – amplitude modulated signal ALGORITHM: Read the amplitude and frequency of message and 1

description

for me cce

Transcript of manual

Page 1: manual

1. (a) GENERATION OF AM, DSBSC & SSB-SC WAVES

AIM:

To generate amplitude modulated, double side band and single side band suppressed carrier using MAT LAB Program.

EQUIPMENT REQUIRED:

1. Personal Computer With MATLAB 2007 r

1. AMPLITUDE MODULATION

FORMULA

Vm(t) = Vm Sin ωmt

Vc(t) = Vc Sin ωct

Vam = Vc + Vm = Vc(1+Vm/Vc sin ωmt)

Vam = Vc(1+Ma Sin ωmt)Instantaneous amplitude of modulated signal is

Vam(t) = Vc Sin ωct + maVc/2 cos(ωc- ωm)t - maVc/2 * cos(ωc+

ωm)tWhere,

Vm- amplitude of modulating signalVc – amplitude of carrier signalVam – amplitude of carrier signal after modulationMa – modulation indexWm –angular frequency of modulating signalWc – angular frequency of carrier signalVam (t) – amplitude modulated signal

ALGORITHM:

Read the amplitude and frequency of message and carrier signal

Generate message and carrier signals for the assigned time intervals

Plot the message and carrier signal

Calculate the lower side band and upper side band frequency of the

spectrum and generate the amplitude modulated signal

End the execution of the program

1

Page 2: manual

2. DOUBLE SIDE BAND SUPPRESSED CARRIER:

FORMULA:

Let the modulating signal be ,Vm(t) = vm Sin wmt

Let the carrier signal be,Vc (t) = vc sin wct

DSb-sc signal = Vm (t)* Vc(t)

ALGORITHM:

Start the execution of the program

Read the amplitude and frequency of message and carrier signal

Generate message and carrier signals for the assigned time intervals

Calculate the lower side band and upper side band frequency of the

spectrum and generate the Double side band suppressed carrier

signal

Plot the DSB-SC signal waveform

End the execution of the program

3. SINGLE SIDE BAND SUPPRESSED CARRIER:

ALGORITHM:

Read the sampling frequency ‘ fs‘ and time interval ‘t’

Generate sin wave (message signal) for a fixed frequency

Plot the message signal in time domain and frequency domain

Modulate the message signal for the given carrier frequency and

plot it in the frequency domain

Demodulate the modulated signal to obtain the message signal and plot it

1. PROGRAM CODING FOR AMPLITUDE MODULATION:

2

Page 3: manual

clc;clear all; close all; am=2; ac=4; ka=am/ac; fm=100; t=0:0.01:50;wm=(2*(3.14)*fm*t); fc=1000; wc=2*3.14*fc*t; m=am*(sin(wm)); subplot(3,1,1); plot(t,m); c=ac*(sin(wc)); subplot(3,1,2); plot(t,c);lsb=(ka*ac/2)*(cos(wc-wm)); msb=(ka*ac/2)*(cos(wc+wm)); x=c+lsb-msb;subplot(3,1,3); plot(t,x);

OUTPUT OF AMPLITUDE MODULATION:

2. PROGRAM FOR DOUBLE SIDED BAND SUPRESSED CARRIER:

3

Page 4: manual

fm=100; fc=3000; t=0:0.01:50; am=0.9; ac=1; mi=am/ac;mt=am*sin(2*3.14*fm*t); subplot(3,1,1);plot (t,mt);title ('Double Sided band Supressed Carrier'); ct=ac*sin(2*3.14*fc*t);subplot(3,1,2); plot (t,ct);lsb=cos((2*3.14*fc*t)-(2*3.14*fm*t)); msb=cos((2*3.14*fc*t)+(2*3.14*fm*t)); st=((am*ac)/2)*(lsb-msb); subplot(3,1,3);plot (t,st);

OUTPUT OF DOUBLE SIDED BAND SUPRESSED CARRIER:

3. PROGRAM CODING FOR SINGLE SIDEDDED SUPRESSED CARRIER:

4

Page 5: manual

fs=200;t=(1:100)/fs; y=sin(2*3.14*10*t); figure(1);plot(t,y); xlabel('time ---->');ylabel('amplitude ---->'); title('modulating signal'); s=fft(y,512); w=(0:255)/256*(fs/2); abs_s=abs(s(1:256')); figure(2); plot(w,abs_s); xlabel('frequncy ---->');ylabel('magnitude of Fourier transform ---->'); title('frequency content of sine wave of 10hz'); mod_out=amod(y,50,fs,'amssb');figure(3); plot(t,mod_out); xlabel('time ---->'); ylabel('amplitude ---->'); title('SSB-SC');fft1_out=fft(mod_out,512); abs_out=abs(fft1_out(1:256')); figure(4);plot(w,abs_out); xlabel('frequncy ---->');ylabel('magnitude of Fourier transform ---->'); demod_out=demod(mod_out,50,fs,'amssb'); figure(5);plot(t,demod_out);xlabel('time ---->'); ylabel('amplitude ---->'); title('demodulated waveform');

OUTPUT OF SINGLE SIDED BAND SUPRESSED CARRIER:

5

Page 6: manual

RESULT:Thus the amplitude modulated , double side band and single side band suppressed carrier

signal are generated using MAT LAB Program and the outputs are verified.1.(b) DIGITAL MODULATION TECHNIQUES\

6

Page 7: manual

AIM:

To generate amplitude shift keying, frequency shift keying and phase shit keying using

MATLAB program.

EQUIPMENT REQUIRED:

1. Personal Computer With MATLAB 2007 r

ALGORITHM:

1. Amplitude shift keying:

• Start the execution of the program

• Read the two different amplitude values for high and low inputs

• Generate the output waveform for high and low inputs and plot them in time

domain

• Stop the execution of the program

2. Frequency shift keying:

• Start the execution of the program

• Read the two different Frequencies for high and low inputs

• Generate the output waveform for high and low inputs and plot them in time

domain

• Stop the execution of the program

3. Phase shift keying:

• Start the execution of the program

• Read the amplitude, Frequency and time interval

• Generate the output signal with inphase and outphase components according to

high and low inputs

• Stop the execution of the program

1. PROGRAM CODING FOR AMPLITUDE SHIFT KEYING:

7

Page 8: manual

E1=5;E2=3;f=3000;t1=1:1:50;t=100;res1=sqrt(2*E1/t)*(cos((2*3.14*f*t1)+90));t2=51:1:100;res2=sqrt(2*E2/t)*(cos((2*3.14*f*t2)+90));t=1:1:100;result(1:50)=res1(1:50);result(51:100)=res2(1:50);figure(1);plot(t,result);title('AMPLITUDE SHIFT KEYING');xlabel('time ---->');ylabel('amplitude ---->');grid on;

OUTPUT OF AMPLITUDE SHIFT KEYING

2. PROGRAM CODING FOR FREQUENCY SHIFT KEYING:

8

Page 9: manual

E=15;t1=1:1:50;f1=100;T=50;res1=(sqrt(2*E/T))*(cos(2*3.14*f1*t1));t2=51:1:100;f2=250;res2=(sqrt(2*E/T))*(cos(2*3.14*f2*t2));t=1:1:100;res(1:50)=res1(1:50);res(51:100)=res2(1:50);plot(t,res);title('FREQUENCY SHIFT KEYING');xlabel('time ---->');ylabel('amplitude ---->');

OUTPUT OF FREQUENCY SHIFT KEYING

3. PROGRAM CODING FOR PHASE SHIFT KEYING:

9

Page 10: manual

E=10;f1=1:1:50;f=3000;T=100;i=1;m=2;res1=(sqrt(2*E/T))*(cos((2*3.14*f*t1)+(2*180*i/m)));t2=51:1:100;i=2;res2=(sqrt(2*E/T))*(cos((2*3.14*f*t2)+(2*180*i/m)));t=1:1:100;result(1:50)=res1(1:50);result(51:100)=res2(1:50);figure(1);plot(t,result);title('PHASE SHIFT KEYING');xlabel('time---->');ylabel('amplitude---->');

OUTPUT OF PHASE SHIFT KEYING

RESULT:Thus the amplitude shift keying, frequency shift keying and phase shit keying are

generated using MATLAB program and the outputs are verified.2 (a) PERIODOGRAM

10

Page 11: manual

AIM:To perform periodogram of the given data using FFT.

EQUIPMENT REQUIRED:• TMS 320c50 DSP trainer kit

• Rs 232 cable

ALGORITHM:• Assign location for input data count normal sequence order etc.

• Perform FFT of the input data using decimation in the algorithm

• Square the output of FFT output data

• Divide the squared FFT data with the number of sequence

• Display the periodogram output

PROGRAM CODING FOR SPECTRUM ESTIMATION – PERIODOGRAM METHOD:

INPUT .set 8010HBIT_REV .set 8020HINPLACE .set 8030HTWIDLE .set 8090HPERIO .set 8040HN .set 0HSTG .set 1HSTGC .set 3HGRP .set 4HGRPC .set 5HBFLY .set 6HBFLYC .set 7HDNS .set 8HDNSC .set 9H.MMREGS.TEXT

LDP #100HCALL FFTLAR AR0,#8030HLAR AR1,#PERIOLACC 0HSUB #1HSACL 75HLAR AR2,75H

START ZAP

11

Page 12: manual

MAR *,AR0LT *MPY *+PACBSAR 0CHSACL 65HLT *MPY *+,AR1PACBSAR 0CHADD 65HBSAR 4AND #0FFFHCALL 0B400HMAR *,AR1SACH *+,AR2BANZ START,*-

H B HFFT

LDP #100HLACC NCALL 0B000HLAR AR0,#BIT_REVLAR AR5,#INPLACECALL 0B100HSPLK #3H,STGSPLK #1H,BFLYSPLK #2H,DNSSPLK #2H,0FHZAPLT 0FHMPY NSPL 2HLT 2HMPY STG

LAR AR1,#TWIDLEMAR *,AR1RPT 2HBLPD #TABLE,*+LAR AR1,#TWIDLELACC STGSUB #1HSACL STGCLACC 00SACL GRP

12

Page 13: manual

LAR AR7,STGCSTGLOP LACC GRP

BSAR 1HSACL GRPSUB #1HSACL GRPCLAR AR6,GRPCLACC BFLYSUB #1HSACL BFLYCLACC DNSSUB #1HSACL DNSCLAR AR0,#INPLACE

GRPLOP LAR AR2,BFLYCBFLYLOP CALL 0B200H

MAR *,AR0RPT DNSCLACC *+CALL 0B200HMAR *,AR0RPT DNSCLACC *-CALL 0B300HMAR *,AR0RPT DNSCLACC *-MAR *,AR2BANZ BFLYLOP,*-MAR *,AR0RPT DNSCLACC *+MAR *,AR6BANZ GRPLOP,*-LT BFLYMPY #2HSPL BFLYLT DNSMPY #2HSPL DNSMAR *,AR7BANZ STGLOP,*-RET

TABLE.word 00100H

13

Page 14: manual

.word 00000H

.word 00100H

.word 00000H

.word 00100H

.word 00000H

.word 00100H

.word 00000H

.word 00100H

.word 00000H

.word 00100H

.word 00000H

.word 00100H

.word 00000H

.word 00100H

.word 00000H

.word 00100H

.word 00000H

.word 00100H

.word 00000H

.word 00100H

.word 00000H

.word 00000H

.word 0FF00H

.word 00100H

.word 00000H

.word 00100H

.word 00000H

.word 00100H

.word 00000H

.word 00000H

.word 0FF00H

.word 00100H

.word 00000H

.word 00100H

.word 00000H

.word 00100H

.word 00000H

.word 000B5H

.word 0FF4BH

.word 00100H

.word 00000H

.word 00000H

.word 0FF00H

.word 00100H

.word 00000H

.word 0FF4BH

14

Page 15: manual

.word 0FF4BH

.END

INPUT / OUTPUT

Location:

N: 8000 = A

Normal order : 8010 = 1,0,1,0

Bit reversal : 8020 = 1,1,0,0

FFT output : 8030 = {2,0,2,0}

Periodogram output : 8040 = 4

RESULT:Thus the periodogram of the input data is performed and displayed.

2. (b) MULTIRATE SIGNAL PROCESSING

15

Page 16: manual

AIM:

To implement multirate signals of input frequency of 35 KHZ by a sampling rate of 4 factors

APPARATUS REQUIRED:• TMS 320C50 DSP TRAINER KIT• CRO• AFO• RS232 CABLE

ALGORITHM:Decimation:

• Get the samples of the input frequency signal at 35 kHz• Get the sample rate values• Load the auxiliary register ARO with factor 4• Perform the convolution of the samples of filter co efficient• The output of the fir filter is sent out of the DAC once every 4 outputs• Next data is loaded in DAC after convolution and send out after next 4 sample

Interpolation:• Get the samples of the input frequency signal at 35 KHZ at lower sampling rate• Load the filter co efficient from program memory location• Move the filter co efficient from program memory location to data memory location• Find convolution of input data with the filter co efficient• The output is increased by a factor 4

BLOCK DIAGRAM FOR DECIMATION

FLOW CHART DECIMATION:

16

Page 17: manual

PROGRAM FOR DECIMATION

Program description:

In this program the sampling rate at the input is 35 KHz. This input sampling rate is reduced by a factor of 4 at the output. For this, the auxiliary register AR0 is loaded with the value of 4 initially. Then the output of the FIR filter is sent out to the DAC only once out of 4 outputs. i.e. when ever the register AR0 becomes 0, the filter output is sent to the DAC and reloaded with 4. Where 4 is the decimation factor of this decimator.

Approximation type: Window design - Rectangular WindowFilter type: Low pass filterFilter Order: 52Cutoff frequency in KHz = 4.000000

.mmregs

17

Page 18: manual

.textB START

CTABLE:.word 0FF82H.word 083H.word 0167H.word 01CFH.word 0188H.word 09DH.word 0FF5BH.word 0FE38H.word 0FDACH.word 0FE01H.word 0FF31H.word 0DEH.word 0271H.word 0342H.word 02DDH.word 0132H.word 0FEADH.word 0FC20H.word 0FA92H.word 0FAEEH.word 0FDB6H.word 02CCH.word 096AH.word 0104CH.word 015F9H.word 0192EH.word 0192EH.word 015F9H.word 0104CH.word 096AH.word 02CCH.word 0FDB6H.word 0FAEEH.word 0FA92H.word 0FC20H.word 0FEADH.word 0132H.word 02DDH.word 0342H.word 0271H.word 0DEH.word 0FF31H.word 0FE01H

18

Page 19: manual

.word 0FDACH

.word 0FE38H

.word 0FF5BH

.word 09DH

.word 0188H

.word 01CFH

.word 0167H

.word 083H

.word 0FF82H** Move the Filter coefficients* from program memory to data memory*START:

MAR *,AR0LAR AR0,#0200HRPT #33HBLKP CTABLE,*+SETC CNF

** Input data and perform convolution*

LAR AR0,#4HISR:

LDP #0AHLACC #0SACL 0OUT 0,05 ;pulse to find sampling frequencyIN 0,06HLAR AR7,#0 ;change value to modify sampling freq.MAR *,AR7

BACK: BANZ BACK,*-IN 0,4NOPNOPNOPNOPMAR *,AR1LAR AR1,#0300HLACC 0AND #0FFFHSUB #800HSACL *LAR AR1,#333HMPY #0ZAC

19

Page 20: manual

RPT #33HMACD 0FF00H,*-APACLAR AR1,#0300HSACH * ;give as sach *,1 incase of overflowLACC *ADD #800HSFR ;remove if o/p is less amplitudeSACL *

MAR *,AR0BANZ NO_OUT,*-

MAR *,AR1OUT *,4LAR AR0,#4H

NO_OUT:LACC #0FFH

SACL 0OUT 0,05NOPB ISR.end

BLOCK DIAGRAM FOR INTERPOLATION

FLOW CHART INTERPOLATION:

20

Page 21: manual

PROGRAM FOR INTERPOLATIONPROGRAM DESCRIPTION:

In this program the sampling rate is increased at the input by including zeros. The samples are taken at the lower sampling rate and since this program uses the interpolation factor of 4, three zeros are included after each sample taken from the ADC. So the number of samples and thus the sampling rate is also increased.

• Approximation type: Window design - Rectangular Window• Filter type: Low pass filter• Filter Order: 52• Cutoff frequency in KHz = 4.000000

.mmregs

21

Page 22: manual

.textB START

CTABLE:.word 0FF82H.word 083H.word 0167H.word 01CFH.word 0188H.word 09DH.word 0FF5BH.word 0FE38H.word 0FDACH.word 0FE01H.word 0FF31H.word 0DEH.word 0271H.word 0342H.word 02DDH.word 0132H.word 0FEADH.word 0FC20H.word 0FA92H.word 0FAEEH.word 0FDB6H.word 02CCH.word 096AH.word 0104CH.word 015F9H.word 0192EH.word 0192EH.word 015F9H.word 0104CH.word 096AH.word 02CCH.word 0FDB6H.word 0FAEEH.word 0FA92H.word 0FC20H.word 0FEADH.word 0132H.word 02DDH.word 0342H.word 0271H.word 0DEH.word 0FF31H.word 0FE01H

22

Page 23: manual

.word 0FDACH

.word 0FE38H

.word 0FF5BH

.word 09DH

.word 0188H

.word 01CFH

.word 0167H

.word 083H

.word 0FF82H** Move the Filter coefficients* from program memory to data memory*START:

MAR *,AR0LAR AR0,#0200HRPT #33HBLKP CTABLE,*+SETC CNF

** Input data and perform convolution*

LAR AR0,#4HISR: LDP #0AH

LACC #0SACL 0OUT 0,05 ;pulse to find sampling frequencyMAR *,AR0BANZ INC0,*-IN 0,06H

; LAR AR7,#0 ;change value to modify sampling freq.; MAR *,AR7;BACK: BANZ BACK,*-

RPT #10HIN 0,4LAR AR0,#4HB STORE

INC0: SPLK #0H,0HRPT #15H

NOPSTORE: NOP

NOPNOPNOPMAR *,AR1

23

Page 24: manual

LAR AR1,#0300HLACC 0AND #0FFFHSUB #800HSACL *LAR AR1,#333HMPY #0ZACRPT #33HMACD 0FF00H,*-APACLAR AR1,#0300HSACH * ;give as sach *,1 incase of overflowLACC *ADD #800HSFR ;remove if o/p is less amplitudeSACL *OUT *,4LACC #0FFFHSACL 0OUT 0,05NOPB ISR.end

RESULT:Thus the incoming sine wave with frequency 35 KHZ is decimated and interpolated

by the factor 4

3. QUADRATURE MIRROR FILTERS

24

Page 25: manual

AIM:

To simulate mirror filters by using MATLAB

EQUIPMENT REQUIRED:

• MATLAB • SIMULINK

THEORY:The basic building block in applications of quadrature mirror filters (QMF) is the two channel QMF bank. This is the multirate digital filter structure that employs two decimators in the signal analysis section and two interpolators in the signal synthesis section and the low pass and highpass filters in the analysis section have impulse response h0(0) and h1(n) respectively. Similarly lowpass and high pass filters contained in the synthesis section have impulse response g0(n) and g1(n) respectively. The scale factor 2 corresponse to the interpolation factor used to normalize the overall frequency response of the QMF. With this choice of the filter characteristics, the component due to aliasing vanishes. Thus the aliasing resulting from decimation in the analysis section of QMF bank is perfectly cancelled by the image signal spectrum that arises due to interpolation. As a result, two channels QMF behaves as a linear time invariant system.

PROGRAM

N = 32; h0 = QMFDesign(N, 0.3, 1); % H(z) h1 = (-1).^(0:N-1)' .* h0; % H(-z) h00 = conv (h0, 2*h0); h11 = conv (h1, -2*h1); [f, Hp] = PlotFilter (h00, 'linear-radian'); close; PlotFilter (h11, 'linear-radian'); hold on; plot(f, Hp); hold off; xlabel ('Frequency'); ylabel ('Amplitude') text (0.1, 1.84, '|{\itH}_0(\omega)|^2'); text (0.8, 1.84, '|{\itH}_1(\omega)|^2');

BLOCK DIAGRAM QMF:

25

Page 26: manual

CHARACTERSTICS OF QMF:

RESULT :Thus by using the above theory the QMF has been simulated using MATLAB filters

Packages

4. IMPLEMENTATION OF LINEAR AND CYCLIC CODES

26

Page 27: manual

AIM:To implement a cyclic code generator and syndrome calculator and to verify the same for the given polynomial

EQUIPMENT REQUIRED:• IC 7495• IC 7486• Trainer kit• Connectivity wires

THEORY:Cyclic code:

Cyclic code from a subclass of linear block codes an advantage of cyclic code over most other types of codes is that are easy to encode further more cyclic codes posses a well defined mathematical structure, which has led to the development of very efficient decoding schemes A binary code is said to be a cyclic code if it exhibits two fundamental properties

1.linear property:The sum of two code words is also a code word

2.cyclic property:Any cyclic shift of a code word is also a code word

The gate is switched on hence the M message bits are shifted into channel as soon as the K message bits have entered the shift register, the resulting (n-k) bits in the register from the parity bits The gate is switched OFF there by berating the feedback connection the contents of the shift register are shifted out into the channel the polynomial for the message (1001) is given by g(t).the contents of the shift register are modified by the incoming message bits as in tables, after A shifts the parity bits are (011), according appending these parity bits to the message bits (1001),we get the code word(0111001)

SYNDROME CALCULATOR BLOCK DIAGRAM:

27

Page 28: manual

SYNDROME CIRCUIT DIAGRAM:

SYNDROME CALCULATOR:

Suppose if the code word (X0,X1,X2,X3………Xn) is transmitted over the noisy channel and received word (Y0,Y1.Y2,Y3……..Yn) the syndrome is calculated for error, if syndrome contain zero there is an error and if non zero is present it contains error.

In case of cyclic code, the received word be represented by polynomial of degree (n-1) as Yn=a(n).g(n) + s(d)S.T. The remainder S(n) is syndrome polynomial of degree n-k-1 or less. Its co-efficients are making up the (n-k) by -1 syndrome S once we know S, we can determine the corresponding error pattern and there by mate the approximate correction.

The cyclic code generation includes the following steps:1. Multiplication of the message polynomial D(x) by X(n-k).2. Division of X(n-k) by D(x) by the generator polynomial G(x) to obtain the remainder.3. Addition of the remainder to X(n-k) D(x) to form the desired code polynomial.

The given polynomial is, G(x) = 1+X+X3

Connect the circuit as shown in the figure for(7,4 cyclic code) So the code word is 011101. The above steps are implemented by means of flip-flops, multipliers, adders, wholly as linear feedback shift register and an external clock control’s the operation of Flipflops.

Let the transmitted code word be (0111001) and the received word (0111001) and the received word (0110001) and the received word be (0110001) that is the middle bits is in error as the received bits are fed into ht shift register initially set to zero its content are modified as in table at the end of seventh shift register as 110. Since the syndrome is non zero the received word is in error pattern corresponding to this syndrome is in the middle bits of the received word.

28

Page 29: manual

PROCEDURE:CODE GENERATOR:

• Give the message bits and note down the outputs across flipflop P0,P1,P2• As the last message bits is given as the input the required code to be transmitted is get across the flipflop P0,P1,P2• The transmitted message = message + code

CODE GENERATOR BLOCK DIAGRAM:

PIN DIAGRAM OF IC 7495

29

Page 30: manual

SYNDROME CALCULATOR:• Connect the circuit as shown in the figure• Give the code word as the input to one of the X – OR gate as shown in the figure starting from LSB.note down the output across flipflop S0,S1,S2• At the MSb if the required bit is correct we get zeros across S0,S1,S2 we get error according to the bit corrupted which has to be checked in the table

CIRCUIT DAGRAM FOR CODE CONVERTER:

CODE GENERATOR

Messge I/O P0 P1 P20 0 0 01 0 1 00 1 1 10 0 1 11 1 1 1

SYNDROME CALCULATOR WITH NO ERROR

Error Code word I/P S0 S1 S2LSB 1 1 0 00 0 1 00 0 0 11 0 1 01 1 0 11 0 0 0MSB 0 0 0 0

30

Page 31: manual

SYNDROME CALCULATOR WITH BIT ERROR

Shift 1st bit0111000

2nd bit0111010

3rd bit0111101

4th bit0110001

5th bit1001001

6th bit0011001

7th bit1111001

1 000 100 100 100 100 100 1002 000 110 010 010 010 010 0103 000 011 101 001 001 001 0014 100 011 000 110 010 010 0105 110 011 100 111 001 101 1016 111 011 110 001 010 100 0007 101 011 100 110 001 010 100

ERROR PATTERN

MSB 0000001

0000010 0000100 0001000 0010000 0100000 1000000

RESULT AND INTERFERENCES:

The cyclic code was designed for generating word where message a = 1001 and parity bitgenerating was 011. The circuit was executed and output table was verified. The syndrome calculator circuit was designed first for the class where no error occurred and if one bit error was occurring both the output flipflop for these cases were verified and observation were written.

31

Page 32: manual

5. LEXICAL ANALYZER

AIM:To write a C Program to implement a Lexical analyzer.

ALGORITHM:1)Start the program.2)Declare all the variables and file pointers.3 )D i sp l ay t he i npu t p rog ram.4)Separate the keyword in the program and display it.5)Display the header files of the input program.6)Separate the operators of the input program and display it.7 )P r in t t he punc tua t i on marks .8)Print the constant that are present in input program.9)Print the identifiers of the input program.10)Stop the program

.

PROGRAM:#include<stdio.h>#include<conio.h>#include<ctype.h>#include<string.h>void main(){

FILE *fp;inti,j;chararr[100],k;char kw[10][10]={"int","float","double","end","main","void","include","printf","scanf"};charhf[2][10]={"stdio.h","conio.h"};char op[5]={'+','-','*','/','%'};charpunc[6]={'(',')','{','}',','};clrscr();fp=fopen("input.c","r");printf("InputProgram\n");while(!feof(fp))

{arr[0]=fgetc(fp); printf("%c",arr[0]);}

fclose(fp); printf("\nSymboltable\n");fp=fopen("input.c","r");

32

Page 33: manual

 printf("\nKeywords");while(!feof(fp)){arr[0]=fgetc(fp);fscanf(fp,"%s",arr);for(i=0;i<10;i++)

{if(strcmp(arr,kw[i])==0){ 

printf("\t%s",arr);}}}fclose(fp);fp=fopen("input.c","r"); printf("\nHeaderfiles");while(!feof(fp))

{arr[0]=fgetc(fp);fscanf(fp,"%s",arr);for(i=0;i<2;i++)

{if(strcmp(arr,hf[i])==0){ printf("\t%s",arr);}}}

fclose(fp);fp=fopen("input.c","r");printf("\nOperators");while(!feof(fp))

{arr[0]=fgetc(fp);for(i=0;i<5;i++){if(arr[0]==op[i]){ printf("\t%c",arr[0]);}}}

fclose(fp);fp=fopen("input.c","r"); printf("\npunctuation");while(!feof(fp)){arr[0]=fgetc(fp);for(i=0;i<6;i++){

33

Page 34: manual

if(arr[0]==punc[i]){ printf("\t%c",arr[0]);}}}

fclose(fp);fp=fopen("input.c","r"); printf("\nConstants");while(!feof(fp)){arr[0]=fgetc(fp);if(isdigit(arr[0])){ printf(" %c ",arr[0]);}}fclose(fp);fp=fopen("input.c","r");printf("\nidentifier ");while(!feof(fp)){fscanf(fp,"%s",arr);for(i=0;i<2;i++){if(strcmp(arr,kw[i])==0){fscanf(fp,"%s",arr); j=0;while(j<strlen(arr) &&arr[j]!=';'){ printf("%c",arr[j]); j++;}}}}fclose(fp);getch();}

INPUT:

#include<stdio.h>#include<conio.h>void main(){inta,b,c;a=10;b=5;

34

Page 35: manual

c=a+b;printf(“The sum is %d”, c);getch();}

OUTPUT:

RESULT:Thus the above the program is executed and the required output is obtained.

35

Page 36: manual

6. IMPLEMENTATION OF SEMAPHORES AND MONITORS INCLASSICAL PROBLEMS OF SYNCHRONIZATION

ALGORITHM1) Start2) Define the maximum buffer size.3) Enter the number of producers and consumers.4) The producer produces the job and put it in the buffer.5) The consumer takes the job from the buffer. 6) If the buffer is full the producer goes to sleep.7) If the buffer is empty then consumer goes to sleep.8) Stop

 PROGRAM #include<stdio.h>#include<unistd.h>#include<pthread.h>#define buffSize 1000struct{pthread_mutex_tmutex;int buff[buffSize];intproducedCount;intconsumedCount;}shared={PTHREAD_MUTEX_INITIALIZER};void *produce(void *arg);void *consume(void *arg);void main(){intprodThreads,consThreads,i;printf(“\nEnter the no of Producers: “);scanf(“%d”,&prodThreads);printf(“\nEnter the no of Consumers: “);scanf(“%d”,&consThreads);intproducerArr[prodThreads],consumerArr[consThreads];pthread_t producer[prodThreads],consumer[consThreads];pthread_setconcurrency(prodThreads+consThreads);for(i=0;i<prodThreads;i++){producerArr[i]=0;pthread_create(&producer[i],NULL,produce,&producerArr[i]);}for(i=0;i<consThreads;i++){

36

Page 37: manual

consumerArr[i]=0;pthread_create(&consumer[i],NULL,consume,&consumerArr[i]);}for(i=0;i<prodThreads;i++){pthread_join(producer[i],NULL);printf(“\nThe Producer (%d) produced: [%d] Items”,i,producerArr[i]);sleep(1);}printf(“\n”);for(i=0;i<consThreads;i++){pthread_join(consumer[i],NULL);printf(“\nThe Consumer (%d) Consumed: [%d] Items”,i,consumerArr[i]);sleep(1);}}void *produce(void *arg){while(1){pthread_mutex_lock(&shared.mutex);if(shared.producedCount<buffSize){shared.producedCount++;*((int *)arg) += 1;pthread_mutex_unlock(&shared.mutex);}else{pthread_mutex_unlock(&shared.mutex);return NULL;}}}void *consume(void *arg){while(1){pthread_mutex_lock(&shared.mutex);if(shared.consumedCount<shared.producedCount){shared.consumedCount++;*((int *)arg) += 1;pthread_mutex_unlock(&shared.mutex);}

37

Page 38: manual

else{pthread_mutex_unlock(&shared.mutex);if (shared.consumedCount>=buffSize)return NULL;}}}

OUTPUTEnter the no of Producers: 4Enter the no of Consumers: 3ResultThe Producer (0) produced: [252] ItemsThe Producer (1) produced: [415] ItemsThe Producer (2) produced: [136] ItemsThe Producer (3) produced: [197] Items The Consumer (0) Consumed: [703] ItemsThe Consumer (1) Consumed: [260] ItemsThe Consumer (2) Consumed: [37] Items RESULT

Thus the semaphore is implemented and the output is verified for the classical problem ofsynchronization successfully.

38

Page 39: manual

7. USAGE OF SYSTEM CALLS

ALGORITHM

1) Start2) Define the flags.3) Define the system calls open(), Close(), write(), lseek()&perror()4) Open and close a file using open() and close() function.5) Write the data in to the opened file using write(). 6) Move the cursor by using lseek()..7) Show the error message using perror().8) Stop

 PROGRAM

GENERAL CLASS SPECIFIC CLASS SYSTEM CALL --------------------------------------------------------------------- File Structure Creating a Channel creat() Related Calls open()close()Input/Outputread()write() Random Access lseek() Channel Duplication dup() Aliasing and Removing link() Files unlink() File Status stat()fstat() Access Control access()chmod()chown()umask() Device Control ioctl() --------------------------------------------------------------------- Process Related Process Creation and exec() Calls Termination fork()wait()exit() Process Owner and Group getuid()geteuid()

39

Page 40: manual

getgid()getegid() Process Identity getpid()getppid() Process Control signal()kill()alarm() Change Working Directory chdir() ----------------------------------------------------------------------Interprocess Pipelines pipe() Communication Messages msgget()msgsnd()msgrcv()msgctl() Semaphores semget()semop() Shared Memory shmget()shmat()shmdt() ----------------------------------------------------------------------

open(), Close(), & write():

#include <fcntl.h> /* defines options flags */ #include <sys/types.h> /* defines types used by sys/stat.h */ #include <sys/stat.h> /* defines S_IREAD & S_IWRITE */

static char message[] = "Hello, world";

int main() {intfd;char buffer[80];

fd = open("file.dat",O_RDWR | O_CREAT | O_EXCL, S_IREAD | S_IWRITE);

if (fd != -1) {printf("file.dat opened for read/write access\n");write(fd, message, sizeof(message));lseek(fd, 0L, 0); /* go back to the beginning of the file */if (read(fd, buffer, sizeof(message)) == sizeof(message))printf("\"%s\" was written to file.dat\n", buffer);elseprintf("*** error reading file.dat ***\n");

40

Page 41: manual

close (fd); }elseprintf("*** file.dat already exists ***\n");exit (0); }

Lseek()&perror():

#include <stdio.h> #include <fcntl.h>

int main() {intfd;long position;

fd = open("file.dat", O_RDONLY);if ( fd != -1) {position = lseek(fd, 0L, 2); /* seek 0 bytes from end-of-file */if (position != -1)printf("The length of file.dat is %ld bytes.\n", position);elseperror("lseek error"); }elseprintf("can't open file.dat\n");close(fd); }

RESULT

Thus the system calls are implemented and the outputs are verified.

41