dsp lab manual.pdf
Post on 21-Jan-2016
126 Views
Preview:
DESCRIPTION
TRANSCRIPT
Continuous signal generation
Output:
Enter the value of frequency3
Enter the value of amplitude2.5
>>
Program:
clc;
clear all;
close all;
t=0:.001:1;
f=input('Enter the value of frequency');
a=input('Enter the value of amplitude');
subplot(3,2,1);
y=a*sin(2*pi*f*t);
plot(t,y,'r');
xlabel('time --->');
ylabel('amplitude --->');
title('sine wave')
grid on;
subplot(3,2,2);
z=a*cos(2*pi*f*t);
plot(t,z);
xlabel('time --->');
ylabel('amplitude --->');
title('cosine wave')
grid on;
subplot(3,2,3);
s=a*square(2*pi*f*t);
plot(t,s);
xlabel('time --->');
ylabel('amplitude --->');
title('square wave')
grid on;
subplot(3,2,4);
plot(t,t);
xlabel('time --->');
ylabel('amplitude --->');
title('ramp wave')
grid on;
subplot(3,2,5);
plot(t,a,'r');
xlabel('time --->');
ylabel('amplitude --->');
title('unit step wave')
grid on;
Discrete signal generation
Output:
Enter the value of frequency.04
Enter the value of amplitude2.5
Enter the length of unit step9
>>
Program:
clc;
clear all;
close all;
n=0:1:50;
f=input('Enter the value of frequency');
a=input('Enter the value of amplitude');
N=input('Enter the length of unit step');
subplot(3,2,1);
y=a*sin(2*pi*f*n);
stem(n,y,'r');
xlabel('time --->');
ylabel('amplitude --->');
title('sine wave')
grid on;
subplot(3,2,2);
z=a*cos(2*pi*f*n);
stem(n,z);
xlabel('time --->');
ylabel('amplitude --->');
title('cosine wave')
grid on;
subplot(3,2,3);
s=a*square(2*pi*f*n);
stem(n,s);
xlabel('time --->');
ylabel('amplitude --->');
title('square wave')
grid on;
subplot(3,2,4);
stem(n,n);
xlabel('time --->');
ylabel('amplitude --->');
title('ramp wave')
grid on;
x=0:N-1;
d=ones(1,N);
subplot(3,2,5);
stem(x,d,'r');
xlabel('time --->');
ylabel('amplitude --->');
title('unit step wave')
grid on;
Linear Convolution
Output:
ENTER THE FIRST SEQUENCE [1 4 1 3]
ENTER THE SECOND SEQUENCE [4 5 2 6]
>>
Program: clc;
clear all;
close all;
x=input('ENTER THE FIRST SEQUENCE ');
h=input('ENTER THE SECOND SEQUENCE ');
y=conv(x,h);
figure(1);
subplot(3,1,1);
stem(x);
grid on;
xlabel('Amplitude---->');
ylabel('time----->');
title('FIRST SEQUENCE');
subplot(3,1,2);
stem(h);
grid on;
xlabel('Amplitude---->');
ylabel('time----->');
title('SECOND SEQUENCE');
subplot(3,1,3);
stem(y);
grid on;
xlabel('Amplitude---->');
ylabel('time----->');
title('LINEAR CONVOLUTION');
Circular Convolution
Output:
Enter the co-efficients of x1[n]=[1 2 3 2 5]
Enter the co-efficients of x2[n]=[5 2 3 1 3]
30 38 33 38 43
>>
Program:
clc;
clear all;
close all;
x=input('Enter the co-efficients of x1[n]=');
h=input('Enter the co-efficients of x2[n]=');
n1=length(x);
n2=length(h);
N=max(n1,n2);
x=[x,zeros(1,N-n1)];
h=[h,zeros(1,N-n2)];
for n=0:N-1;
y(n+1)=0;
for k=0:N-1;
j= mod(n-k,N);
y(n+1)=y(n+1)+x(k+1)*h(j+1);
end
end
subplot(3,1,1);
n=0:(length(x)-1);
stem(n,x);
grid on;
xlabel('TIME');
ylabel('AMPLITUDE');
title('x1[n]');
subplot(3,1,2);
n=0:(length(h)-1);
stem(n,h);
grid on;
xlabel('TIME');
ylabel('AMPLITUDE');
title('x2[n]');
subplot(3,1,3);
n=0:(length(y)-1);
stem(n,y);
grid on;
disp(y)
xlabel('TIME');
ylabel('AMPLITUDE');
title('OUTPUTx3[n]');
DIGITAL BUTTERWORTH FILTER
Output:
Enter the passband attenuation:.4
Enter the stop band attenuation:30
Enter the pass band frequency:.2*pi
Enter the stop band frequency:.4*pi
>>
Program :
clc;
clear all;
close all;
rp=input('Enter the passband attenuation:');
rs=input('Enter the stop band attenuation:');
wp=input('Enter the pass band frequency:');
ws=input('Enter the stop band frequency:');
[N,wn]=buttord(wp/pi,ws/pi,rp,rs);
%DIGITAL BUTTERWORTH LOW PASS FILTER
[b,a]=butter(N,wn,'low');
figure(1);
freqz(b,a);
title('DIGITAL BUTTERWORTH LOW PASS FILTER');
%DIGITAL BUTTERWORTH HIGH PASS FILTER
[N,wn]=buttord(wp/pi,ws/pi,rp,rs);
[b,a]=butter(N,wn,'high');
figure(2);
freqz(b,a);
title('DIGITAL BUTTERWORTH HIGH PASS FILTER');
%DIGITAL BUTTERWORTH BAND PASS FILTER
wpb=[wp,ws];
wsb=[wp-.1*pi,ws+.1*pi];
[N,wn]=buttord(wpb/pi,wsb/pi,rp,rs);
[b,a]=butter(N,wn,'bandpass');
figure(3);
freqz(b,a);
title('DIGITAL BUTTERWORTH BAND PASS FILTER');
%DIGITAL BUTTERWORTH BAND STOP FILTER
wps=wsb;
wss=wpb;
[N,wn]=buttord(wps/pi,wss/pi,rp,rs);
[b,a]=butter(N,wn,'stop');
figure(4);
freqz(b,a);
title('DIGITAL BUTTERWORTH BAND STOP FILTER');
DIGITAL CHEBYSHEV(TYPE-1) FILTER
Output:
Enter the passband attenuation:20
Enter the stop band attenuation:50
Enter the pass band frequency:0.3*pi
Enter the stop band frequency:0.4*pi
>>
Program:
clc;
clear all;
close all;
rp=input('Enter the passband attenuation:');
rs=input('Enter the stop band attenuation:');
wp=input('Enter the pass band frequency:');
ws=input('Enter the stop band frequency:');
%DIGITAL CHEBYSHEV LOW PASS FILTER
[N,wn]=cheb1ord(wp/pi,ws/pi,rp,rs);
[b,a]=cheby1(N,rp,wn,'low');
figure(1);
freqz(b,a);
title('DIGITAL CHEBYSHEV LOW PASS FILTER');
%DIGITAL CHEBYSHEV HIGH PASS FILTER
[N,wn]=cheb1ord(wp/pi,ws/pi,rp,rs);
[b,a]=cheby1(N,rp,wn,'high');
figure(2);
freqz(b,a);
title('DIGITAL CHEBYSHEV HIGH PASS FILTER');
%DIGITAL CHEBYSHEV BAND PASS FILTER
wpb=[wp,ws];
wsb=[wp-.1*pi,ws+.1*pi];
[N,wn]=cheb1ord(wpb/pi,wsb/pi,rp,rs);
[b,a]=cheby1(N,rp,wn,'bandpass');
figure(3);
freqz(b,a);
title('DIGITAL CHEBYSHEV BAND PASS FILTER');
%DIGITAL CHEBYSHEV BAND STOP FILTER
wps=wsb;
wss=wpb;
[N,wn]=cheb1ord(wps/pi,wss/pi,rp,rs);
[b,a]=cheby1(N,rp,wn,'stop');
figure(4);
freqz(b,a);
title('DIGITAL CHEBYSHEV BAND STOP FILTER');
Program:
clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
%FIR LOW PASS FILTER USING HANNING WINDOW
h=fir1(N,wc/pi,hanning(N+1));
figure(1);
freqz(h);
title('DIGITAL HANNING LOW PASS FILTER');
%FIR HIGHPASS FILTER USING HANNING WINDOW
h=fir1(N,wc/pi,'high',hanning(N+1));
figure(2);
freqz(h);
title('DIGITAL HANNING HIGH PASS FILTER');
%FIR BAND PASS FILTER USING HANNING WINDOW
wcc=[wc-.2*pi,wc+.2*pi];
h=fir1(N,wcc/pi,hanning(N+1));
figure(3);
freqz(h);
title('DIGITAL HANNING BAND PASS FILTER');
%FIR STOP PASS FILTER USING HANNING WINDOW
h=fir1(N,wcc/pi,'stop',hanning(N+1));
figure(4);
freqz(h);
title('DIGITAL HANNING BAND STOP FILTER');
Program:
clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
%FIR LOW PASS FILTER USING HAMMING WINDOW
h=fir1(N,wc/pi,hamming(N+1));
figure(1);
freqz(h);
title('DIGITAL HAMMING LOW PASS FILTER');
%FIR HIGHPASS FILTER USING HAMMING WINDOW
h=fir1(N,wc/pi,'high',hamming(N+1));
figure(2);
freqz(h);
title('DIGITAL HAMMING HIGH PASS FILTER');
%FIR BAND PASS FILTER USING HAMMING WINDOW
wcc=[wc-.2*pi,wc+.2*pi];
h=fir1(N,wcc/pi,hamming(N+1));
figure(3);
freqz(h);
title('DIGITAL HAMMING BAND PASS FILTER');
%FIR STOP PASS FILTER USING HAMMING WINDOW
wcs=[wc-.3*pi,wc+.3*pi];
h=fir1(N,wcs/pi,'stop',hamming(N+1));
figure(4);
freqz(h);
title('DIGITAL HAMMING BAND STOP FILTER');
Program:
clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
%FIR LOW PASS FILTER USING BLACKMAN WINDOW
h=fir1(N,wc/pi,blackman(N+1));
figure(1);
freqz(h);
title('DIGITAL BLACKMAN LOW PASS FILTER');
%FIR HIGHPASS FILTER USING BLACKMAN WINDOW
h=fir1(N,wc/pi,'high',blackman(N+1));
figure(2);
freqz(h);
title('DIGITAL BLACKMAN HIGH PASS FILTER');
%FIR BAND PASS FILTER USING BLACKMAN WINDOW
wcc=[wc-.2*pi,wc+.2*pi];
h=fir1(N,wcc/pi,blackman(N+1));
figure(3);
freqz(h);
title('DIGITAL BLACKMAN BAND PASS FILTER');
%FIR STOP PASS FILTER USING BLACKMAN WINDOW
wcs=[wc-.3*pi,wc+.3*pi];
h=fir1(N,wcs/pi,'stop',blackman(N+1));
figure(4);
freqz(h);
title('DIGITAL BLACKMAN BAND STOP FILTER');
FIR FILTER USING RECTANGULAR WINDOW
Output:
Enter the value of N:28
Enter cutoff frequency:0.5*pi
>>
Program:
clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
%FIR LOW PASS FILTER USING RECTANGULAR WINDOW
h=fir1(N,wc/pi,rectwin(N+1));
figure(1);
freqz(h);
title('DIGITAL RECTANGULAR LOW PASS FILTER');
%FIR HIGHPASS FILTER USING RECTANGULAR WINDOW
h=fir1(N,wc/pi,'high',rectwin(N+1));
figure(2);
freqz(h);
title('DIGITAL RECTANGULAR HIGH PASS FILTER');
%FIR BAND PASS FILTER USING RECTANGULAR WINDOW
wcc=[wc-.2*pi,wc+.2*pi];
h=fir1(N,wcc/pi,rectwin(N+1));
figure(3);
freqz(h);
title('DIGITAL RECTANGULAR BAND PASS FILTER');
%FIR STOP PASS FILTER USING RECTANGULAR WINDOW
wcs=[wc-.3*pi,wc+.3*pi];
h=fir1(N,wcs/pi,'stop',rectwin(N+1));
figure(4);
freqz(h);
title('DIGITAL RECTANGULAR BAND STOP FILTER');
DISCRETE FOURIER TRANSFORM
Output:
Enter your Choice: 1.DFT 2.IDFT1
Enter the value of N4
Enter the input sequence X(n):[1 2 3 4]
in =
1 2 3 4
out =
10.0000 -2.0000 + 2.0000i -2.0000 -2.0000 - 2.0000i
>>
Program:
clc;
clear all;
close all;
ch=input('Enter your Choice: 1.DFT 2.IDFT');
ifch==1
N=input('Enter the value of N');
x=input('Enter the input sequence X(n):');
t=0:N-1;
y=fft(x,N);
in=x
out=y
elseifch==2
N=input('Enter the value of N=');
y=input('Enter the sequence y[n]=');
t=0:N-1;
x=ifft(y,N);
in=y
out=x
end
subplot(2,1,1);
stem(t,in);
xlabel('TIME --->');
ylabel('AMPLITUDE --->');
title('INPUT SIGNAL');
grid on;
subplot(2,1,2);
stem(t,out);
xlabel('TIME --->');
ylabel('AMPLITUDE --->');
title('OUTPUT SIGNAL');
grid on;
INVERSE DISCRETE FOURIER TRANSFORM
Output:
Enter your Choice: 1.DFT 2.IDFT2
Enter the value of N=4
Enter the sequence y[n]=[10 -2+2i -2 -2-2i]
in =
10.0000 -2.0000 + 2.0000i -2.0000 -2.0000 - 2.0000i
out =
1 2 3 4
>>
Program:
Adder
;-------------------------------------------------
;Frontline Electronics Pvt Ltd, Salem, INDIA. 23-10-2001
;
;fix32add.asm - Fixed point 32bit addition.
;-------------------------------------------------
.mmregs;initialise all registers.
.ds 1000h
X1 .word 55h ;X input -> X1 X0 (32 bits)
X0 .word 66h
Y1 .word 77h ;Y input -> Y1 Y0 (32 bits)
Y0 .word 88h
Z1 .word 0 ;Z output -> Z1 Z0 (32 bits)
Z0 .word 0
.listoff
;-------------------------------------------------
;Frontline Electronics Pvt Ltd, Salem, INDIA.
;
;Begin1.asm - Example programs beginning code.
; (without AIC initialization).
;-------------------------------------------------
.mmregs;initialise all registers.
;-------------------------
;Main Program starts here.
;-------------------------
.ps 0a00h ;set program segment starting address.
.entry ;set entry point,used in down loading program.
START: SETC INTM ;disable all Interrupts.
LDP #00 ;data page pointer = 0.
OPL #0834h,PMST;set processor mode status reg.
LACC #00 ;accumulator = 00.
SAMM CWSR ;storeaccu. in CWSR & PDWSR.
SAMM PDWSR ;clear wait state registers.
SPLK #02h,IMR ;enable INT2.
;you must enable INT2 always,because
;it is used for serial communication
;between starter kit & host computer.
CLRC INTM ;clear interrupt mask bit.
.liston
ADD32:
ldp #X0 ;set data page pointer.
lacc X1,16 ;Acc = X1 00
adds X0 ;Acc = X1 X0
adds Y0 ;Acc = X1 X0 + 00 Y0
add Y1,16 ;Acc = X1 X0 + Y1 Y0
sacl Z0 ;store Z0 result.
sach Z1 ;store Z1 result.
hlt: b hlt ;halt program.
.END ;end of program.
Program:
Multiplier
;-------------------------------------------------
;Frontline Electronics Pvt Ltd, Salem, INDIA. 23-10-2001
;
;fx16m_s.asm - Fixed point signed 16bit multiplication.
;-------------------------------------------------
.mmregs;initialise all registers.
.ds 1000h
X0 .word 55h ;X input -> X0 (16 bits)
Y0 .word 77h ;Y input -> Y0 (16 bits)
Z1 .word 0 ;Z output -> Z1 Z0 (32 bits)
Z0 .word 0
.listoff
;-------------------------------------------------
;Frontline Electronics Pvt Ltd, Salem, INDIA.
;
;Begin1.asm - Example programs beginning code.
; (without AIC initialization).
;-------------------------------------------------
.mmregs;initialise all registers.
;-------------------------
;Main Program starts here.
;-------------------------
.ps 0a00h ;set program segment starting address.
.entry ;set entry point,used in down loading program.
START: SETC INTM ;disable all Interrupts.
LDP #00 ;data page pointer = 0.
OPL #0834h,PMST;set processor mode status reg.
LACC #00 ;accumulator = 00.
SAMM CWSR ;storeaccu. in CWSR & PDWSR.
SAMM PDWSR ;clear wait state registers.
SPLK #02h,IMR ;enable INT2.
;you must enable INT2 always,because
;it is used for serial communication
;between starter kit & host computer.
CLRC INTM ;clear interrupt mask bit.
.liston
MUL16:
ldp #X0 ;set data page pointer.
lt X0 ;load X0 in T register.
mpy Y0 ;multiply T * Y0 (signed).
spl Z0 ;store Product reg. low in Z0.
sph Z1 ;store Product reg. high in Z1.
hlt: b hlt ;halt program.
.END ;end of program.
Program:
Sine Wave Generator
;---------------------------------------------------------
;Frontline Electronics Pvt Ltd, Salem, INDIA. 02-03-2002
;
;sine.asm - Example program to generate sinewave.
; (FEPL 5X DSK target board).
;---------------------------------------------------------
.mmregs;initialise all registers.
.ds 1000h
.include "sinetbl.dat" ;load 800 point wavetable
;f1= fs/D = 8000/800 = 10hz.
.ds 0f00h
temp .word 0
mod .word 100 ;Required freq. = mod * f1 = 100*10 = 1000hz.
scale .q15 0.5
;---------------------------------
;Interrupt vectors
;---------------------------------
.ps 080ah
rint b getdata ;receive interrupt
xint b xint ;transmit interrupt
.ps 0a00h ;program entry point
.entry
;---------------------------------
;Processor initialization
;---------------------------------
;--------------------------------------------------------
;Frontline Electronics Pvt Ltd, Salem, INDIA. 04-FEB-2001
;
;TMS320c50 Processor initialization program for DSP LAB.
; (FEPL 5X EVM target board).
;--------------------------------------------------------
start: ldp #0 ;data page pointer to page zero
setc INTM ;globally disable interrupts
setc SXM ;set sign extension mode
setc OVM ;set saturation on arithmetic overflow
clrc CNF ;configure B0 as data memory.
spm 0 ;no product register shift.
splk #0834h,PMST ;set processor mode status reg.
lacl #0 ;accumulator = 00.
samm CWSR ;store accu. in CWSR & PDWSR.
samm PDWSR ;clear wait state registers.
clrc CNF ;B0 is in data memory.
splk #0,gotflag ;zero data received flag
splk #0,outbuff ;zero output storage flag
splk #012h,IMR ;enable RINT & INT2.
call ac01_init ;call to initialize serial port & AC01.
clrc INTM ;enable all interrupts.
wait: nop ;wait for interrupt.
b wait
;---------------------------------
;Receive interrupt handler
;---------------------------------
getdatasplk #1,gotflag ;set a flag to indicate data available.
lamm DRR
ldp #mod ;set data page pointer.
lacc mod ;load modifier
samm INDX ;store modifier in INDX register.
callwavgen ;calculate current sample output from wavetable.
and #0FFFCh,0 ;only 14 MSBs are used in ADC &DAC,So
; mask unused two LSBs.
samm DXR ;send digital data to DAC to produce analog o/p.
clrc INTM ;enable interrupt.
rete ;return back to main from interrupt routine.
offset .set 1320h ;table length = 800 + table start address.
;-------------------------------------------------
;Frontline Electronics Pvt Ltd, Salem, INDIA.
;
;wavgen.asm - waveform generation module.
;-------------------------------------------------
wavgen:
ldp #temp ;set Data page pointer.
mar *,AR1 ;set current ARP to AR1(wavetable pointer)
lt *0+ ;load T-reg with wavetable current data,
;and modify pointer to point next data.
sar AR1,temp
lacc temp
sub #offset,0 ;subtract offset, to check end of table.
bcndn_oflw,LT
or #1000h,0 ;if table exceeds limit, initialize
sacl temp ;wavetable pointer(circular buffer effect).
lar AR1,temp
n_oflw: mpy scale ;scaling correction.
apac ;accumulator = scaled sample.
sach temp,1
lacc #0
lacl temp
ret ;return.
;---------------------------------
;AC01 register initialization.
;---------------------------------
REG1 .set 0124h
; 0000000100100100b ;36 -> 8ks/sec @ 10.368Mhz clockin
REG2 .set 0212h
; 0000001000010010b ;reg 2 = B register 18(18,default),8ks/sec
; ||||||||||||||||
; ||||||||++++++++-- data
; |||+++++---------- address
; ||+--------------- 0 = write
; ++---------------- phase shift
REG4 .set 0417h
; 0000010000010111b ;reg4 amplifier gain sellect
; ||||||||||||||++-- output 0=sq, 1=0 dB, 2=-6 dB, 3=-12 dB
; ||||||||||||++---- input 0=sq, 1=0 dB, 2=+6 dB, 3=+12 dB
; ||||||||||++------ monitor 0=sq, 1=0 dB, 2=-8 dB, 3=-18 dB
; ||||||||++-------- not used
; |||+++++---------- address
; ||+--------------- 0 = write
; ++---------------- phase shift
REG5 .set 0505h
; 0000010100000101b ;reg5 Analog configuration
; ||||||||||||||++-- 0=loopback, 1=norm i/p, 2=aux i/p, 3=both
; |||||||||||||+---- 0=hp filter on, 1=hpfilter off
; ||||||||||||+----- 0=echo off, 1=echo on
; ||||||||++++------ not used
; |||+++++---------- address
; ||+--------------- 0 = write
; ++---------------- phase shift
;---------------------------------
;Serial port and AC01 initialization
;---------------------------------
;--------------------------------------------------------
;Frontline Electronics Pvt Ltd, Salem, INDIA. 04-FEB-2002
;
;AC01INZ.asm - AC01-AIC chip initialisation program for DSP LAB.
; (FEPL 5X EVM target board).
;--------------------------------------------------------
;---------------------------------
;Internal memory buffers
;---------------------------------
gotflag .set 60h ;used to signal that an interrupt
;came from the serial port.
ac01_init
;set up serial port
splk #0,dxr ;zero data transmit register
splk #08h,SPC ;use external clock and sync.
opl #0c0h,SPC ;take it out of reset.
splk #0ffffh,IFR ;clear all interrupt flag bits
clrc INTM ;enable interrupts
callwaitint ;wait for interrupt from serial port.
;reset AC01 AIC
lacc #080h ;accu = 00000080h
sacl GREG ;set GREG to 0080h,to select global memory
lar ar0,#0FFFFh ;set AR0 = 0ffffh.
rpt #10 ;repeat following instruction 10 times.(delay).
lacc *,0,ar0 ;dummy read to reset AIC.
lacl #0
sacl GREG ;remove global memory.
;setup codec - only need to reprogram those registers that need
; to be changed from their defaults
;reg 0 = default
lacc #REG1,0 ;reg 1 = A register (18 = default)
callprogreg
lacc #REG2,0 ;reg 2 = B register (18 = default)
callprogreg
;reg3 = A' register = default.
lacc #REG4,0 ;reg4 amplifier gain sellect
callprogreg
lacc #REG5,0 ;reg5 Analog configuration
callprogreg
;reg6, digital configuration = default
;reg7, frame sync delay = default
;reg8, frame sync number = default
ret
;---------------------------------
;wait for interrupt subroutine
;---------------------------------
waitint
laccgotflag
bcndwaitint,EQ ;wait for semaphore to be changed
splk #0,gotflag ;set it again
ret
;------------------------------------
;AC01 register programming subroutine
; input: ACC = register command
;------------------------------------
progregsacb ;backup command in Acc B
splk #03h,dxr ;request secondary communication.
callwaitint ;wait for transmission
lacb ;load commnd from Acc B
sammdxr ;send value
callwaitint ;wait
ret
.END ;end of program.
Sine wave generation
.mmregs;initialise all registers.
.ds 1000h
.include "sinetbl.dat" ;load 800 point wavetable
;f1= fs/D = 8000/800 = 10hz.
.ds 0f00h
temp .word 0
mod .word 100 ;Required freq. = mod * f1 = 100*10 = 1000hz.
scale .q15 0.5
.ps 080ah
rint b getdata ;receive interrupt
xint b xint ;transmit interrupt
.ps 0a00h ;program entry point
.entry
.include "c5xinz.asm"
splk #012h,IMR ;enable RINT & INT2.
call ac01_init ;call to initialize serial port & AC01.
clrc INTM ;enable all interrupts.
wait: nop ;wait for interrupt.
b wait
getdatasplk #1,gotflag ;set a flag to indicate data available.
lamm DRR
ldp #mod ;set data page pointer.
lacc mod ;load modifier
samm INDX ;store modifier in INDX register.
callwavgen ;calculate current sample output from wavetable.
and #0FFFCh,0 ;only 14 MSBs are used in ADC &DAC,So
; mask unused two LSBs.
samm DXR ;send digital data to DAC to produce analog o/p.
clrc INTM ;enable interrupt.
rete ;return back to main from interrupt routine.
offset .set 1320h ;table length = 800 + table start address.
.include "wavgen.asm" ;includewavgen module.
REG1 .set 0124h
; 0000000100100100b ;36 -> 8ks/sec @ 10.368Mhz clockin
REG2 .set 0212h
; 0000001000010010b ;reg 2 = B register 18(18,default),8ks/sec
; ||||||||||||||||
; ||||||||++++++++-- data
; |||+++++---------- address
; ||+--------------- 0 = write
; ++---------------- phase shift
REG4 .set 0417h
; 0000010000010111b ;reg4 amplifier gain sellect
; ||||||||||||||++-- output 0=sq, 1=0 dB, 2=-6 dB, 3=-12 dB
; ||||||||||||++---- input 0=sq, 1=0 dB, 2=+6 dB, 3=+12 dB
; ||||||||||++------ monitor 0=sq, 1=0 dB, 2=-8 dB, 3=-18 dB
; ||||||||++-------- not used
; |||+++++---------- address
; ||+--------------- 0 = write
; ++---------------- phase shift
REG5 .set 0505h
; 0000010100000101b ;reg5 Analog configuration
; ||||||||||||||++-- 0=loopback, 1=norm i/p, 2=aux i/p, 3=both
; |||||||||||||+---- 0=hp filter on, 1=hpfilter off
; ||||||||||||+----- 0=echo off, 1=echo on
; ||||||||++++------ not used
; |||+++++---------- address
; ||+--------------- 0 = write
; ++---------------- phase shift
.include "ac01inz.asm"
.END ;end of program.
Adder
.mmregs;initialise all registers.
.ds 1000h
X1 .word 55h ;X input -> X1 X0 (32 bits)
X0 .word 66h
Y1 .word 77h ;Y input -> Y1 Y0 (32 bits)
Y0 .word 88h
Z1 .word 0 ;Z output -> Z1 Z0 (32 bits)
Z0 .word 0
.include "begin1.asm" ;Initialisation routine.
ADD32:
ldp #X0 ;set data page pointer.
lacc X1,16 ;Acc = X1 00
adds X0 ;Acc = X1 X0
adds Y0 ;Acc = X1 X0 + 00 Y0
add Y1,16 ;Acc = X1 X0 + Y1 Y0
sacl Z0 ;store Z0 result.
sach Z1 ;store Z1 result.
hlt: b hlt ;halt program.
.END ;end of program.
Multiplier
.mmregs;initialise all registers.
.ds 1000h
X0 .word 55h ;X input -> X0 (16 bits)
Y0 .word 77h ;Y input -> Y0 (16 bits)
Z1 .word 0 ;Z output -> Z1 Z0 (32 bits)
Z0 .word 0
.include "begin1.asm"; Initialisation routine.
MUL16:
ldp #X0 ;set data page pointer.
lt X0 ;load X0 in T register.
mpy Y0 ;multiply T * Y0 (signed).
spl Z0 ;store Product reg. low in Z0.
sph Z1 ;store Product reg. high in Z1.
hlt: b hlt ;halt program.
.END ;end of program.
PERIODOGRAM BASED ON SPECTRAL EFFICIENCY
Output:
Enter the length of the sequence4
length of the fft4
Sampling frequency500
Program: clc;
close all;
clear all;
n=input('Enter the length of the sequence');
window=hamming(n);
nfft=input('length of the fft');
fs=input('Sampling freq');
n=0:1:n-1;
x=cos(2*0.1*pi*n/fs)+sin(2*0.4*pi*n/fs)+0.01*rand(size(n));
subplot(2,1,1);
plot(n,x);
xlabel('n');
ylabel('x(n)');
[pxx,f]=periodogram(x,window,nfft,fs);
subplot(2,1,2);
plot(f/fs,10*log10(pxx));
grid;
xlabel('|omega| \pi');
ylabel('Power spectrum');
title('Periodogram');
Program: clc;
close all;
clear all;
t=0:1/200:10;
y=3*cos(2*pi*50*t/200)+1*cos(2*pi*100*t/200);
figure(1);
stem(y);
xlabel({'Times in seconds';'(a)'});
ylabel('Amplitude');
figure(2);
stem(decimate(y,20));
xlabel({'Times in seconds';'(b)'});
ylabel('Amplitude');
figure(3);
stem(interp(decimate(y,20),2));
xlabel({'Times in seconds';'(c)'});
ylabel('Amplitude');
Program: clc;
clear all;
close all;
fm=15;
t=0:0.001:0.5;
in_sig=cos(2*pi*fm*t);
subplot(2,2,1);
plot(t,in_sig);
title('input sig');
fs1=2*fm;
t1=0:1/fs1:.5;
out_sig1=cos(2*pi*fm*t1);
subplot(2,2,2);
plot(2*pi*fm*t1,out_sig1);
title('fs=2fm');
fs2=2*fm+50;
t2=0:1/fs2:.5;
out_sig2=cos(2*pi*fm*t2);
subplot(2,2,3);
plot(2*pi*fm*t2,out_sig2);
title('fs>2fm');
fs3=2*fm-2;
t3=0:1/fs3:.5;
out_sig3=cos(2*pi*fm*t3);
subplot(2,2,4);
plot(2*pi*fm*t3,out_sig3);
title('fs<2fm(aliasing)');
Program:
Division
;-------------------------------------------------
;Frontline Electronics Pvt Ltd, Salem, INDIA. 23-10-2001
;
;fx16id.asm - Fixed point signed 16bit integer division.
;-------------------------------------------------
.mmregs ;initialise all registers.
.ds 1000h
TEMSGN .word 0
DENOM .word 05h
NUMERA .word 19h
QUOT .word 0
REM .word 0
.listoff
;-------------------------------------------------
;Frontline Electronics Pvt Ltd, Salem, INDIA.
;
;Begin1.asm - Example programs beginning code.
; (without AIC initialization).
;-------------------------------------------------
.mmregs ;initialise all registers.
;-------------------------
;Main Program starts here.
;-------------------------
.ps 0a00h ;set program segment starting address.
.entry ;set entry point,used in down loading program.
START: SETC INTM ;disable all Interrupts.
LDP #00 ;data page pointer = 0.
OPL #0834h,PMST;set processor mode status reg.
LACC #00 ;accumulator = 00.
SAMM CWSR ;store accu. in CWSR & PDWSR.
SAMM PDWSR ;clear wait state registers.
SPLK #02h,IMR ;enable INT2.
;you must enable INT2 always,because
;it is used for serial communication
;between starter kit & host computer.
CLRC INTM ;clear interrupt mask bit.
.liston
INTDIV:
setc sxm ;set sign extention.
clrc ovm ;clear overflow mode.
ldp #DENOM ;set data page pointer.
lt NUMERA ;determine sign of quotient.
mpy DENOM
sph TEMSGN ;save the sign.
lacc DENOM
abs ;make denominator and numerator positive.
sacl DENOM ;save absolute value of denominator.
lacc NUMERA
abs ;acc. = absolute value of numerator.
rpt #15 ;16 cycle division. Low accumulator contains
subc DENOM ;the quotient and high accumulator contains
;the remainder at the end of the loop.
bit TEMSGN,0;Test sign of quotient.
sach REM ;Save remainder.
xc 1,TC ;
neg ;if sign negative, negate quoitient.
sacl QUOT ;Store quotient.
hlt: b hlt ;halt program.
.END ;end of program.
top related