Sunteți pe pagina 1din 144

Department of Electronics and Communication Engineering

DIGITAL SIGNAL PROCESSING


LABORATORY MANUAL
(2010 2011)

EX.NO:
AND
DATE:

GENERATION OF SINE, SQUARE


TRIANGULAR WAVE FORMS

AIM:
To generate sine wave, triangular wave, square wave.

ALGORITHM:
1. SINE WAVE:
STEP 1: Get the values oft for sine wave.
STEP 2: Generate the function with y (n) =sin (2*pi*t).
STEP 3: Take x as the time period and y as the amplitude of
the waveform.
2. TRIANGULAR WAVE:
STEP 1: Get the values oft.
STEP 2: Give the amplitude for corresponding position.
STEP 3: Plot the function with x as the time period and y as
the amplitude.
3. SQUARE WAVE:
STEP 1: Get the values oft for square wave.
STEP 2: Give amplitude for corresponding position.

STEP 3: Plot the function with x as the time period and y as


amplitude.

FLOWCHART:

START
INITILIZE THE WAVE

GENERATE THE SEQUENCE OF ZEROES ONES


COMMAND BY THEIR PREDEFINED DEFINITION

LABEL X-AXIS: TIME INDEX


LABEL Y-AXIS: AMPLITUDE

STOP

PROGRAM:
1. SQUARE SEQUENCE:
FS=input('sampling frequency:');

N=input(' no of samples:');
n=1:N;
F=input ('frequency of square wave:');
f=F/FS;
x=square(2*pi*f*n);
stem(x);
title('square wave');
xlabel('samples .......>');
ylabel('amplitude......>');
2. SINE SEQUENCE:
clc;
N4=input('enter the length of the input sequence');
X4=input('enter the n0. of cycles');
n4=0:pi/N4:X4*pi;
Y4=sin(2*n4);
subplot(3,2,4);
plot(n4*N4/pi,Y4);
title('sinusoidal sequence');
xlabel('sample...>');
ylabel('amplitude.....>');
3. TRIANGULAR SEQUENCE:
clc;
t=-2:1:2;
y=[zeros(1,1),ones(1,1),zeros(1,1),ones(1,1),zeros(1,1)];
subplot(2,2,1);
plot(t,y);
xlabel('sample>');
ylabel('amplitude..>');
title('triangle sequence:');

INPUT:
1. SQUARE WAVE:
sampling frequency:400
no of samples:40
frequency of square wave:40
2. SINUSOIDAL SEQUENCE:
enter the length of the input sequence:10
enter the n0. of cycles:10
OUTPUT:
1. SQUARE WAVE:

2. SINUSOIDAL SEQUENCE:

3. TRIANGULAR SEQUENCE:

RESULT:
Thus the MATLAB programs for generation of sine, square and
triangular waveform is written, executed and the output is
verified.

EXP. NO.:
DATE

GENERATION OF SEQUENCE

AIM:
To write and execute the MATLAB simulation program for
generating the following sequence
(i) Unit impulse sequence
(ii) Unit step sequence
(iii) Unit ramp sequence

ALGORITHM:
UNIT IMPULSE SEQUENCE:
STEP 1:
STEP 2:
STEP 3:
STEP 4:
STEP 5:

Start the process


Obtain the length of the sequence
Generate the sequence
Plot the generated sequence
Stop the process

UNIT STEP SEQUENCE:


STEP 1:
STEP 2:
STEP 3:
STEP 4:
STEP 5:

Start the process


Obtain the length of the sequence
Generate the sequence y(n)=10, 0<n<N-1
Plot the generated sequence
Stop the process

UNIT RAMP SEQUENCE:


STEP 1:
STEP 2:
STEP 3:
STEP 4:
STEP 5:

Start the process


Obtain the length of the sequence
Generate the sequence y(n)=n, 0<n<N-1
Plot the generated sequence
Stop the process

FLOWCHART:

START

INITIALISE THE WAVEFORM ASSUME AS -2 TO 2

GENERATE THE SEQUENCE OF ZEROS AND ONES


COMMAND BY THEIR PREDEFINED DEFINITIONS

LABEL X AXIS: TIME INDEX


LABEL Y AXIS: AMPLITUDE INDEX

STOP

PROGRAM:

UNIT IMPULSE SEQUENCE:


clc;
n=-2:1:2;
y=[zeros(1,2),ones(1,1),zeros(1,2)];
subplot(2,2,1);
stem(n,y);
title('unit impulse');
xlabel('time index.....>');
ylabel('amplitude.....>');
disp(n);

UNIT STEP SEQUENCE:


clc;
a=input('enter the length of the input sequence');
n1=0:1:a-1;
y=[ones(1,a)];
subplot(3,2,2);
stem(n1,y);
title('unit step');
xlabel('time index.....>');
ylabel('amplitude.....>');
disp(n1);

UNIT RAMP SEQUENCE:


clc;
a1=input('enter the length of the input sequence');
n2=0:1:a1-1;
subplot(2,2,3);
stem(n2,n2);
title('unit Ramp');
xlabel('time index....>');
ylabel('amplitude.....>');
disp(n2);

GRAPH:
OUTPUT :
Enter the length of the step sequence: 5
Enter the length of ramp sequence: 5

RESULT:
Thus the MATLAB simulation program for generating
1. Unit step sequence
2. Unit ramp sequence
3. Unit impulse sequence
are executed and output is verified.

EXP. NO.:
DATE

LINEAR CONVOLUTION

AIM:
To write and execute MATLAB program to find linear
convolution

ALGORITHM:
STEP 1: Start the program
STEP 2: Get the two signals x(n) and h(n) in matrix form
STEP 3: The convolution is denoted by y(n)
STEP 4: y(n)= x(k) h(n-k). Where n=0 to n+p-1
STEP 5: Stop the program

FLOWCHART:

START

ENTER x(n) AND h(n)

y=conv(x,h)

DISPLAY INPUT AND OUTPUT SEQUENCES

STOP

PROGRAM:
clc;
disp('input:');
x=input('enter the 1st sequence:');
h=input('enter the 2nd sequence:');
y=conv2(x,h);
display('output');
figure;
subplot(3,1,1);
stem(x);
xlabel('sample-->');
ylabel('magnitude-->');
title('1st sequence');
subplot(3,1,2);
stem(h);
xlabel('sample-->');
ylabel('magnitude-->');
title('2nd sequence');
subplot(3,1,3);
xlabel('sample-->');
ylabel('magnitude-->');
stem(y);
title('after convolution');
disp('the resultant signal is:');
disp('y');

INPUT:
enter the 1st sequence:[1 3 4]
enter the 2nd sequence:[2 3 5 6]

OUTPUT:
The resultant signal is: y

RESULT:
Thus the MATLAB simulation program for linear convolution of
two samples has been written and executed.

EXP. NO.:
DATE

CIRCULAR CONVOLUTION

AIM:
To write and execute a MATLAB simulation program for
generating a circular convolution.

ALGORITHM:
STEP 1:
STEP 2:
STEP 3:
STEP 4:

Get the two signals x(n) and h(n) in matrix form


The convolution is denoted by y(n)
y(n)= x(k) h(n-k) when n=0 to m+D-1 k=-
Stop the program

FLOWCHART:

START

GET TWO
SEQUENCE

IF ZERO
PADDING
REQUIRE
PORT ZERO

PERFORM CIRCULAR
CONVOLUTION

CALCULATE
CONVOLUTION BY MATRIX
MULTIPLICATION

DISPLAY THE
PLOT

STOP

PROGRAM:
clc;
x=input('enter the first sequence:');
h=input('enter the second sequence:');
N1=length(x);
N2=length(h);
N=8;
x=[x zeros(1,N-N1)];
h=[h zeros(1,N-N2)];
M=[0:1:N-1];
disp(M);
h=h(M+1);
disp(h);
M=mod(-M,N);
disp(M);
for n=1:1:N
M=n-1;
p=0:1:N-1;
q=mod(p-M,N);
disp(q);
hm=h(q+1);
H(n,:)=hm;
disp(H(n,:));

end
y=x*H;
%plot;
n1=0:1:n-1;
subplot(3,1,1);
stem(n1,x);
title(' First sequence');
xlabel('sample.....>');
ylabel(' magnitude....>');
subplot(3,1,2);
stem(n1,h);
title('second sequence');
%xlabel('sampel.....');
ylabel('magnitude....>');
subplot(3,1,3);
stem(n1,y);
disp(y);
title(' circular convolution ');
xlabel('sample...>');
ylabel('magnitude....>');

