Program: %generation of Basic Signals
Program: %generation of Basic Signals
Input:
enter the first sequence:[1,2,3,1]
enter the second sequence[1,2,2,1]
Output:
The resultant signal is :
y= 1 4 9 12 10 5 1
LINEAR CONVOLUTION
input sequence
4
amplitude
0
1 1.5 2 2.5 3 3.5 4
x(n)
impulse sequence
2
amplitude
0
1 1.5 2 2.5 3 3.5 4
h(n)
output sequence
20
amplitude
10
0
1 2 3 4 5 6 7
y(n)
Circular Convolution
Input:
enter the first sequence:[1,2,3,1]
enter the second sequence[1,2,2,1]
Output:
The circular convolution output is :
y1 = 11 9 10 12
CIRCULAR CONVOLUTION
1.8
2.5 10
1.6
1.4
2 8
1.2
amplitude
amplitude
amplitude
1.5 1 6
0.8
1 4
0.6
0.4
0.5 2
0.2
0 0 0
0 2 4 0 2 4 0 2 4
x(n) h(n) y1(n)
PROGRAM:
Output:
y = Columns 1 through 5
Columns 6 through 8
7 30
3
25
6
2
20
5
15 1
4
y(n)
y(n)
y(n)
10 0
3
5
-1
2
0
1 -2
-5
0 -10 -3
0 5 10 0 5 10 0 5 10
n n n
PROGRAM:
%Sampling Theorem
clc;
close all;
clear all;
f1=1/128;f2=5/128;n=0:255;fc=50/128;
x=cos(2*pi*f1*n)+cos(2*pi*f2*n);
xa=cos(3*pi*fc*n);
xamp=x.*xa;
subplot(2,2,1);
plot(n,x);
title('Modulating signal');
xlabel('time');
ylabel('amplitude');
subplot(2,2,2);
plot(n,xa);
title('Carrier signal');
xlabel('time');
ylabel('amplitude');
subplot(2,2,3);
plot(n,xamp);
title('Modulated signal');
xlabel('time');
ylabel('amplitude');
FIGURE: 1
1 0.5
0 0
plitude
plitude
am
am
-1 -0.5
-2 -1
0 100 200 300 0 100 200 300
time time
Modulated signal
2
0
amplitude
-1
-2
0 100 200 300
time
SAMPLING THEOREM
FIGURE: 2
30
25
20
a m p litu d e
15
10
-5
0 20 40 60 80 100 120 140
time
SAMPLING THEOREM
FIGURE: 3
25
20
15
amplitude
10
-5
-10
-15
0 20 40 60 80 100 120 140
time
PROGRAM:
%Design FIR filter using Rectangular window
% Clear the screen
clc;
close all;
clear all;
n=input('Enter the order of the filter: ');
wn=input('Enter cut off frequency: ');
wn1=input('Enter the cut off frequencies Wn1,Wn2: ');
w=boxcar(n+1);
Output:
Output of b =
Columns 1 through 9
Columns 10 through 13
RECTANGULAR WINDOW
0 0
Gain in DB
Gain in DB
-50 -50
-100 -100
0 0.5 1 0 0.5 1
Normalized frequency Normalized frequency
Band pass filter Bandstop filter
20 20
0 0
Gain in DB
Gain in DB
-20 -20
-40 -40
-60 -60
0 0.5 1 0 0.5 1
Normalized frequency Normalized frequency
PROGRAM:
%Design FIR filter using Hamming window
%Clear the screen
clc;
close all;
clear all;
n=input('Enter the order of the filter: ');
wn=input('Enter cut off frequency: ');
wn1=input('Enter the cut off frequencies Wn1,Wn2: ');
w=hamming(n+1);
Output:
Output of b =
Columns 1 through 9
Columns 10 through 13
HAMMING WINDOW
0 0
Gain in DB
Gain in DB
-50 -50
-100 -100
0 0.5 1 0 0.5 1
Normalized frequency Normalized frequency
Band pass filter Bandstop filter
0 5
-20
0
Gain in DB
Gain in DB
-40
-5
-60
-80 -10
0 0.5 1 0 0.5 1
Normalized frequency Normalized frequency
PROGRAM:
%Design FIR filter using Hanning window
%Clear the screen
clc;
close all;
clear all;
n=input('Enter the order of the filter: ');
wn=input('Enter cut off frequency: ');
wn1=input('Enter the cut off frequencies Wn1,Wn2: ');
w=hanning(n+1);
Output:
output of b =
Columns 1 through 9
Columns 10 through 18
Column 19
0.0000
HANNING WINDOW
0
0
Gain in DB
Gain in DB
-50
-50
-100
-100 -150
0 0.5 1 0 0.5 1
Normalized frequency Normalized frequency
Band pass filter Bandstop filter
0 50
-20
0
Gain in DB
Gain in DB
-40
-50
-60
-80 -100
0 0.5 1 0 0.5 1
Normalized frequency Normalized frequency
PROGRAM:
Input:
Output:
Columns 10 through 18
82.2008 108.0509 127.0999 134.1508 127.0999 108.0509 82.2008 55.7576 33.4957
Columns 19 through 27
17.6733 8.0770 3.1424 1.0086 0.2561 0.0465 0.0051 1.0000 5.4979
Columns 28 through 36
16.4646 35.3450 61.1848 89.9227 115.1711 130.5669 132.6060 121.5685 101.0611
Columns 37 through 45
76.3656 52.5289 32.8800 18.6958 9.6240 4.4647 1.8532 0.6817 0.2191
Columns 46 through 50
0.0604 0.0138 0.0025 0.0003 0.0000
BUTTERWORTH FILTER
FIGURE:1
Phase in radians
2
0
Gain in DB
0
-200
-2
-400 -4
0 0.5 1 0 0.5 1
Normalized frequency Normalized frequency
High pass filter
200 4
Phase in radians
2
0
Gain in DB
0
-200
-2
-400 -4
0 0.5 1 0 0.5 1
Normalized frequency Normalized frequency
BUTTERWORTH FILTER
FIGURE:2
-100 2
Gain in DB
-200 0
-300 -2
-400 -4
0 0.5 1 0 0.5 1
Normalized frequency Normalized frequency
Band stop filter
100 4
Phase in radians
0 2
Gain in DB
-100 0
-200 -2
-300 -4
0 0.5 1 0 0.5 1
Normalized frequency Normalized frequency
PROGRAM: (Addition)
.include”5416_iv.asm”
.def start
.data
.word 0003h,0004h
.text
Input:
1500=0003
1501=0004
Output:
1502=0007
PROGRAM: (Subtraction)
.include”5416_iv.asm”
.def start
.data
.word 0004h,0003h
.text
Input:
1500=0004
1501=0003
Output:
1502=0001
PROGRAM: (Multiplication)
.include”5416_iv.asm”
.def start
.data
.word 0003h,0004h
.text
Input:
1500=0003
1501=0004
Output:
1504=000C
PROGRAM: (Division)
.include”5416_iv.asm”
.def start
.data
.word FFFFh,0002h
.text
Input:
1000=FFFF
1001=0002
Output:
2000=7FFF
2001=0001
PROGRAM: (IIR filter)
.include”5416_iv.asm”
.def start
.data
Pole .word a7e 3h,154fh
Azero .word 0b4ch,1698h,064ch
Xin .word 0,0
Xout .word 0
.text
.include”500.asm”
Start LD #b pole,DP
STM #3000h,AR3
STM #4000h,AR4
STM #5000h,AR1
STM #6000h,AR2
STM #8000h,AR0
STM #7000h,AR5
STM #80h,BRL
RPTB LOOP
NTAR *AR2+
RPT #02h
MACD *AR2-,Azero,A
STH A,0,*AR0
LD #0h,A
MVDD *AR5+,*AR4+
RPT #01h
MACD *AR4-,b Pole A
RPT #01h
MACD *AR4-,b Pole A
STH A,0,*AR7
LD *AR0,A
LD *AR7,B
ADD B,0,A
STA A,*AR5
RPT #01h
MAR *AR4+
MAR *AR2+
MAR *AR7+
MAR *AR0+
.end
PROGRAM: (FIR Filter)
.include”5416_iv.asm”
.def start
.data
.word 086eh,0b9eh,0e5fh,1064h,
176h,1064h, 0e5fh, 0b9eh, 086eh
.text
COEFF .include”s500.asm”
STM #3000h,AR3
STM #5000h,AR1
STM #80h,BRC
RPTB LOOP
MVDD *AR5+,*AR3
RPT #08h
MAR *AR3+
RPT #09h
MACD *AR3-,COEFF,A
STH A,0,*AR1+
.end
PROGRAM:(FFT)
.include”twi.asm”
.include”twr.asm”
.include”cos.asm”
.include”5416_iv.asm”
.def start
.data
R1 .word 0h ;variables
I1 .word 0h
Stages .word 7h
Grp .word 0h
Grp1 .word 0h
but .word 1h
but1 .word 0h
R .word 0h
I .word 0h
A1 .word 0h
sizetw .word 40h
sizein .word 80h
bitr .word 40h
shi .word 7Fh
CNT .word 128
E .word 45h
.text
Start LD #R1,DP
RSBX INTM
LD #022Bh,0,A
STLM A,P,MST
RSBX INTM
LD #01 7h,0,A
STLM A,IMR
STM #0h,McBSP0_DXR1
STM #0h,McBSP0_DXR2
STM #0007h,GPIOCR
STM #0003h,GPIOSR
STM #SPCR2,McBSP2_SPSA
STM #00E1h,McBSP2_SPSD ;Mclk
NOP
STM #007h,GPIOSR
STM #SPCR2,McBSPO_SPSA
STM #00E1h,McSPSD ;Sclk & Fs
STM #1000h,AR6 ;FFT I/P
STM #1800h,AR1 ;FFT O/P
SSBX SXM
RSBX OVM
LD #0h,0,A
RPT #127
STL A,*AR1+
STM #1800h,AR1
STM #3500h,AR7
WAIT NOP
NOP
LD CNT,B
BC FFT,BEQ
NOP
NOP
B WAIT
_RINT0_ISR
PSHM AL
PSHM AH
PSHM AG
PSHM BL
PSHM BH
PSHM BG
LD *AR6+,0,A
STLM A,McBSP0_DXR1 ;O/P for R channel
STLM A,McBSP0_DXR2 ;O/P for L channel
LD CNT,B
SUB #IH,0,B
STL B,0,BNT
POPM BG
POPM BH
POPM BL
POPM AG
POPM AL
RETE
FET NOP
NOP
LD #0,A
STLM A,IMR
STM #1000h,AR6
STM #1800h,AR1
STM #2000h,AR4
STM #1000h,AR3
RPT #127
MVDD *AR4+,*AR3+
LD #R1,DP
NOP
LD #80h,A
STL A,CNT
NOP
PORTW E,0
;----------------Bit Reversal-----------------------------------------------
;----------------For 128pt FFT the index value is 128/2=64(40h)----
NOP
NOP
STM #2400h,AR5
LD #0h,0,A
STM #2800h,AR3
RPT #127
STL A,0,*AR3+
STM #3000h,AR3 ;TWIDDLE REAL
STM #3400h,AR4 ;TWIDDLE IMAG
STM #40h,BK
-----------------------------------Butterfly loop Begins-------------------------------------
SU LD Stages,0,A
LD Grp,0,B
STL B,Grp1
LD but,0,A
STM #2400h,AR5
STM #2800h,AR2
GU LD #40h,B
STLM B,BK
LD but,0,A
STL A,but1
LD #0h,0,B
SUB A,0,B
STL B,A1
STM #3000h,AR3
STM #3400h,AR4
BU LD #80h,B
STLM B,BK
LD *AR5,0,A
LD *AR2,0,B
STL A,0,R
STL B,0,I
LF but,0,S
DTLM S,SR0
NOP
NOP
MAR *AR5+0%
MAR *AR2+0%
MAR *AR3,*AR5,A
MAR *AR4,*AR2,B
SUB B,0,A
STH A,R1
MPY *AR3,*AR3,A
MPY *AR4,*AR5,B
ADD A,0,B
STH B,I1
LD R,-1,A
LD R1,0,B
SUB B,0,A
STL A,*AR5
LD I,-1,A
LD I1,0,B
SUB B,0,A
STL A,*AR2
NOP
NOP
NOP
LD A1,0,B
STLM B,AR0
NOP
NOP
MAR *AR5+0%
MAR *AR2+0%
LD R,-1,A
LD R1,0,B
ADD B,0,A
STL A,*AR5+
LD I,-1,A
LD I1,0,B
SUB B,0,A
STL A,*AR2+ ;BUT
NOP
LD #40h,0,B
STLM B,BK
LD Grp,0,A
STLM A,AR0
NOP
NOP
NOP
NOP
MAR *AR3+0%
MAR *AR4+0%
LD but1,0,B
SUB #1h,0,B
STL B,0,but1
BC BU,BNEQ ;;;;;;;;;;;;;;Butterfly end
LD #80h,B
STLM B,BK
NOP
NOP
NOP
LD but,0,B
STLM B,AR0
NOP
NOP
MAR *AR5+0%
MAR *AR2+0%
LD Grp1,0,B
SUB #1h,0,B
STL B,Grp1
BC GU,BNEQ ;;;;;;;;;;;;;;Group end
NOP
LD but,0,B
SFTA B,1
STL B,but
STL B,but1
LD Grp,0,B
SFTA B,-1
STL B,Grp
STL B,Grp1
LD Stages,0,a
SUB #1h,0,a
STL A,Stages
BC SU,ANEQ ;;;;;;;;;;;;;;STAGES
LD #0h,0,A
LD #0h,0,B
----------------------------------Initialization of Variables-------------------------------------------
LD #7h,0,B
STL B,Stages
LD #40h,0,A
STL A,Grp
LD #1h,0,B
STL B,but
STM #2400h,AR3
STM #1800h,AR6
STM #7Fh,BRC
RPTB VE
LD *AR3+,A
ABS A
STL A,*AR6+
NOP
VE NOP
NOP
STM #1800h,AR6
LD #001h,A
STLM A,IMR
NOP
NOP
B WAIT
INTERFACING
PROGRAMS