Skip to main content

Posts

Showing posts from April 15, 2012
Mat lab program to plot the ask modulated wave for a given binary sequence  %program to plot ask modulated wave clc; clear all; close all; f=2; t=0:(2*pi)/99:2*pi; g=input('Enter the binary sequence to be modulated '); bit=[];mod=[];c=[];cp=[]; for i=1:length(g)     if g(i)==0         die=zeros(1,100);         sp=zeros(1,100);     else g(i)==1         die=ones(1,100);         sp=ones(1,100);     end     c=sin(f*t);     bit=[bit die];     mod=[mod c];     cp=[cp sp]; end ask=cp.*mod; subplot(2,1,1) plot(bit); title('Binary bit pattern'); axis([0 100*length(g) -2.5 2.5]) grid on; subplot(2,1,2) plot(ask); axis([0 100*length(g) -2.5 2.5]) title('ASK modulated signal'); grid on;
Mat lab program to plot the frequency response of high pass filter  clc; clear all; close all; rp=1; rs=40; w1=800; w2=1200; ws=3600; aw1=2*pi*w1/ws; aw2=2*pi*w2/ws; pw1=2*tan(aw1/2); pw2=2*tan(aw2/2); [n,wc]=buttord(pw1,pw2,rp,rs,'s'); [b,a]=butter(n,wc,'high','s'); [num,den]=bilinear(b,a,1); [mag,freq]=freqz(num,den,128); freq1=freq*ws/(2*pi); m=20*log10(abs(mag)); plot(freq1,m); title('Respose of high pass filter'); grid on;
Mat lab program to plot the frequency response of low pass filter  clc; clear all; close all; rp=1; rs=40; w1=800; w2=1200; ws=3600; aw1=2*pi*w1/ws; aw2=2*pi*w2/ws; pw1=2*tan(aw1/2); pw2=2*tan(aw2/2); [n,wc]=buttord(pw1,pw2,rp,rs,'s'); [b,a]=butter(n,wc,'s'); [num,den]=bilinear(b,a,1); [mag,freq]=freqz(num,den,128); freq1=freq*ws/(2*pi); m=20*log10(abs(mag)); plot(freq1,m); title('Respose of low pass filter'); grid on;
Mat lab program to illustrate the impulse response of a LTI(linear time in-variant) system %program illustriating sampling theorem clc; clear all; close all; t=0:0.000005:0.5; f=16; t2=0:1/(1.3*f):0.5; s=cos(2*pi*f*t); sp=cos(2*pi*f*t2); subplot(3,1,1) plot(t,s,'b',t2,sp,'r*-'); hold on; stem(t2,sp,'g'); title('under sampling plot') ns=0:1/(2*f):0.5; ni=cos(2*pi*f*ns); subplot(3,1,2) plot(t,s,'b',ns,ni,'r*-') hold on; stem(ns,ni,'g'); title('nyquist sampling plot') os=0:1/(6*f):0.5;; ow=cos(2*pi*f*os); subplot(3,1,3) plot(t,s,'b',os,ow,'r*-') hold on; stem(os,ow,'g'); title('Over sampled plot') legend('analog signal','reconstructed signal','sampled signal'); 
Mat lab program to illustrate sampling theorem %program illustriating sampling theorem clc; clear all; close all; t=0:0.000005:0.5; f=16; t2=0:1/(1.3*f):0.5; s=cos(2*pi*f*t); sp=cos(2*pi*f*t2); subplot(3,1,1) plot(t,s,'b',t2,sp,'r*-'); hold on; stem(t2,sp,'g'); title('under sampling plot') ns=0:1/(2*f):0.5; ni=cos(2*pi*f*ns); subplot(3,1,2) plot(t,s,'b',ns,ni,'r*-') hold on; stem(ns,ni,'g'); title('nyquist sampling plot') os=0:1/(6*f):0.5;; ow=cos(2*pi*f*os); subplot(3,1,3) plot(t,s,'b',os,ow,'r*-') hold on; stem(os,ow,'g'); title('Over sampled plot') legend('analog signal','reconstructed signal','sampled signal'); 
Matlab program to generate sine ramp and square and their spectrum  %program to generate sine square ramp and their spectra clc; close all; clear all; f=10; t=0:0.001:0.5; s=sin(2*pi*f*t); subplot(3,1,1) plot(t,s) title('sine wave'); q=square(2*pi*50*t); subplot(3,1,2) plot(t,q) axis([0 0.2 -1.2 1.2]) title('square wave') subplot(3,1,3) plot(t,t); title('ramp wave'); figure(2) subplot(3,1,1) plot(abs(fft(s))); title('sine wave spectrum') subplot(3,1,2) plot(abs(fft(q))); title('square wave spectrum') subplot(3,1,3) plot(abs(fft(t))); title('ramp wave spectrum')
Matlab program for generating a truth table for logic equation and verify it %program to verify the logic equation clc; clear all; close all; a=[0 0 0 0 1 1 1 1]; b=[0 0 1 1 0 0 1 1]; c=[0 1 0 1 0 1 0 1]; f=(~a&~b&~c)|(~a&b&c)|(~a&~b&c)|(~a&b&c) 
Matlab program to plot VI characteristics of a diode  clc; close all; clear all; a=input('Enter the temperatre in degree centigrade '); b=input('Enter the reverse saturation current at room temperature '); q=1.6e-19; k=1.38e-23; t=a+273; v=-0.2:0.01:0.25; i=b*(exp(q*v/(k*t))-1); plot(v,i) xlabel('Voltage -->') ylabel('Current -->') grid on;
Matlab program to plot a parabola  clc; clear all; close all; t=-100:1:100; y=(t.^2)/16; plot(t,y); axis('equal');
COUNTING NEGATIVE NUMBERS  AREA data1,data,readonly  DCD 2,3,-4,-5 num equ 0x80000000  AREA data2,data  SPACE 1  AREA prog,code,readonly  ENTRY  ldr r4,=num  mov r3,#4  ldr r0,=data1 up ldr r1,[r0],#4  tst r1,r4  beq skp  add r5,#1 skp subs r3,#1  bne up  ldr r0,=data2  str r5,[r0] s b s  END 
SEARCHING A NUMBER IN AN ARRAY  ;Program to search for a given 32 bit number in an array of 32 bit numbers  AREA data1,data,readonly  DCD 0x11322,0x1132101,0x32110,0x11111 strm DCD 0x11111  AREA prog,code,readonly  ENTRY  ldr r3,strm  mov r2,#1  ldr r0,=data1 up ldr r1,[r0],#4  cmp r1,r3  beq done  add r2,#1  b up done ldr r0,=pos  str r2,[r0]  ;position of the found bit is stored in SRAM s b s  AREA data2,data pos SPACE 1  END 
ONES AND ZEROS COUNT  ;Program to count the number of ones and zeros in two consecutive memory locations  AREA dot,data,readonly  DCB 0x01,0x21  AREA data1,data  SPACE 4  AREA prog,code,readonly  ENTRY  mov r2,#2  ldr r0,=dot up ldrb r1,[r0],#1  mov r3,#8 top tst r1,#0x01  bne addone  add r7,r7,#1 ;r7 contains the count of number of zeros  beq skp addone add r6,r6,#1 ; r6 contains the count of number of ones skp subs r3,r3,#1  lsr r1,#1  bne top  subs r2,#1  bne up  ldr r0,=data1  str r7,[r0],#4  str r6,[r0] s b s  END 
ASCENDING AND DESCENDING SORT  ;Program to arrange series of 32bit numbers in ascending or descending order  AREA data1,data,readonly  DCD 0x12,0x13,0x18,0x674  AREA data2,data  SPACE 4  AREA prog,code,readonly  ENTRY  mov r3,#4  ldr r0,=data1  ldr r1,=data2 top ldr r2,[r0],#4  str r2,[r1],#4  subs r3,#1  bne top  mov r5,#3 olop ldr r0,=data2  mov r6,r5 up ldr r1,[r0],#4  ldr r2,[r0]  cmp r1,r2  bcc skp ;replace bcc with bhi for descending sorting  str r1,[r0],#-4  str r2,[r0],#4 skp subs r6,#1  bne up  subs r5,#1  bne olop s b s  END
LENGTH OF NULL TERMINATED STRING  ;Program to find the length of a null terminated string  AREA data1,data,readonly strr DCB "Advanced",'0'  AREA data2,data  SPACE 1  AREA progq,code,readonly  ENTRY  ldr r0,=strr up ldrb r2,[r0],#1  cmp r2,#'0'  beq done  add r1,r1,#1  b up done ldr r0,=data2  str r1,[r0] s b s  END 
LARGER OR SMALLER IN ARRAY  ;Program to find the largest or smallest number in an array of 32 numbers  AREA data1,data,readonly array DCD 0x12,0x11,0x22,0x12,0x33,0x12,0x32,0x33,0x12,0x67,0x42,0x56,0x55,0x45,0x33,0x78       DCD 0x45,0x77,0x52,0x71,0x16,0x07,0x08,0x88,0x21,0x45,0x13,0x55,0x7A,0x64,0x11,0xff  AREA data2,data num SPACE 4  AREA reset,code,readonly  ENTRY  ldr r0,=array  mov r3,#31  ldr r1,[r0],#4 lop ldr r2,[r0],#4  cmp r1,r2  bhi skp ;replace with bcc for smallest number  mov r1,r2 skp subs r3,r3,#1  bne lop  ldr r0,=data2  str r1,[r0] s b s  END 
SQUARE OF A NUMBER USING LOOKUP TABLE   ;Program to find the square of a number (1 to 10) using lookup table   AREA data2,data res space 2  AREA prog,code,readonly  ENTRY  ldr r0,=num  ldr r1,=sqr  add r1,r1,r0  ldrb r3,[r1]  ldr r4,=res  strb r3,[r4] s b s  AREA data1,data,readonly num equ 5 sqr DCB 0x0,0x1,0x4,0x9,0x16,0x25,0x36,0x49,0x64,0x81  END
ADDIGNG 64 BIT NUMBERS  ;Program to add two 64 bit numbers   AREA prog,code,readonly   ENTRY   ldr r0,=lbl   ldmia r0,{r1-r4}   adds r5,r2,r4   adcs r6,r1,r3   eor r8,r8   adc r8,#0 ;r8 contains the carry generated if any   ldr r7,=res   stmia r7,{r5,r6,r8}   s b s    AREA dta,data,readonly lbl DCQ 0x1234567891191812     DCQ 0x1234567989999987   AREA data2,data res SPACE 8  END
DISASSEMBLING OF A BYTE  AREA data1,data,readoly  DCB 0x32  AREA data2,data  SPACE 2  AREA prog,code,readonly  ENTRY  ldrb r0,data1  and r1,r0,#0x0f  mov r2,r0,lsr #4  ldr r3,=data2  str r1,[r3],#1  str r2,[r3] s b s  END 
ADDING OF 16 BIT ARRAY     AREA data2,data sum space 1  AREA prog,code,readonly  ENTRY   LDR r0,=lbl  MOV r1,#4  LDR R2,[r0],#4  ;ADD r4,r0,#4 up LDR r3,[R0],#4  add r7,r2,r3  subs r1,#1  mov r2,r7  ;mov r0,r4  bne up  ldr r5,=sum  str r7,[r5] s b s  AREA data1,data,readonly lbl DCD   0x1201     DCD   0x0121     DCD   0x3210     DCD   0x1111  END
PROGRAM FOR ARRAY MULTIPLICATION    AREA prog,code   ENTRY   LDR R0,=DATAE   LDR R4,[R0],#4   LDR R5,[R0]   mul r2,r4,r5   ldr r3,=reslt    str r2,[r3] s b s    AREA DATAE,DATA,READONLY    DCD 0X0004,0X0002      AREA data1,data reslt DCD 0  END
ARM ASM PROGRAM FOR FINDING FACTORIAL OF A NUMBER-1     AREA prog,code,readonly EntRY     ldrb r0,num     mov r3,r0 up  sub r1,r3,#1     mul r2,r0,r1 mov r0,r2 mov r3,r1 cmp r3,#1 bhi up ldr r0,=fact str r2,[r0] s b s  AREA data2,data,readonly num DCB 0x3  AREA data1,data fact SPACE 5  END