INPUT:
enter the first sequence:[1 2 3 4]
enter the second sequence:[1 2 3 4]

OUTPUT:

RESULT:
Thus the MATLAB simulation program for circular convolution
of two samples has been written and executed.

EXP. NO.:
DATE

SAMPLING OF SIGNALS

AIM:
To write and execute the MATLAB program for generating
sampling for
the given signals.

ALGORITHM:
STEP 1: Start the program.
STEP 2: Get the band of signals to be sampled
STEP 3: Determine the highest frequency component

STEP 4: Calculate twice the highest frequency component


STEP 5: Sample the input signal at three different rates of =
2fh>2fh<2fh
STEP 6: Obtain the sampled signal output
STEP 7: Stop the process.

FLOWCHART:

START
GET THE INPUT SIGNALS

GET FH
CALCULATE 2FH
SAMPLE THE INPUT SIGNAL AT 2FH<2FH>2FH
GET THE CORRESPONDING
SAMPLED OUTPUTS

STOP

PROGRAM:
fig size=[232 84 774 624];
Ts1=0.05;
Ts2=0.1;
Ts3=0.2;
ws1=2*pi/Ts1;
ws2=2*pi/Ts2;
ws3=2*pi/Ts3;
w1=7;
w2=23;
t=[0:0.005:2];
x=cos(w1*t)+cos(w2*t);
disp('x');
disp(x);
figure(1),clf,plot(t,x),grid,xlabel('time (s)'),ylabel('amplitude'),...
title('continuous-time signal; x(t)=cos(7t)+cos(23)'),....
set(gcf,'position',fig_size)
t1=[0:Ts1:2];
xs1=cos(w1*t1)+cos(w2*t1);
disp('xs1');
disp(xs1);
figure (2),clf,stem(t1,xs1);
grid,hold on,plot(t,x,'r:'),hold off,...
xlabel('time (s)'),ylabel('amplitude'),....
title('sampled version of x(t) with T_s=0.05s'),...
set(gcf,'position',fig_size)
t2=[0:Ts2:2];
xs2=cos(w1*t2)+cos(w2*t2);
figure (3),clf,stem(t2,xs2);
grid,hold on,plot(t,x,'r:'),hold off,...
xlabel('time (s)'),ylabel('amplitude'),....
title('sampled version of x(t) with T_s=0.1s'),...

set(gcf,'position',fig_size)
t3=[0:Ts3:2];
xs3=cos(w1*t3)+cos(w2*t3);
figure (4),clf,stem(t3,xs3);
grid,hold on,plot(t,x,'r:'),hold off,...
xlabel('time (s)'),ylabel('amplitude'),....
title('sampled version of x(t) with T_s=0.2s'),...
set(gcf,'position',fig_size)
w2s3=w2-ws3;
x1=cos(w1*t)+cos(w2s3*t);
figure (5),clf,stem(t3,xs3);
grid,hold on,plot(t,x,'k:',t,x1,'r:'),hold off,...

xlabel('time (s)'),ylabel('amplitude'),....
title('sampling x(t) and x1(t) with T_s=0.2s'),...
set(gcf,'position',fig_size)
text(1.13,1.2,'x(t)'),text(0.1,1.6,'x_1(t)')
n=[-1 0 1];
wx=[-w2 -w1 w1 w2];
wx1=[];
wx2=[];
wx3=[];
for i=1:length(n)
wx1=[wx1 (wx+n(i)*ws1)];
wx2=[wx2 (wx+n(i)*ws2)];
wx3=[wx3 (wx+n(i)*ws3)];
end
wx1=sort(wx1);

wx2=sort(wx2);
wx3=sort(wx3);
clear i

RESULT:
Thus the MATLAB simulation program for generating samples of
the given signal has been written and executed.
EXP NO:
DATE :

BUTTERWORTH FILTER

AIM:
To write and execute a MATLAB program to design a
Butterworth
a) Low pass filter
b) High pass filter
c) Band pass filter
d) Band stop filter

ALGORITHM:
STEP 1: Start the program.
STEP 2: Get the values of pass band and stop band ripple, pass
band and stop band
frequency and sampling frequency.
STEP 3: Calculate the order of the filter.
STEP 4: Compute the frequency response and plot the graph.
STEP 5: Stop the program.

FLOWCHART:
1. LOW PASS FILTER

START
READ rp, rs, ws, fs

READ THE ORDER OF FILTER

USE BUTTORD TO DESIGN LPF

GET THE ANALOG FORM

OBTAIN MAGNITUDE AND PHASE

PLOT THE RESULT

STOP

PROGRAM:

1. LOW PASS FILTER


clc;
disp('Input:');
rp=input('Enter the passband ripple');
rs=input('Enter the stop band ripple');
wp=input('Enter the passband frequency');
ws=input('Enter the stopband frequency');
fs=input('Enter the sampling frequency');
w1=2*(wp/fs);
w2=2*(ws/fs);
disp('Output:');
disp('Order of sequence');
[n,wn]=buttord(w1,w2,rp,rs,'s');n
disp('3 db cutoff frequency');
disp('wn');
[b,a]=butter(n,wn,'low','s');n
w=0:.1:pi;
[b,om]=freqs(b,a,w);
m=20*log10(abs(b));m
an=angle(b);an
subplot(2,1,1);
plot(om/pi,m);
xlabel('Normalised frequency');
ylabel('gain in db.....>');
subplot(2,1,2);
plot(om/pi,an);
xlabel('Normalised frequency');

ylabel('Phase in radians.....>');
title('phase plot');

FLOWCHART:

2. HIGH PASS FILTER:

START
READ rp, rs, ws, fs

READ THE ORDER OF FILTER

USE BUTTORD TO DESIGN HPF

GET THE ANALOG FORM

OBTAIN MAGNITUDE AND PHASE

PLOT THE RESULT

STOP

PROGRAM:
2. HIGH PASS FILTER:

close all
clear all
disp('Input:');
rp=input('Enter the passband ripple');
rs=input('Enter the stop band ripple');
wp=input('Enter the passband frequency');
ws=input('Enter the stopband frequency');
fs=input('Enter the sampling frequency');
w1=2*(wp/fs);
w2=2*(ws/fs);
disp('Output:');
disp('Order of sequence');
[n,wn]=buttord(w1,w2,rp,rs,'s');n
disp('3 db cutoff frequency');
disp('wn');
[b,a]=butter(n,wn,'high','s');n
w=0:.01:pi;
[b,om]=freqs(b,a,w);
m=20*log10(abs(b));m
an=angle(b);an
subplot(2,1,1);
plot(om/pi,m);
xlabel('Normalised frequency');
ylabel('gain in db.....>');
subplot(2,1,2);
plot(om/pi,an);
xlabel('Normalised frequency');
ylabel('Phase in radians.....>');
title('phase plot');

FLOWCHART:

3. BAND PASS FILTER:

START
READ rp, rs, ws, fs

READ THE ORDER OF FILTER

USE BUTTORD TO DESIGN BPF

GET THE ANALOG FORM

OBTAIN MAGNITUDE AND PHASE

PLOT THE RESULT

STOP

PROGRAM:
3. BAND PASS FILTER:

