Write A Mat Lab Program To Perform Linear and Circular Convolution of The Discrete Time Sequences X
Write A Mat Lab Program To Perform Linear and Circular Convolution of The Discrete Time Sequences X
1. Write a Mat lab program to perform Linear and Circular convolution of the discrete time
sequences x(n) = { 0,1,0,1} and h(n) = { 1,2,1,2} using DFT.
AIM:
To write the program for finding the linear and circular convolution of two
signals using MATLAB 7.0.
APPARATUS REQUIRED:
System with MATLAB 7.0.
LINEAR CONVOLUTION:
ALGORITHM:
1. Get the number of samples.
2. Generate the output sequence of the given two input signals using conv command
3. Plot the graph.
PROGRAM:
clc;
clear all;
close all;
x=input('Enter the first sample');
N1=length(x);
h=input('Enter the second sample');
N2=length(h);
n=0:1:N1-1;
subplot(2,2,1);
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('X Sequence Response');
n=0:1:N2-1;
subplot(2,2,2);
stem(n,h);
xlabel('Time');
ylabel('Amplitude');
title('H Sequence Response');
y=conv(x,h);
N=N1+N2-1;
n=0:1:N-1;
subplot(2,2,3);
stem(n,y);
xlabel('Time');
ylabel('Amplitude');
title('Convolution of X&H Response');
CIRCULAR CONVOLUTION:
ALGORITHM:
1. Get the number of samples.
2. Generate the sequence for the given two input signals using zeros and ones matrix
command.
3. Generate the convoluted output sequence of the given two input signals using conv
command.
4. Plot the graph.
PROGRAM:
% PROGRAM FOR CIRCULAR CONVOLUTION
clc;
clear all;
close all;
x=input('Enter the first sequence');
N1=length(x);
h=input('Enter the second
sequence');
N2=length(h);
n=0:1:N1-1;
subplot(2,2,1);
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('X Sequence Response');
n=0:1:N2-1;
subplot(2,2,2);
stem(n,h);
xlabel('Time');
ylabel('Amplitude');
title('H Sequence Response');
N=max(N1,N2);
x=[x,zeros(1,N-N1)];
h=[h,zeros(1,N-N2)];
for n=1:N
y(n)=0;
for i=1:N
j=n-i+1;
if(j<=0)
j=N+j;
end
y(n)=y(n)+x(i)*h(j);
end
end
disp('Convolution of x & h is');
subplot(2,2,3);
stem(y);
xlabel('Time');
ylabel('Amplitude');
title('Convolution of
X&H Response');
RESULT:
Thus the program for finding the linear and circular convolution of two
signals using MATLAB 7.0. was verified successfully].
2. Write a Mat lab program to determine the impulse response of FIR low pass filter and High
pass filter by Fourier series method and hence plot the frequency response.
AIM:
To design a FIR filter using Fourier series method with MATLAB 7.0.
APPARATUS REQUIRED:
System with MATLAB 7.0
ALGORITHM:
1. Get the pass band and stop band ripple and frequency.
2. Get the sampling frequency.
3. Find the order of filter N.
4. Design the lowpass and High pass filter.
5. Plot the magnitude response of all the filters.
PROGRAM:
clc;
clear all;
%LOW PASS FILTER
close all;
b=fir1(n,wp,y);
rp=input('Pass band ripple=');
[h,o]=freqz(b,1,256);
rs=input('Stop band ripple=');
m=20*log10(abs(h));
fs=input('Stop band frequency in
subplot(2,2,1);
rad/sec=');
plot(o/pi,m,'k');
fp=input('Pass band frequency in
ylabel('Gain in db---->');
rad/sec=');
xlabel('Normalized frequency---->');
f=input('Sampling frequency in
title('LOW PASS FILTER')
rad/sec=');
wp=2*fp/f;
%HIGH PASS FILTER
ws=2*fs/f;
b=fir1(n,wp,'high',y);
num=-20*log10(sqrt(rp*rs))-13;
[h,o]=freqz(b,1,256);
dem=14.6*(fs-fp)/f;
m=20*log10(abs(h));
n=ceil(num/dem)
subplot(2,2,2);
n1=n+1;
plot(o/pi,m,'k');
if(rem(n,2)~=0);
ylabel('Gain in db---->');
n1=n;
xlabel('Normalized frequency---->');
n=n-1;
title('HIGH PASS FILTER')
end
OUTPUT:
RESULT:
Thus the FIR filter using Fourier series method with MATLAB 7.0. was designed and verified
successfully
.
3. Write a Mat lab program to design an IIR filter (Chebyshev3rd order LPF) to satisfy the
following specifications (Assume T= 1seconds) using BLT method.
0.8|H (ej) |1, for 00.2
|H (ej) |0.2, for 0.32
AIM:
To design a digital IIR filter using Chebyshev filter with MATLAB 7.0.
APPARATUS REQUIRED:
System with MATLAB 7.0.
ALGORITHM:
1. Get the pass band and stop band ripples.
2. Get the pass band and stop band frequencies.
3. Get the sampling frequency.
4. Calculate the order of the filter using
5.Find the filter co-efficient.
6.Draw the magnitude and phase response.
PROGRAM:
clear all;
clc;
close all;
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;
%LOW PASS FILTER
[n,wn]=cheb ord(w1,w2,rp,rs];
[b,a]=cheby 1(n,wn);
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)normalized
frequency>);
Subplot(2,1,2);
Plot(om/pi,an);
Xlabel((b)normalized
Ylabel(phase in
radians>);
frequency>);
OUTPUT:
OUTPUT FOR CHEBYSHEV IIR DIGITAL FILTER:
Enter the pass band ripple:0.02
Enter the stop band ripple:.03
Enter the pass band frequency:1200
Enter the stop band frequency:2400
Enter the sampling frequency:8000
Filter order
1
Cut-off frequency
0.300000000000000
RESULT:
Thus the digital IIR filter using Chebyshev filter with MATLAB 7.0 was designed and
verified successfully.
4. Write a Mat lab program to determine the impulse response of FIR Low pass filter and
High pass filter by using Rectangular window method and hence plot the frequency
response.
AIM:
To design a FIR filter using Rectangular window with MATLAB 7.0.
APPARATUS REQUIRED:
end
y=boxcar(n1);
%LOW PASS FILTER
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(o/pi,m,'k');
ylabel('Gain in db---->');
xlabel('Normalized frequency---->');
title('LOW PASS FILTER')
%HIGH PASS FILTER
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(o/pi,m,'k');
ylabel('Gain in db---->');
xlabel('Normalized frequency---->');
title('HIGH PASS FILTER')
OUTPUT
Enter the passband ripple: .05
Enter the stopband ripple: .03
Enter the passband frequency: 1300
Enter the stopband frequency: 1600
Enter the sampling frequency: 7400
The order is:n = 26
RESULT:
Thus the matlab program to design a FIR filter using rectangular window was written and the
output was verified.
5. Write a Mat lab program to determine the impulse response of FIR Low pass filter and
High pass filter by using Kaiser window method and hence plot the frequency
response
AIM
To write a matlab program to design a FIR filter using Kaiser window and to verify the output.
ALGORITHM
');
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(om/pi,m);
ylabel('Gain in dB---->');
xlabel('Frequency in rad/sec---->');
%highpass filter
b=fir1(n,wp,'high',y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(om/pi,m);
ylabel('Gain in dB---->');
xlabel('Frequency in rad/sec---->');
OUTPUT
Enter the passband ripple: .05
Enter the stopband ripple: .03
Enter the passband frequency: 1300
Enter the stopband frequency: 1600
Enter the sampling frequency: 7400
Enter the beta value:
7
The order is:
n = 26
RESULT
Thus the matlab program to design a FIR filter using Kaiser window was written and the output
was verified.
6. Write a Mat lab program to determine the impulse response of FIR Low pass filter and
High pass filter by using triangular window method and hence plot the frequency
response
AIM:
To write a matlab program to design a FIR filter using triangular window and to verify the
output.
ALGORITHM
y=kaiser(n1,beta);
clc;
close all;
clear all;
rp=input('Enter the passband ripple: ');
rs=input('Enter the stopband ripple: ');
fp=input('Enter the passband frequency: ');
fs=input('Enter the stopband frequency: ');
f=input('Enter the sampling frequency: ');
beta=input('Enter the beta value:
');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
disp('The order is:');n
%lowpass filter
b=fir1(n,wp,y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(om/pi,m);
ylabel('Gain in dB---->');
xlabel('Frequency in rad/sec---->');
%highpass filter
b=fir1(n,wp,'high',y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(om/pi,m);
ylabel('Gain in dB---->');
xlabel('Frequency in rad/sec---->');
OUTPUT:
enter passband ripple0.02
enter the stopband ripple0.01
enter passband freq1000
enter stopband freq1500
10
G a in in d B -->
GRAPH:
-20
-40
-60
G a in in d B -->
LPF
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(a) Normalized frequency-->
HPF
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(b) Normalized frequency-->
0.8
0.9
0
-10
-20
-30
RESULT:
The LP and HP FIR Filter response for the given sequence is generated based upon the choice of the
windowing function and the filter characteristics are plotted.
7. Write a Mat lab program to design an IIR filter (Butterworth 2 nd order LPF & HPF) to
satisfy the following specifications (Assume T= 0.1seconds) using BLT method.
0.6|H (ej) |1, for 0.7
|H (ej) |0.1, for 00.35
AIM:
To design a Butterworth digital IIR filter using MATLAB 7.0.
APPARATUS REQUIRED:
System with MATLAB 7.0.
ALGORITHM:
1. Get the pass band and stop band ripples.
2. Get the pass band and stop band frequencies.
3. Get the sampling frequency.
4. Calculate the order of the filter using
5.Find the filter co-efficient.
6.Draw the magnitude and phase response.
PROGRAM:
clear all;
clc;
close all;
format long
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;
%LOW PASS FILTER
[n,wn]=buttord(w1,w2,rp,rs];
[b,a]=butter(n,wn);
%[b,a]=zp2tf(z,p,k);
[b,a]= butter(n,wn);
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
%figure(1);
Subplot(2,1,1);
Plot(om/pi,m);
Ylabel(gain in db>);
11
Xlabel((a)normalized frequency>);
%figure(1);
Subplot(2,1,2);
Plot(om/pi,an);
Xlabel((b)normalized frequency>);
Ylabel(phase in radians>);
%HIGH PASS FILTER
[n,wn]=buttord(w1,w2,rp,rs];
[b,a]=butter(n,wn,high);
W=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure(2);
Subplot(2,1,1);
Plot(om/pi,m);
Ylabel(gain in db>);
Xlabel((a)normalized frequency>);
figure(2);
Subplot(2,1,2);
Plot(om/pi,an);
Xlabel((b)normalized frequency>);
Ylabel(phase in radians>);
OUTPUT:
Enter the ripple of pass band (rp)= .5
Enter the ripple of stop band (rs)= 50
Enter the frequency of pass band (fp)= 1200
Enter the frequency of stop band (fs)= 2400
Enter the sampling frequency (F)= 10000
Filter order
8
Cut-off frequency
0.273047748609120
12
RESULT:
The LP and HP IIR Filter response for the given sequence is generated and the filter characteristics are
plotted.
8. .
Write a MATLAB program to generate the CT and DT elementary signals and plot it.
AIM
To write a MATLAB program to generate various type of signals.
ALGORITHM
1. Start the program.
2. Clear the command window using clc function.
3. Create the array of time sequence by assigning values oft.
4. Get the input value using the input function for generating
various sequences.
5. Provide matrix values by giving zero and ones values in y.
6. Using subplot function plot the graph and use stem to obtain discrete sequence.
7. Label in the X and Y axis using label function.
8. End the program.
PROGRAM
clc;
clear all;
close all;
%Generation of cosine sequence
t1=0:.01:pi;
y1=cos(2*pi*t1);
figure(1);
subplot(3,2,1);
plot(t1,y1);
ylabel('Amplitude---->');
13
xlabel('(a)n---->');
%Generation of sine sequence
y2=sin(2*pi*t1);
subplot(3,2,2);
plot(t1,y2);
ylabel('Amplitude---->');
xlabel('(b)n---->');
%Generation of exponential sequence
n2=input('Enter the length of
exponential sequence: ');
t3=0:n2;
a=input('Enter the value: ');
y3=exp(a*t3);
subplot(3,2,3);
stem(t3,y3);
ylabel('Amplitude---->');
xlabel('(c)n---->');
%Generation of unit impulse signal
t4=-2:1:2;
y4=[zeros(1,2),ones(1,1),zeros(1,2)];
subplot(3,2,4);
stem(t4,y4);
ylabel('Amplitude---->');
xlabel('(d)n---->');
%Generation of unit step sequence
n5=input('Enter the N value for unit step
sequence: ');
t5=0:1:n5-1;
y5=ones(1,n5);
subplot(3,2,5);
stem(t5,y5);
ylabel('Amplitude---->');
xlabel('(e)n---->');
%Generation of unit ramp sequence
n6=input('Enter the length of ramp
sequence: ');
t6=0:n6;
subplot(3,2,6);
stem(t6,t6);
ylabel('Amplitude---->');
xlabel('(f)n---->');
OUTPUT
Enter the length of exponential sequence: 4
Enter the value: 4
Enter the N value for unit step sequence: 6
Enter the length of ramp sequence: 5
14
9. Write a Mat lab program to perform Auto Correlation and Cross correlation of the discrete
time sequences x(n) = { 1,2,3,4} and h(n) = { 4,3,2,1} using DFT.
AIM:
To perform auto- correlation and cross- correlation of given sequences in MATLAB.
ALGORITHM:
Start MATLAB.
Enter the input sequence.
Give Xlabel and Ylabel and title it.
Save and run the program.
Stop/Halt the program.
PROGRAM:
%Auto Correlation%
x= input (Enter any sequence);
subplot(3,2,1);
stem(x);
xlabel(Time period);
ylabel(Amplitude);
title(Input sequence);
y=xcorr(x);
subplot(3,2,2);
xlabel(Time period);
ylabel(Amplitude);
title(Auto correlation);
15
%Cross correlation%
x=input(Enter any sequence);
subplot(3,2,1);
stem(x);
xlabel(Time period);
ylabel(Amplitude);
title(Input sequence);
h=input(Enter any sequence);
subplot(3,2,2);
stem(h);
xlabel(Time period);
ylabel(Amplitude);
title(Impulse sequence);
y=xcorr(x,h);
subplot(3,2,3);
stem(y);
xlabel(Time period);
ylabel(Amplitude);
title(Cross correlation);
16
RESULT:
Thus, the auto- correlation and cross- correlation was performed using MATLAB
10. Write a program to study the various addressing modes of DSP using DSP processor.
AIM:
To study about direct, indirect and immediate addressing modes in TMS320C50 debugger.
APPARATUS REQUIRED:
1.System with TMS 320C50 debugger software
2.TMS 320C50 Kit.
ALGORITHM:
IMMEDIATE ADDRESSING MODE:
1. Initialize data pointer with 100H data.
2. Load the accumulator with first data.
3. Add the second data with accumulator content.
4. Store the accumulator content in specified address location.
5. DIRECT ADDRESSING MODE:
6. Initialize data pointer with 100H data.
7. Load the accumulator with first data, whose address is specified in the
8. instruction.
9. Add the accumulator content with second data, whose address is specified
10. in the instruction.
11. Store the accumulator content in specified address location.
IN-DIRECT ADDRESSING MODE:
1. Load the auxiliary register with address location of first data.
17
18
MPY *-,AR1
LTP *+,AR0
ADD 0H
SACL 0H
BANZ Loop_MAC,*-,AR2
LACC 0H
MAR *,AR3
SACL *;Shiftx(n) Values:
LAR AR1,#(8100H+6H)
LAR AR2,#5H
LAR AR0,#2H
MAR *,AR1
LACC *SACL 1H
Shift_XN:
LACC *+
SACL *0-,AR2
BANZ Shift_XN,*-,AR1
MAR *+
LACC 1H
SACL *,AR4
BANZ Next_YN,*NOP
H1: B H1
CIRCULAR CONVOLUTION
ALGORITHM:
19
ROTATE:
LDP #100H
LACC 1H
SUB #1H
SACL 2H
LACC 0050H
SACB
LAR AR3,#8051H
LAR AR5,#8070H
LAR AR6,2H
LOOP1:MAR *,AR3
LACC *+,0,AR5
SACL *+,0,AR6
BANZ LOOP1,*LACB
MAR *,AR5
SACL *+
LACC #8070H
SAMM BMAR
LAR AR3,#8050H
MAR *,AR3
RPT 0H
BLDD BMAR,*+
RET
RESULT:
Thus the program to find the Convolution of two sequences X(n) and H(n) using TMS320C50
debugger was designed and verified successfully.
. 12. Write and execute a DSP PROCESSOR program to Generate a Square wave using
TMS320C50.
20
AIM:
To write a program to generate Triangle Wave,Sine Wave,Square Wave and SawTooth Wave
using TMS320C50 debugger.
APPARATUS REQUIRED:
1.System with TMS 320C50 debugger software
2.TMS 320C50 Kit.
3.CR0
4.Function Generator.
ALGORITHM:
TRIANGLE WAVE GENERATION:
1. Start the program.
2. Load the LSBs of the address data memory
location.
3. Write full 16 bit pattern into address data
memory location.
4. Load the content of address data memory
location.
5. Add the content of address data memory
location.
6. Store the data of accumulator into address
data memory location.
7. Modify the current AR as specified.
8. Repeat the step 2,3.
9. Subtract the contents of address data memory
location.
10. Repeat the steps 5,6,7.
11. Stop the program.
SINE WAVE GENERATION:
1. Start the program
2. Load the LSBs of the address data memory
location
3. Write full 16 bit pattern into address data
memory location.
4. Load the content of address data memory
location.Specify the address of a
subroutine.
5. Multiply the content of the register.
6. Load the content of the register into
accumulator.
7. Store the 16 LSBs of the accumulator into the
address data memory
location.
9. Branch the contents of entire auxiliary
register.
10. Load the content of address data memory
location.
11. Repeat the Step.
12. Stop the program.
SQUARE WAVE GENERATION:
1. Start the program
2. Load the content of address data memory
location.
3. Store the 16 LSBs of the accumulator into the
address data memory
location.
4. Load the content of address data memory
location.
5. Complement the contents of the accumulator.
6. Stop the program.
.text
START:LDP #100H
SPLK #B500,TEMP
LAR AR2,#((LENGTH/INCFREQ)+
(LENGTH*DECFREQ))-1
LAR AR3,#DECFREQ
CONT:CALL DELAY
LACC TEMP
TBLR TEMP1
21
LT TEMP1
MPY #AMPLITUDE
PAC
SACL TEMP1
MAR *,AR3
BANZ REPEAT,*LAR AR3,#DECFREQ
LACC TEMP
ADD #INCFREQ
SACL TEMP
OUT TEMP1,4
MAR *,AR2
BANZ CONT,*B START
DELAY:LAR AR7,#DELAY1
MAR *,AR7
BACK:BANZ BACK,*RET
;
TABLE
.word 100 .word 145
.word 101 .word 146
.word 103 .word 148
.word 105 .word 150
RESULT:
Thus the program to generate Triangle Wave,Sine Wave,Square Wave and SawTooth Wave using
TMS320C50 debugger.
13. Write a program to determine the impulse response of FIR Low pass filter and Band pass filter
by Fourier series method and hence plot the frequency response by using DSP
Processor.
AIM:
To design a FIR low pass filter in serial mode.
APPARATUS REQUIRED:
1.System with VI debugger software
2.TMS 320C50 Kit.
3.CR0
ALGORITHM:
1. Start the program.
2. Initialize the C table value.
3. Load the auxillary register with
0200H.
4. Modify the auxillary register zero.
5. Block the C table to the program.
6. Set configuration control bit.
22
23
SUB #800H
MAR *,AR1
SACL *
LAR AR1,#0333H
ZAP
RPT #33H
MACD 0FF00H,*APAC
LAR AR1,#0300H
RESULT:
Thus the program for FIR low pass filter was designed and verified successfully using TMS
processor.
14. Write and execute a DSP PROCESSOR program to design a 9 tap FIR Low pass Filter
using TMS320C50.
For Answer Refer question no:13
15. Write a Mat lab program to determine the impulse response of IIR High pass filter and
Band stop filter by Fourier series method and hence plot the frequency response by
using DSP processor.
AIM:
To design a FIR high pass filter in serial mode.
APPARATUS REQUIRED:
1.System with VI debugger software
2.TMS 320C50 Kit.
3.CR0
ALGORITHM:
1. Start the program.
2. Initialize the C table value.
3. Load the auxillary register with 0200H.
4. Modify the auxillary register zero.
5. Block the C table to the program.
6. Set configuration control bit.
7. Load the data pointer with 0AH.
8. Initialize the analog to digital conversion.
9. Load the auxillary register 1 with 0300
content.
10. Load the accumulator in 8000H.
11. AND the accumulator with 0FFFH.
12. Subtract the accumulator content with data
800H.
13. Modify the auxillary register 1.
PROGRAM:
*Approximation type:Window designBlackmann Window
24
*Cutoff frequency in
KHZ=3.000000
.text
B START
CTABLE:
.word 0FCD3H
.word 05H
.word 0FCB9H
.word 087H
.word 0FD3FH
.word 01ADH
.word 0FE3DH
.word 0333H
.word 0FF52H
.word 04ABH
.word 0FFF8H
.word 0595H
.word 0FFACH
.word 0590H
.word 0FE11H
.word 047CH
.word 0FB0BH
.word 029DH
.word 0F6BAH
.word 0AEH
.word 0F147H
.word 01CH
.word 0E9FDH
.word 04C5H
.word 0D882H
.word 044BCH
.word 0D882H
.word 04C5H
.word 0E9FDH
.word 01CH
.word 0F147H
.word 0AEH
.word 0F6BAH
.word 029DH
.word 0FB0BH
.word 047CH
.word 0FE11H
.word 0590H
.word 0FFACH
.word 0595H
.word 0FF8H
.word 04ABH
.word 0FF52H
.word 0333H
.word 0FE3DH
.word 01ADH
.word 0FD3FH
.word 087H
.word 0FCB9H
.word 05H
.word 0FCD3H
* Move the Filter coefficients
* from program memory to
data memory
START:
LAR AR0,#0200H
MAR *,AR0
RPT #33H
BLKP CTABLE,*+
SETC CNF
25
RESULT:
Thus the program for designing a FIR high pass filter in serial mode was performed
SKILLED ASSISTANT
INTERNAL EXAMINER
EXTERNAL EXAMINER