clc;
disp('input');
rp=input('enter the passband ripple:');
rs=input('enter the stopband ripple:');
wp=input('enter the passband frequency:');
ws=input('enter the stopband frequency:');
fs=input('enter the sampling frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
disp('output');
disp('order of sequence');
[n,wn]=buttord(w1,w2,rp,rs,'s');
disp(wn);
wn=[w1 w2];
[b,a]=butter(n,wn,'bandpass','s');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel('gain in db');
xlabel('normalised frequency');
title ('magnitude response');
subplot(2,1,2);
plot(om/pi,an);
xlabel('normalised frequency');
ylabel('phase in radians');
title('phase response');

FLOWCHART:

4. BAND STOP FILTER:

START
READ rp, rs, ws, fs

READ THE ORDER OF FILTER

USE BUTTORD TO DESIGN BSF

GET THE ANALOG FORM

OBTAIN MAGNITUDE AND PHASE

PLOT THE RESULT

STOP

PROGRAM:

4. BAND STOP FILTER:


clc;
disp('input');
rp=input('enter the passband ripple:');
rs=input('enter the stopband ripple:');
wp=input('enter the passband frequency:');
ws=input('enter the stopband frequency:');
fs=input('enter the sampling frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs,'s');
wn=[w1 w2];
[b,a]=butter(n,wn,'stop','s');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel('gain in db');
xlabel('(a)normalised frequency');
title ('magnitude response');
subplot(2,1,2);
plot(om/pi,an);
xlabel('(b)normalised frequency');
ylabel('phase in radians');
title('phase response');

GRAPH:
1. LOWPASS FILTER:

2. HIGH PASS FILTER:

INPUT:

1. LOWPASS FILTER:
Enter the passband ripple04
Enter the stop band ripple80
Enter the passband frequency1400
Enter the stopband frequency4000
Enter the sampling frequency7000

2. HIGHPASS FILTER:
Enter the passband ripple09
Enter the stop band ripple50

Enter the passband frequency1780


Enter the stopband frequency3400
Enter the sampling frequency6000
3. BANDPASS FILTER:
enter the passband ripple:09
enter the stopband ripple:78
enter the passband frequency:1000
enter the stopband frequency:2000
enter the sampling frequency:8000
4. BANDSTOP FILTER:
enter the passband ripple:08
enter the stopband ripple:10
enter the passband frequency:1000
enter the stopband frequency:6000
enter the sampling frequency: 5400

GRAPH:
3. BANDPASS FILTER:

4. BANDSTOP FILTER:

RESULT:
Thus the Butterworth filters are executed and the output is
obtained.

EXP. NO:
DATE :

CHEBYCHEV FILTER

AIM:
To write and execute a MATLAB simulation program to design
the
following analog filters using Chebychev filters
1) Low pass filters
2) High pass filters
3) Band pass filters
4) Stop band filters

ALGORITHM:
STEP 1: Start the program.

STEP 2: Get the values of pass band and stop band ripple, pass
band and stop band
frequency and sampling frequency.
STEP 3: Calculate the order of the filter.
STEP 4: Use chebychev function to design various filter
STEP 5: Compute the frequency response and plot the graph.
STEP 6: Stop the program.

FLOW CHART:
1) LOW PASS FILTER:

START

READ rp, rs, ws, fs

READ ORDER OF THE


FILTER

USE CHEBYCHEV IIR TO DESIGN LPF

GET THE ANALOG FORM

OBTAIN MAGNITUDE AND PHASE

PLOT THE RESULT

STOP

PROGRAM:

1) LOW PASS FILTER:


clc;
disp('input');
rp=input('enter the pass band ripple:');
rs=input('enter the stop band ripple:');
wp=input('enter the pass band frequency:');
ws=input('enter the stop band frequency:');
fs=input('enter the sampling frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
disp('output');
[n,wn]=cheb1ord(w1,w2,rp,rs,'s');n
disp('3db cut off frequency');
disp('wn');
[b,a]=cheby1(n,rp,wn,'low');n
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));m
an=angle(h);an
subplot(2,1,1);
plot(om/pi,m);
xlabel('normalised frequency.....>');
ylabel('gain in db...>');
title('magnitude plot');
subplot(2,1,2);
plot(om/pi,an);
xlabel('normalised frequency....>');
ylabel('phase in radians....>');
title('phase plot');

FLOW CHART:
2) HIGH PASS FILTER:

START

READ rp, rs, ws, fs

READ ORDER OF THE


FILTER

USE CHEBYCHEV IIR TO DESIGN HPF

GET THE ANALOG FORM

OBTAIN MAGNITUDE AND PHASE

PLOT THE RESULT

STOP

PROGRAM:

2) HIGH PASS FILTER:


clc;
disp('input');
rp=input('enter the passband ripple:');
rs=input('enter the stopband ripple:');
wp=input('enter the passband frequency:');
ws=input('enter the stopband frequency:');
fs=input('enter the sampling frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
%wn=[w1,w2];
disp('output');
disp('order of sequence');
[n,wn]=cheb1ord(w1,w2,rp,rs,'s');n
disp('3db cutoff frequency');
disp(wn);
[b,a]=cheby1(n,rp,wn,'high');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));m
an=angle(h);an
subplot(2,1,1);
plot(om/pi,m);
xlabel('normalised frequency-->');
ylabel('gain in db-->');
title('magnitude plot');
subplot(2,1,2);
plot(om/pi,an);
xlabel('normalised frequency-->');
ylabel('phase in radians-->');
title('phase plot');
%subplot(2,1,2);
%plot(om\pi,an,'k');
%xlabel('normalised frequency->');
%ylabel('phase in radians----->');

%title('phase plot');

FLOW CHART:
3) BAND PASS FILTER:

START

READ rp, rs, ws, fs

READ ORDER OF THE


FILTER

USE CHEBYCHEV IIR TO DESIGN BPF

GET THE ANALOG FORM

OBTAIN MAGNITUDE AND PHASE

PLOT THE RESULT

STOP

PROGRAM:

3) BAND PASS FILTER:


clc;
disp('input');
rp=input('enter the pass band ripple:');
rs=input('enter the stop band ripple:');
wp=input('enter the pass band frequency:');
ws=input('enter the stop band frequency:');
fs=input('enter the sampling frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
disp('output');
disp('order of sequence');
[n,wn]=cheb1ord(w1,w2,rp,rs,'s');n
wn=[w1 w2];
disp('3db cut off frequency');
disp('wn');
[b,a]=cheby1(n,rp,wn,'bandpass');n
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));m
an=angle(h);an
subplot(2,1,1);
plot(om/pi,m);
xlabel('normalised frequency.....>');
ylabel('gain in db...>');
title('magnitude plot');
subplot(2,1,2);
plot(om/pi,an);
xlabel('normalised frequency....>');
ylabel('phase in radians....>');
title('phase plot');

FLOW CHART:
4) BAND STOP FILTER:

START

READ rp, rs, ws, fs

READ ORDER OF THE


FILTER

USE CHEBYCHEV IIR TO DESIGN BSF

GET THE ANALOG FORM

OBTAIN MAGNITUDE AND PHASE

PLOT THE RESULT

STOP

PROGRAM:

4) BAND STOP FILTER:


clc;
disp('input');
rp=input('enter the pass band ripple:');
rs=input('enter the stop band ripple:');
wp=input('enter the pass band frequency:');
ws=input('enter the stop band frequency:');
fs=input('enter the sampling frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
disp('output');
[n,wn]=cheb1ord(w1,w2,rp,rs);n
disp('3db cut off frequency');
disp('wn');
wn=[w1 w2];
[b,a]=cheby1(n,rp,wn,'stop');
w=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));m
an=angle(h);an
subplot(2,1,1);
plot(om/pi,m,'k');
xlabel('normalised frequency.....>');
ylabel('gain in db...>');
title('magnitude plot');
subplot(2,1,2);
plot(om/pi,an,'k');
xlabel('normalised frequency....>');
ylabel('phase in radians....>');
title('phase plot');

OUTPUT:
1) LOW PASS FILTER:

2) HIGH PASS FILTER:

INPUT:
1) LOW PASS FILTER:
enter the pass band ripple:0.09
enter the stop band ripple:50
enter the pass band frequency:3000
enter the stop band frequency:5000
enter the sampling frequency:9000
2) HIGH PASS FILTER:
enter the passband ripple:0.05
enter the stopband ripple:35
enter the passband frequency:1000
enter the stopband frequency:1400
enter the sampling frequency: 44000

3) BAND PASS FILTER:


enter the pass band ripple:0.003
enter the stop band ripple:35
enter the pass band frequency:2500
enter the stop band frequency:5000
enter the sampling frequency:12000
4) BAND STOP FILTER:
enter the pass band ripple:0.01
enter the stop band ripple:20
enter the pass band frequency:3000
enter the stop band frequency:3500
enter the sampling frequency:12000

OUTPUT:
3)

BAND PASS FILTER:

4) BAND STOP FILTER:

RESULT:
Thus the chebychev filters are executed and the output is
obtained.

EXP NO:
WINDOWING TECHNIQUES
DATE:

AIM:
To write and execute the MATLAB simulation program for the
following windowing techniques
1.Blackmann
2.Hamming and
3.Hanning.
ALGORITHM:
1. BLACKMANN:
STEP 1: Start the program.
STEP 2: Get the number of points (N).
STEP 3: Using the function Blackmann (N) design the
window for
frequency (0 : 0.01 : pi).

STEP 4: Window output.


STEP 5: Stop the program.
2.HAMMING:
STEP 1: Start the program.
STEP 2: Get the number of points (N).
Calculate the alpha value.
STEP 3: Using the function Hamming (N) design the
window for frequency
(0 : 0.01 : pi).
STEP 4: Window output.
STEP 5: Stop the program.
3.HANNING:
STEP 1: Start the program.
STEP 2: Get the number of points (N).
Calculate alpha value.
STEP 3: Using the function Hanning (N) design the
window for frequency
(0 : 0.01 : pi).
STEP 4: Window output.
STEP 5: Stop the program.

FLOWCHART:

1. BLACKMANN WINDOW:

START
GET THE VALUE OF N

CALCULATE USING THE WINDOW FUNCTION


BLACKMAN FOR N VALUES
CALCULATE THE FREQUENCY SAMPLE USING THE
FUNCTION FREQUENCY
PLOT THE OUTPUT

STOP

PROGRAM:

1.BLACKMANN WINDOW:
clc;
wi=3*pi;
N=25;
alpha=(N-1)/2;CPS=0.001;
n=0:1:N-1;
hd=sin(wi*(n-alpha-CPS)/(pi*(n-alpha)));
Wr=boxcar(N);
hn=hd*Wr;
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h));
hold on
wn=blackman(N);
hn=hd*wn;
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'...');grid;
title('blackmann window');
xlabel('normalised frequency....>');
ylabel('magnitude...>');
hold off

FLOWCHART:

2. HAMMING WINDOW:

START
GET THE VALUE OF N

CALCULATE USING THE WINDOW FUNCTION


HAMMING FOR N VALUES
CALCULATE THE FREQUENCY SAMPLE USING THE
FUNCTION FREQUENCY
PLOT THE OUTPUT

STOP

PROGRAM:
2.HAMMING WINDOW:
clc;
wi=0.5*pi;
N=25;
alpha=(N-1)/2;CPS=0.001;
n=0:1:N-1;
hd=sin(wi*(n-alpha+CPS)/(pi*(n-alpha+CPS)));
Wr=boxcar(N);
hn=hd*Wr;
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h));
hold on
wn=hamming(N);
hn=hd*wn;
w=0:0.01:pi;

h=freqz(hn,1,w);
plot(w/pi,abs(h),'...');grid;
title('hamming window');
xlabel('normalised frequency....>');
ylabel('magnitude...>');
hold off

FLOWCHART:

3. HANNING WINDOW:

START
GET THE VALUE OF N

CALCULATE USING THE WINDOW FUNCTION


HANNING FOR N VALUES
CALCULATE THE FREQUENCY SAMPLE USING THE
FUNCTION FREQUENCY
PLOT THE OUTPUT

STOP

PROGRAM:

3. HANNING WINDOW:
clc;
wi=5*pi;
N=25;
alpha=(N-1)/2;CPS=0.001;
n=0:1:N-1;
hd=sin(wi*(n-alpha+CPS)/(pi*(n-alpha+CPS)));
Wr=boxcar(N);
hn=hd*Wr;
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h));
hold on
wn=hanning(N);
hn=hd*wn;
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'...');grid;
title('hanning window');
xlabel('normalised frequency....>');
ylabel('magnitude...>');
hold off

OUTPUT:
1. BLACKMANN WINDOW:

2. HAMMING WINDOW:

3. HANNING WINDOW:

RESULT:
Thus the program for the different windowing technique is
written, executed and verified.

EXP NO:
STUDY OF TMS320C50 ARCHITECTURE
DATE:

AIM:
To study the architecture of TMS320C50.
DSP CHIP TMS320C50:
The TMS320C50 is a 16-bit fixed point digital signal processor
that combines the flexibility of a high speed controller with the
numerical capability of an array processor, thereby offering an
inexpensive alternative to multichip bit-slice processor. The highly
parelled architecture and efficient instruction set, provide speed and
flexibility capable of executing 10 MIPS. The TMS320C50 optimizes
speed by implementing function in hardware that other processors
implement through microcode or software. This hardware-intensive
approach provides the design engineer with processing power
previously unavailable on a single chip.
The TMS320C50 is the third generation digital signal processor
in the TMS320 family. Its powerful instruction set, inherent flexibility,
high speed number-crunching capabilities and innovative architecture
have made this high performance, cost effective processor the ideal
solution to many telecommunication, computer, commercial, industrial
and military applications.
KEY FEATURES OF TMS320C50:
The key features of digital signal processor TMS320C50 are:
35-/-50-ns single-cycle fixed-point instruction execution
time (28.6/20 MIPS)
Upward source-code compatible with all C1X and C2X
devices.
RAM- based memory operation(C50)
9K x 16-bit single- cycle on-chip program/data RAM (C50)
2K x 16-bit single- cycle on- chip boot ROM (C50)
1056 x 16-bit dual-access on-chip data RAM.
224K x 16-bit maximum addressable external memory

space (64K program, 64K data,64K I/O and 32K global).


32-bit arithmetic logic unit (ALC), 32-bit accumulator
(ACC) and 32-bit accumulator buffer (ACCB).
16-bit parallel logic unit (PLU)
16 x 16-bit parallel multiplier with a 32-bit product
capability.
Single- cycle multiply/accumulate instructions.
8 auxiliary registers with a dedicated auxiliary register
arithmetic unit for indirect addressing.
11 context- switch register (shadow register) for storing
strategic CPU- controlled registers during an interrupt
service routine.
8-level hardware stack
0-to 16-bit left and right data barrel shifters and a 64-bit incremental
data

shifter.
Two indirectly addressed circular buffer for circular
addressing.
Single- instruction repeat and block repeat operations for
program code.
Block memory move instructions for better program/data
management.
Full-duplex synchronous serial port for direct
communication between C5X and another serial device.

Time-division multiple-access (TDM) serial port


Interval timer with period, control and counter registers for
software stop, start and reset.
64K parallel I/O port, 16 of which are memory mapped.
16 software programmable wait-state generator for
program, data and I/O memory spaces.
ARCHITECTURE:
The TMS320C50 is utilizes a modified Harvard architecture for
speed and flexibility. In a strict Harvard architecture, program and data
memory are in two separate spaces, permitting a full overlap of
instruction fetch and execution. The TMS320 familys modification of
the Harvard architecture allows transfer between program and data
spaces, thereby increasing the flexibility of the device. This
modification permits coefficients stored program memory to be read
into the data RAM, eliminating the need for a separate coefficient
ROM. It also makes available immediate instructions and subroutines
based on computed values.
32-BIT ACCUMULATOR:
The TMS320C50 contains a 32-bit ALU and accumulator for
support of double-precision twos complement arithmetic. The ALU is
a general purpose arithmetic unit that operates on 16-bit words taken
from the data RAM or derived from immediate instruction. In addition
to the usual arithmetic instructions ALU can performs Boolean
operations, providing the bit manipulation ability required of a high
speed controller. The accumulator stores the output from ALU and is
often an input to ALU. It is 32-bit long. The accumulator is divided
into high order word(bits 31-16) and low order(bits15-0). Instructions
are provided for storing and loading the high and lower order
accumulator words to memory.
16 x 16-BIT PARALLEL MULTIPLIER:
The multiplier performs a 16 x 16-bit 2s complement
multiplication with a 32-bit resulting in a single instruction cycle. The

multiplier consists of three units: T-registers, P-registers and multiplier


array. The 16-bit T-register temporarily stores the multiplicand and the
P-register stores the 32-bit product. Multiplier values either come from
the data memory or are derived immediately from the MPY (multiply
immediate) instruction word. The fast on-chip multiplier allows the
device to perform fundamental operations such as convolution,
correlation and filtering. Two multiply/accumulate instructions in the
instruction set fully utilizes the computational bandwidth of the
multiplier, allowing both operands to be processed simultaneously.
SHIFTERS:
A 16-bit scaling shifter is available at the accumulator input, this
shifter produces a left shift of 0 to 16-bit on the input data to
accumulator.
TMS320C50 also contains a shifter at the accumulator output.
This shifter provides a left shift of 0 to 7, on the data from either the
ACCH or ACCL register.
In addition one shifter at the output of P-register , can shift the
product by 1 or 4-bits left or 6-bits right, before transferring the
product to accumulator.
DATA AND PROGRAM MEMORY:
Since the TMS320C50 uses Harvard architecture, data and
program memory reside in two separate spaces. Additionally
TMS320C50 has one more memory space called I/O memory space.
The total memory capacity of TMS320C50 is 64KW each of Program,
Data and I/O memory. The 64KW of data memory is divided into 512
pages with each page containing 128 words. Only one page can be
active at a time. One data page selection is done by setting data page
pointer. TMS320C50 has 1056 words of dual access on chip data
memory is divided as three blocks B0, B1 & B2, of which B0 can be
configured as program or data RAM.
Out of the 64KW of total program memory, TMS320C50 has 2K

words of on-chip program ROM.


The TMS320C50 offers two modes of operation defined by the
state of the MC/MP pin: the microprocessor mode (MC/MP=1) or the
microprocessor mode (MC/MP=0). In the microprocessor mode, on
chip ROM is mapped into the memory into the memory space with up
to 2K words of memory are external.
INTERRUPTS AND SUBROUTINES:
The TMS320C50 has three external maskable user interrupts
available for external devices that interrupt the processor.
The TMS320C50 contains a eight-level hardware stack for saving
the contents of the program counter during interrupts and subroutine
calls. Instructions are available for saving the devices complete
context. PUSH and POP instructions permit a level of nesting restricted
only by the amount of available RAM.
SERIAL PORT:
A full-duplex on chip serial port communication with serial
devices such as codecs, serial A/D converters and other serial systems.
The interface signals are compatible with codecs and many other serial
devices with a minimum of external hardware.
INPUT AND OUTPUT:
The 16-bit parallel data bus can be utilized to perform I/O
function in two cycles. The I/O ports are addressed by the four LSBs
on the address lines, allowing 16 input and 16 output ports. In addition,
a polling input for bit test and jump operations (BIO) and three
interrupt pins(INT0-INT2) have been incorporated for multitasking.

RESULT: Thus the architecture of TMS320C50 is studied.


SINE WAVE GENERATION
;
*********************************************************
*******************
; PROGRAM DESCRIPTION:
;~~~~~~~~~~~~~~~~~~~
;
The sine table values are stored in the program memory.
Accumulator A
; is initially loaded with the starting address of the sine table. The
; read an instruction, reads the content of the address which is stored in
acc.
; That data is sent to the dac and the acc. content is incremented to
point

; to the next value in the sin table.


DATA
.SET 0H
ADD
.SET 1H
TABLE
.SET 200H
.mmregs
.text
START:
STM #140H,ST0
;initialize the data page pointer
RSBX CPL
;make the processor to work using DP
NOP
NOP
NOP
NOP
REP:
LD
#TABLE,A
;Load the address first value of the sine
;table to the accumulator
STM #372,AR1
;no. of sine table values
LOOP:
READA DATA
;read the sine table value
PORTW DATA,04H
;send it to the dac
ADD #1H,A
;increment the sine table address which
;is in the accumulator
BANZ LOOP,*AR1;repeat the loop until all 372 values has
;been sent
B
REP
;repeat the above
Note:
~~~~
1. Download the program sin.asc in the prog. memory address 0h
2. Download the sine table values which is in the file datsine.asc in the
program memory address 200h using PI 200h command in the
XTALK.exe
3. Execute the program using GO 0 command.

WORD

03915H
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD

0373eH
03535H
032faH
03091H
02dfbH
02b3aH
02852H
02544H
02214H
01ec5H
01b5aH
017d5H
0143aH
0108dH
0cd0H
0908H
0537H
0161H
0fd8bH
0f9b7H
0f5e8H
0f223H
0ee6aH
0eac1H
0e72cH
0e3aeH
0e04aH
0dd04H
0d9ddH
0d6daH
0d3fcH
0d147H
0cebeH
0cc61H
0ca34H

.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD

0c839H
0c671H
0c4deH
0c382H
0c25dH
0c171H
0c0bfH
0c047H
0c009H
0c007H
0c040H
0c0b3H
0c161H
0c248H
0c368H
0c4c0H
0c64fH
0c813H
0ca0aH
0cc33H
0ce8cH
0d112H
0d3c4H
0d69eH
0d99eH
0dcc2H
0e006H
0e368H
0e6e4H
0ea78H
0ee1fH
0f1d6H
0f59bH
0f969H
0fd3dH
0113H

.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD

04e9H
08baH
0c83H
01041H
013f0H
0178cH
01b13H
01e80H
021d2H
02505H
02815H
02b00H
02dc4H
0305eH
032cbH
03509H
03716H
038f1H
03a97H
03c07H
03d40H
03e41H
03f08H
03f95H
03fe7H
03fffH
03fdcH
03f7dH
03ee5H
03e12H
03d06H
03bc2H
03a47H
03896H
036b1H
0349aH

.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD

03252H
02fdcH
02d39H
02a6dH
0277aH
02463H
0212aH
01dd3H
01a60H
016d4H
01334H
0f82H
0bc2H
07f7H
0424H
04eH
0fc78H
0f8a5H
0f4d8H
0f116H
0ed62H
0e9beH
0e62fH
0e2b8H
0df5cH
0dc1eH
0d901H
0d608H
0d336H
0d08dH
0ce0fH
0cbc0H
0c9a1H
0c7b4H
0c5fbH
0c477H

.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD

0c32aH
0c215H
0c139H
0c097H
0c030H
0c003H
0c011H
0c05aH
0c0deH
0c19cH
0c293H
0c3c3H
0c52aH
0c6c8H
0c89bH
0caa0H
0ccd7H
0cf3cH
0d1cfH
0d48cH
0d772H
0da7cH
0dda9H
0e0f6H
0e460H
0e7e3H
0eb7cH
0ef28H
0f2e3H
0f6abH
0fa7bH
0fe51H
0226H
05fbH
09cbH
0d91H

.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD

0114bH
014f5H
0188bH
01c0bH
01f72H
022bbH
025e4H
028eaH
02bcbH
02e83H
03110H
03371H
035a1H
037a1H
0396dH
03b04H
03c65H
03d8eH
03e7eH
03f35H
03fb2H
03ff4H
03ffbH
03fc7H
03f58H
03eafH
03dcdH
03cb1H
03b5dH
039d3H
03813H
03620H
033fbH
031a6H
02f23H
02c75H

.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD

0299eH
026a0H
0237fH
0203dH
01cdeH
01964H
015d2H
0122cH
0e76H
0ab2H
06e5H
0311H
0ff3bH
0fb65H
0f794H
0f3caH
0f00bH
0ec5bH
0e8bdH
0e534H
0e1c4H
0de70H
0db3bH
0d828H
0d53aH
0d273H
0cfd6H
0cd65H
0cb23H
0c912H
0c733H
0c588H
0c414H
0c2d7H
0c1d2H
0c106H

.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD

0c074H
0c01dH
0c001H
0c01fH
0c079H
0c10dH
0c1dbH
0c2e3H
0c422H
0c599H
0c746H
0c926H
0cb3aH
0cd7eH
0cff1H
0d28fH
0d558H
0d848H
0db5dH
0de93H
0e1e8H
0e559H
0e8e3H
0ec81H
0f032H
0f3f1H
0f7bcH
0fb8eH
0ff64H
033aH
070dH
0adbH
0e9eH
01253H
015f8H
01989H

.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD

01d02H
02060H
023a1H
026c1H
029bcH
02c92H
02f3eH
031bfH
03413H
03636H
03827H
039e4H
03b6cH
03cbeH
03dd7H
03eb8H
03f5eH
03fcaH
03ffcH
03ff2H
03faeH
03f2fH
03e76H
03d83H
03c57H
03af4H
0395bH
0378cH
0358bH
03358H
030f6H
02e67H
02badH
028cbH
025c3H
02299H

.WORD
.WORD

01f4eH
01be7H

*********************************************************
****************
;
SQUARE WAVE GENERATION
;
*********************************************************
*******************
DATA
.SET 0H
.mmregs
.text
START:
STM #140H,ST0
;initialize the data page pointer
RSBX CPL
;make the processor to work using DP
NOP
NOP
NOP
NOP
REP:
ST #0H,DATA
;send 0h to the dac
CALL DELAY
;delay for some time
ST #0FFFH,DATA ;send 0fffh to the dac

CALL DELAY
;delay for some time
B
REP
;repeat the same
DELAY:
STM #0FFFH,AR1
DEL1:
PORTW DATA,04H
BANZ DEL1,*AR1RET

TRIANGULAR WAVE GENERATION


;
*********************************************************
*******************
DATA
.SET 0H
.mmregs
.text
START:
STM #140H,ST0
;initialize the data page pointer
RSBX CPL
;make the processor to work using DP
NOP
NOP
NOP
NOP
REP:
ST #0H,DATA
;initialize the value as 0h
INC:
LD
DATA,A
;increment the value
ADD #1H,A
STL A,DATA
PORTW DATA,04H
;send the value to the dac
CMPM DATA,#0FFFH ;repeat the loop until the value
becomes 0fffh
BC
INC,NTC

DEC:
LD
DATA,A
;decrement the value
SUB #1H,A
STL A,DATA
PORTW DATA,04H
;send the value to the dac
CMPM DATA,#0H
BC
DEC,NTC
;repeat the loop until the value becomes 0h
B
REP
;repeat the above

*********************************************************
*******
;
SAWTOOTH WAVE GENERATION
;
*********************************************************
*******************
DATA
.SET 0H
.mmregs
.text
START:
STM #140H,ST0
;initialize the data page pointer
RSBX CPL
;make the processor to work using DP
NOP
NOP
NOP
NOP
REP:
ST #0H,DATA
;initialize the value as 0h
INC:
LD
DATA,A
ADD #1H,A
;increment the value
STL A,DATA
PORTW DATA,04H
;send the value to the dac

CMPM DATA,#0FFFH ;repeat the loop until the value


becomes 0fffh
BC
INC,NTC
B
REP
;repeat the above

CONVOLUTION FOR FOUR INPUTS


;
*********************************************************
****
.mmregs
.text
START:
STM #40H,ST0
RSBX CPL
RSBX FRCT
NOP
NOP
NOP
NOP
STM #0A000H,AR0 ;AR0 for X(n)
STM #00100H,AR1 ;AR1 for H(n)
STM #0A020H,AR2 ;AR2 for temporary location
;temporary storage locations are initially zero
LD #0H,A
RPT #4H
STL A,*AR2+
STM #0A004H,AR0 ;padding of zeros after x(n)
LD #0H,A
RPT #5H

STL A,*AR0+
STM #0A000H,AR0
STM #0A020H,AR2
STM #0A030H,AR3 ;location for storing output Y(n)
STM #6H,BRC
;counter for number of Y(n)
RPTB CONV
;start of the program
LD *AR0+,A
STM #0A020H,AR2
STL A,*AR2
STM #0A023H,AR2
LD #0H,A
RPT #3H
MACD *AR2-,0100H,A
CONV
STL A,*AR3+
HLT: B HLT

;
*********************************************************
*******************
;INPUT:
X(n) DATA MEMORY
;
;
;
;

0A000
0A001
0A002
0A003

;INPUT:

0001H
0003H
0001H
0003H
H(n) PROGRAM MEMORY

;
;
;
;

00100
00101
00102
00103

0000H
0001H
0002H
0001H

;h(n)

;OUTPUT
Y(n) DATA MEMORY
;
0A030 0001
;
0A031 0005
;
0A032 0008
;
0A034 0008
;
0A035 0007
;
0A036 0003
;
*********************************************************
*******************

IMPLEMENTATION OF FIR FILTERS


;
*********************************************************
*******************
;
LOW-PASS FILTER
;
*********************************************************
*******************
;Filter type
:
FIR-LPF
;Window type
:
Rectangular window
;Sampling frequency :
41khz
;Cut-off frequency
:
4khz
;No. of taps
:
52
;
.mmregs
.text
START:
STM #01h,ST0
RSBX CPL
RSBX FRCT
NOP
NOP
STM #150H,AR1
LD
#0H,A
RPT #34H
STL A,*AR1+
LOOP:
PORTR 06,0
CHK_BUSY:
; PORTR 07,0
; BITF 0,#20H
; BC
CHK_BUSY,TC

PORTR 04,0
LD
0,A
AND #0FFFH,A
XOR #0800H,A
SUB #800H,A
STM #150H,AR1
STL A,*AR1
STM #183H,AR2
LD
#0H,A
RPT #33H
MACD *AR2-,TABLE,A
STH A,1,0H
LD
0H,A
ADD #800H,A
STL A,1H
PORTW 1H,04H
B
LOOP
;fs = 41khz ; fc = 4khz ; N = 52
TABLE:
.word 01FH
.word 010EH
.word 01ABH
.word 01B4H
.word 0117H
.word 0H
.word 0FECDH
.word 0FDEEH
.word 0FDC2H
.word 0FE6EH
.word 0FFCDH
.word 016FH
.word 02C0H
.word 0333H
.word 0274H
.word 097H
.word 0FE19H

.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word

0FBCBH
0FA9BH
0FB53H
0FE50H
0362H
09C5H
01048H
01599H
01895H
01895H
01599H
01048H
09C5H
0362H
0FE50H
0FB53H
0FA9BH
0FBCBH
0FE19H
097H
0274H
0333H
02C0H
016FH
0FFCDH
0FE6EH
0FDC2H
0FDEEH
0FECDH
0H
0117H
01B4H
01ABH
010EH
01FH

;
*********************************************************
*****************
;
HIGH PASS FIR FILTER
;
*********************************************************
*****************
;Sampling freq
: 43khz
;Cut-off freq
: 2khz
;N
: 52
;Filter type
: High pass filter
;Window type
: Rectangular
;Program Description:
;1. Make all the x(n) zero initially
;2. Read the data from the adc.
;3. Store the adc data in x(0)
;4. Make the pointer to point the x(n_end)
;5. Perform the convolution of x(n) and the coefficients h(n) using
; MACD instruction.
;6. Send the convolution output to the dac
;7. Repeat from step 2.
.mmregs
.text
START:
STM #01h,ST0
RSBX CPL
RSBX FRCT
NOP
NOP

;intialize the data page pointer


;Make the processor to work using DP
;reset the fractional mode bit

;*****loop to make all x(n) zero initially*****


STM #150H,AR1
;initialize ar1 to point to x(n)
LD
#0H,A
;make acc zero
RPT #34H
STL A,*AR1+
;make all x(n) zero
;*****to read the adc data and store it in x(0)*****
LOOP:
PORTR 06,0
;start of conversion
CHK_BUSY:
; PORTR 07,0
;check for busy
; BITF 0,#20H
; BC
CHK_BUSY,TC
PORTR 04,0
;read the adc data
LD
0,A
AND #0FFFH,A
;AND adc data with 0fffh for 12 bit adc
XOR #0800H,A
;recorrect the 2's complement adc data
SUB #800H,A
;remove the dc shift
STM #150H,AR1
;initialize ar1 with x(0)
STL A,*AR1
;store adc data in x(0)
STM #183H,AR2
;initialize ar2 with x(n_end)
;*****start of convolution*****
LD
#0H,A
;sum is 0 initially
RPT #33H
MACD *AR2-,TABLE,A ;convolution process
STH A,1,0H
LD
0H,A
ADD #800H,A
;add the dc shift to the convolution output
STL A,1H
PORTW 1H,04H
;send the output to the dac
B
LOOP
TABLE:
.word
.word
.word
.word

0FCEFH
62H
0FD50H
14AH

.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word

0FE1BH
28FH
0FF11H
3E5H
0FFD1H
4ECH
0FFF5H
54FH
0FF28H
4DAH
0FD38H
398H
0FA2EH
1DDH
0F627H
55H
0F131H
4BH
0EA6DH
568H
0D950H
459EH
459EH
0D950H
568H
0EA6DH
4BH
0F131H
55H
0F627H
1DDH
0FA2EH
398H
0FD38H
4DAH
0FF28H

.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word

54FH
0FFF5H
4ECH
0FFD1H
3E5H
0FF11H
28FH
0FE1BH
14AH
0FD50H
62H
0FCEFH

;
*********************************************************
*****************
;
BAND PASS FIR FILTER
;
*********************************************************
*****************
;Sampling freq
: 43khz
;Cut-off freq1
: 2khz
;Cut-off freq2
: 4khz
;N
: 52
;Filter type
: Band pass filter
;Window type
: Rectangular
;Program Description:
;1. Make all the x(n) zero initially
;2. Read the data from the adc.
;3. Store the adc data in x(0)
;4. Make the pointer to point the x(n_end)
;5. Perform the convolution of x(n) and the coefficients h(n) using
; MACD instruction.
;6. Send the convolution output to the dac
;7. Repeat from step 2.
.mmregs
.text
START:
STM #01h,ST0

;intialize the data page pointer

RSBX CPL
;Make the processor to work using DP
RSBX FRCT
;reset the fractional mode bit
NOP
NOP
;*****loop to make all x(n) zero initially*****
STM #150H,AR1
;initialize ar1 to point to x(n)
LD
#0H,A
;make acc zero
RPT #34H
STL A,*AR1+
;make all x(n) zero
;*****to read the adc data and store it in x(0)*****
LOOP:
PORTR 06,0
;start of conversion
CHK_BUSY:
;PORTR 07,0
;check for busy
; BITF 0,#20H
; BC
CHK_BUSY,TC
PORTR 04,0
;read the adc data
LD
0,A
AND #0FFFH,A
;AND adc data with 0fffh for 12 bit adc
XOR #0800H,A
;recorrect the 2's complement adc data
SUB #800H,A
;remove the dc shift
STM #150H,AR1
;initialize ar1 with x(0)
STL A,*AR1
;store adc data in x(0)
STM #183H,AR2
;initialize ar2 with x(n_end)
;*****start of convolution*****
LD
#0H,A
;sum is 0 initially
RPT #33H
MACD *AR2-,TABLE,A ;convolution process
STH A,1,0H
LD
0H,A
ADD #800H,A
;add the dc shift to the convolution output
STL A,1H
PORTW 1H,04H
;send the output to the dac
B
LOOP
TABLE:

.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word

208H
257H
218H
143H
0H
0FE9EH
0FD7AH
0FCE7H
0FD08H
0FDD1H
0FEECH
0FFE4H
3DH
0FFA1H
0FDFCH
0FB8FH
0F8ECH
0F6D4H
0F608H
0F713H
0FA21H
0FEE6H
4A7H
0A60H
0EF8H
1187H
1187H
0EF8H
0A60H
4A7H
0FEE6H
0FA21H
0F713H
0F608H
0F6D4H
0F8ECH

.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word

0FB8FH
0FDFCH
0FFA1H
3DH
0FFE4H
0FEECH
0FDD1H
0FD08H
0FCE7H
0FD7AH
0FE9EH
0H
143H
218H
257H
208H

IMPLEMENTATION OF IIR FILTERS


;Filter type
: Low pass filter
;Filter order
:2
;Filter design type : Butterworth
;Pass band attenuation : 3db
;First corner freq
: 0.2
;Second corner freq : 0.24
;Sampling freq
: 50Khz
;Cut-off freq
: 10Khz
;
;FROM PCDSP COEFFICIENTS
;
XN
.SET 0H
XNM1
.SET 1H
XNM2
.SET 2H
YN
.SET 3H
YNM1
.SET 4H
YNM2
.SET 5H
XN1
.SET 6H
XN1M1
.SET 7H
XN1M2
.SET 8H

YN1
.SET 9H
YN1M1
.SET 0AH
YN1M2
.SET 0BH
TEMP
.SET 0CH
A10
.SET 0100H
A11
.SET 0FFA2H
A12
.SET 0032H
B10
.SET 0100H
B11
.SET 0200H
B12
.SET 0100H
.mmregs
.text
START:
STM #40H,PMST
RSBX CPL
STM #01H,ST0
RSBX FRCT
NOP
NOP
NOP
;initialize xn,x(n-1),x(n-2),yn,y(n-1),y(n-2)
ST #0H,XN
ST #0H,XNM1
ST #0H,XNM2
ST #0H,YN
ST #0H,YNM1
ST #0H,YNM2
ST #0H,XN1
ST #0H,XN1M1
ST #0H,XN1M2
ST #0H,YN1
ST #0H,YN1M1
ST #0H,YN1M2
REPEAT:
;to read data from ADC
PORTR 06,20
;start of conversion

CHK_BUSY:
;check status
; PORTR 07,20
; BITF 20,#20H
; BC
CHK_BUSY,TC
PORTR 04,20
;read ADC data
LD
20,A
AND #0FFFH,A
XOR #0800H,A
;to correct 2's complement
SUB #800H,A
STL A,XN
;xn
STL A,TEMP
;
LD
#0H,B
;sum = B = 0
LD
#B10,A
;b0 = T
STLM A,T
MPY XN,A
;b0*xn = A
SFTL A,-8
ADD A,B
;b0*xn =B
LD
#B11,A
STLM A,T
MPY XNM1,A
SFTL A,-8
ADD A,B

;b0 = T

LD
#B12,A
STLM A,T
MPY XNM2,A
SFTL A,-8
ADD A,B

;b0 = T

LD
#A11,A
STLM A,T
MPY YNM1,A
SFTL A,-8
SUB A,B

;b0 = T

;b0*xn = A
;b0*xn =B

;b0*xn = A
;b0*xn =B

;b0*xn = A
;b0*xn =B

LD
#A12,A
STLM A,T
MPY YNM2,A
SFTL A,-8
SUB A,B
STL B,YN
STL B,XN1
LD
STL
LD
STL
LD
STL
LD
STL

YNM1,A
A,YNM2
YN,A
A,YNM1
XNM1,A
A,XNM2
XN,A
A,XNM1

LD YN,A
ADD #800H,A
STL A,YN
PORTW YN,04H
B
REPEAT

;b0 = T
;b0*xn = A
;b0*xn =B

;Filter type
: High pass filter
;Filter order
:2
;Filter design type : Butterworth
;Pass band attenuation : 3db
;First corner freq
: 0.2
;Second corner freq : 0.24
;Sampling freq
: 50Khz
;Cut-off freq
: 10Khz
;
;FROM PCDSP COEFFICIENTS
;
XN
.SET 0H
XNM1
.SET 1H
XNM2
.SET 2H
YN
.SET 3H
YNM1
.SET 4H
YNM2
.SET 5H
XN1
.SET 6H
XN1M1
.SET 7H
XN1M2
.SET 8H
YN1
.SET 9H
TEMP
.SET 0CH
YN1M1
.SET 0AH
YN1M2
.SET 0BH

A10
.SET 0100H
A11
.SET 0FFEDH
A12
.SET 002CH
B10
.SET 0100H
B11
.SET 0FE00H
B12
.SET 0100H
START:
STM #40H,PMST
RSBX CPL
STM #01H,ST0
RSBX FRCT
NOP
NOP
NOP
;initialize xn,x(n-1),x(n-2),yn,y(n-1),y(n-2)
ST #0H,XN
ST #0H,XNM1
ST #0H,XNM2
ST #0H,YN
ST #0H,YNM1
ST #0H,YNM2
ST #0H,XN1
ST #0H,XN1M1
ST #0H,XN1M2
ST #0H,YN1
ST #0H,YN1M1
ST #0H,YN1M2
REPEAT:
;to read data from ADC
PORTR 06,20
;start of conversion
CHK_BUSY:
;check status
; PORTR 07,20
; BITF 20,#20H
; BC
CHK_BUSY,TC
PORTR 04,20
;read ADC data

LD
20,A
AND #0FFFH,A
XOR #0800H,A
SUB #800H,A
STL A,XN
STL A,TEMP

;to correct 2's complement


;xn

;
LD
#0H,B
LD
#B10,A
STLM A,T
MPY XN,A
SFTL A,-8
ADD A,B

;sum = B = 0
;b0 = T

LD
#B11,A
STLM A,T
MPY XNM1,A
SFTL A,-8
ADD A,B

;b0 = T

LD
#B12,A
STLM A,T
MPY XNM2,A
SFTL A,-8
ADD A,B

;b0 = T

LD
#A11,A
STLM A,T
MPY YNM1,A
SFTL A,-8
SUB A,B

;b0 = T

LD
#A12,A
STLM A,T
MPY YNM2,A
SFTL A,-8

;b0 = T

;b0*xn = A
;b0*xn =B

;b0*xn = A
;b0*xn =B

;b0*xn = A
;b0*xn =B

;b0*xn = A
;b0*xn =B

;b0*xn = A

SUB
STL
STL

A,B
B,YN
B,XN1

LD
STL
LD
STL
LD
STL
LD
STL

YNM1,A
A,YNM2
YN,A
A,YNM1
XNM1,A
A,XNM2
XN,A
A,XNM1

LD YN,A
ADD #800H,A
STL A,YN
PORTW YN,04H
B
REPEAT

;b0*xn =B

;Filter type
: Band pass filter
;Filter order
:2
;Filter design type : Chebyshev-I
;Pass band attenuation : 3db
;Edge frequencies:
;f1
: 0.1
;f2
: 0.125
;f3
: 0.15
;f4
: 0.175
;Sampling freq
: 50Khz
;Cut-off freq1
: 5Khz
;Cut-off freq2
: 7.5Khz
;
;FROM PCDSP COEFFICIENTS
;
XN
.SET 0H
XNM1
.SET 1H
XNM2
.SET 2H
YN
.SET 3H
YNM1
.SET 4H
YNM2
.SET 5H
XN1
.SET 6H
XN1M1
.SET 7H
XN1M2
.SET 8H
YN1
.SET 9H

YN1M1
.SET 0AH
YN1M2
.SET 0BH
TEMP
.SET 0CH
A10
.SET 0100H
A11
.SET 0FECBH
A12
.SET 00DAH
B10
.SET 0100H
B11
.SET 0000H
B12
.SET 0FF00H
.mmregs
.text
START:
STM #40H,PMST
RSBX CPL
STM #01H,ST0
RSBX FRCT
NOP
NOP
NOP
;initialize xn,x(n-1),x(n-2),yn,y(n-1),y(n-2)
ST #0H,XN
ST #0H,XNM1
ST #0H,XNM2
ST #0H,YN
ST #0H,YNM1
ST #0H,YNM2
ST #0H,XN1
ST #0H,XN1M1
ST #0H,XN1M2
ST #0H,YN1
ST #0H,YN1M1
ST #0H,YN1M2
REPEAT:
;to read data from ADC
PORTR 06,20
;start of conversion
CHK_BUSY:
;check status

; PORTR 07,20
; BITF 20,#20H
; BC
CHK_BUSY,TC
PORTR 04,20
;read ADC data
LD
20,A
AND #0FFFH,A
XOR #0800H,A
;to correct 2's complement
SUB #800H,A
STL A,XN
;xn
STL A,TEMP
;
LD
#0H,B
LD
#B10,A
STLM A,T
MPY XN,A
SFTL A,-8
ADD A,B

;sum = B = 0
;b0 = T

LD
#B11,A
STLM A,T
MPY XNM1,A
SFTL A,-8
ADD A,B

;b0 = T

LD
#B12,A
STLM A,T
MPY XNM2,A
SFTL A,-8
ADD A,B

;b0 = T

LD
#A11,A
STLM A,T
MPY YNM1,A
SFTL A,-8
SUB A,B

;b0 = T

;b0*xn = A
;b0*xn =B

;b0*xn = A
;b0*xn =B

;b0*xn = A
;b0*xn =B

;b0*xn = A
;b0*xn =B

LD
#A12,A
STLM A,T
MPY YNM2,A
SFTL A,-8
SUB A,B
STL B,YN
STL B,XN1
LD
STL
LD
STL
LD
STL
LD
STL

YNM1,A
A,YNM2
YN,A
A,YNM1
XNM1,A
A,XNM2
XN,A
A,XNM1

LD YN,A
ADD #800H,A
STL A,YN
PORTW YN,04H
B
REPEAT

;b0 = T
;b0*xn = A
;b0*xn =B

*********************************************************
*****************
;
8-POINT FFT
;
*********************************************************
******************
INPUT
.SET
0A200H
REV
.SET
0A300H
INC
.SET
0A400H
TWIDC
.SET
0A500H
TWIDS
.SET
0A550H
BFY
.SET
0H
BFYC
.SET
1H
DNS
.SET
2H
DNSC
.SET
3H
GRP
.SET
4H
GRPC
.SET
5H
STG
.SET
6H
STGC
.SET
7H
K
.SET
8H
INCTF
.SET
9H
AX
.SET
0AH
BX
.SET
0BH
CX
.SET
0CH
DX
.SET
0DH

ACMBD
.SET
0EH
ADPBC
.SET
0FH
AR10
.SET
10H
AR11
.SET
11H
AR12
.SET
12H
AR13
.SET
13H
AR14
.SET
14H
ATEMP
.SET
15H
BTEMP
.SET
16H
B3
.SET
0F000H B2
.SET
00F0H B0
.SET
30H TXD
.SET
31H
.mmregs
.text
START:
;
STM #40H,PMST
RSBX CPL
STM #140H,ST0
RSBX FRCT
NOP
NOP
NOP
NOP
CALL BIT_REV
CALL INCLUDE
ST #1H,BFY
ST #4H,GRP
ST #2H,DNS
ST #3H,STG
LD
STG,A
SUB #1H,A
STL A,STGC
STM #TWIDC,AR0
RPT #3H
MVPD TABCOS,*AR0+

.SET
0F00H B1
000FH DATA
.SET

STM #TWIDS,AR0
RPT #3H
MVPD TABSIN,*AR0+
STM #2H,AR5
;AR5 = STAGE LOOP
STGLOP:
ST #0H,K
LD
BFY,A
SUB #1H,A
STL A,BFYC
LD
GRP,A
SUB #1H,A
STL A,GRPC
LD
DNS,A
STLM A,AR0
SUB #1H,A
STL A,DNSC
LD
DNSC,A
LD
GRP,A
CMPM GRP,#4H
;N/2=8/2=4H
BC
NO_CHG,NTC
LD
#0H,A
NO_CHG:
STL A,INCTF
LD
GRPC,A
STLM A,AR3
;AR3 = GROUP LOOP
STM #INC,AR1
GRPLOP:
ST #0H,K
;k is initially 0 in all groups
LD
BFYC,A
STLM A,AR4
;AR4 = BFLY LOOP
BFYLOP:
LD
*AR1+0,A
CALL MUL
LD
DNS,A
STLM A,AR0

LD
*AR1-0,A
CALL ADDSUB
LD
K,A
ADD INCTF,A
STL A,K
BANZ BFYLOP,*AR4LD
DNS,A
STLM A,AR0
LD
*AR1+0,A
BANZ GRPLOP,*AR3MPY BFY,#2,A
;BFY * 2 = BFY
STL A,BFY
MPY DNS,#2,A
;DNS * 2 = DNS
STL A,DNS
STLM A,AR0
LD
GRP,A
STL A,-1,GRP
;GRP / 2 = GRP
BANZ STGLOP,*AR5hlt: B hlt
MUL:
STM #TWIDC,AR2
LD
K,A
STLM A,AR0
NOP
NOP
LD
*AR2+0,A
LD
*AR2,A
STL A,CX
STM #TWIDS,AR2
LD
K,A
STLM A,AR0
LD
*AR2+0,A
LD
*AR2,A
STL A,DX
LD
*AR1+,A
STL A,AX

LD
*AR1-,A
STL A,BX
LD AX,A
STLM A,T
MPY CX,A
;A*C
LD
BX,B
STLM B,T
MPY DX,B
;B*D
SUB B,A
;AC-BD -> A
STL A,-8,ACMBD
LD AX,A
STLM A,T
MPY DX,A
;A*D
LD
BX,B
STLM B,T
MPY CX,B
;B*C
ADD A,B
;AD+BC -> B
STL B,-8,ADPBC
LD ACMBD,A
STL A,*AR1+
LD ADPBC,A
STL A,*AR1LD
DNS,A
STLM A,AR0
RET
ADDSUB:
LD
STL
LD
STL
ADD
STL
LD
SUB
LD

*AR1+0,A
A,ATEMP
*AR1-0,B
B,BTEMP
A,B
B,*AR1
ATEMP,A
BTEMP,A
*AR1+0,B

STL A,*AR1-0
LD
*AR1+,A
LD
*AR1+0,A
STL A,ATEMP
LD
*AR1-0,B
STL B,BTEMP
ADD A,B
STL B,*AR1
LD ATEMP,A
SUB BTEMP,A
LD
*AR1+0,B
STL A,*AR1-0
LD
*AR1-,A
LD
*+AR1(2),A
LDM AR1,A
STL A,AR10
RET
BIT_REV:
STM #INPUT,AR4
STM #REV,AR5
STM #4H,AR0
;N/2
STM #7H,BRC
;N-1
RPTB REPREV
LD
*AR4+0B,A
REPREV: STL A,*AR5+
RET
INCLUDE:
STM #REV,AR1
STM #INC,AR2
STM #7H,BRC
RPTB REPINC
LD
*AR1+,A
STL A,*AR2+
LD
#0H,A
REPINC: STL A,*AR2+
RET

TABCOS:
.word
.word
.word
.word
TABSIN:
.word
.word
.word
.word

00100H
000B5H
00000H
0FF4BH
00000H
0FF4BH
0FF00H
0FF4BH

;
*********************************************************
******************
;INPUT:
DATA MEMORY
;
0A200
0700
;
0A201
0B00
;
0A202
0F00
;
0A203
0B00
;
0A204
0700
;
0A205
0300
;
0A206
0000
;
0A207
0300
;OUTPUT:
;
0A400
;
0A401
;
0A402
;
0A403
;
0A404
;
0A405
;
0A406

DATA MEMORY
3900
0000
0000
E5B0
FF00
0000
0000

;
0A407
03B0
;
0A408
0100
;
0A409
0000
;
0A40A
0000
;
0A40B
FC50
;
0A40C
FF00
;
0A40D
0000
;
0A40E
0000
;
0A40F
1A50
;
*********************************************************
******************

S-ar putea să vă placă și