Вы находитесь на странице: 1из 30

MOOKAMBIGAI COLLEGE OF ENGINEERING

Srinivasa Nagar, Kalamavur – 622 502

DEPARTMENT OF ELECTRONICS AND


COMMUNICATION ENGINEERING

EC6511 - Digital Signal Processing Laboratory

Name : ……………………………………

Reg No : ……………………………………

Branch : ……………………………………

Year & Semester : …………………………………...


INDEX

S.No Date Name of the Experiment Page Signature


Number
MATLAB
1a Generation of discrete time signals

1b Generation of continuous time signals

2 Generation of waveforms

3 Convolution of signals

4 Calculation of FFT

5a Design of FIR filter using Kaiser window

5a Design of FIR filter using Rectangular


window
5b Design of FIR filter using Hamming window

5c Design of FIR filter using Hanning window

5d Design of FIR filter using Blackmann


window
6a Butterworth digital IIR filter

6b Chebyshev digital IIR filter

7a Decimation by polyphase decomposition

7b Up sampling and down sampling of sequence

TMS320C5X
8 Study of addressing modes

9 Basic arithmetic operations

10 Implementation of Linear and Circular


Convolution
11 Waveform Generation

12 Design of FIR Low Pass filter


MATLAB COMMANDS

INPUT:
Syntax: input(‘’);
Description: To get the input
Eg: a = input(‘Enter the frequency’);

TIME:
Syntax: t = [initial value: step value: final value];
Description: To get the time period
Eg: t=[0;0.01];

PLOT:
Syntax: plot(x,y);
Description: To plot the result in continuous form.
Eg: plot(x,y);

SUBPLOT:
Syntax: subplot(m,n,p);
Where m - no of rows
n - no of columns
p - no of blocks
Description: To plot the graph in particular blocks
Eg: subplot(3,1,1);

STEM:
Syntax: stem();
Description: To give the result in discrete form.
Eg: stem(t,x);

LABEL:
(a) XLABEL:
Syntax: xlabel(‘ ’);
(b) YLABEL:
Syntax: ylabel(‘ ’);
Eg: xlabel(‘time’);
ylabel(‘amp’);
Description: To give the parameters on the graph.

TITLE:
Syntax: title(‘’);
Description: To give the title on the graph.
Eg: title(‘sine wave’);
FIR FILTER:
(a) BOXCAR:
Syntax: W=boxcar(N);
Description: Return the N-point rectangular window.
(b) HAMMING:
Syntax: W=hamming(N);
Description: Return the N-point hamming window
(c) HANNING:
Syntax: W=hanning(N);
Description: Return the N-point hanning window
(d) BLACKMAN:
Syntax: W=blackman(N);
Description: Return the N-point blackman window.

FRI:
Syntax: W=fir1(N,Wn);
Description: Design an Nth order lowpass FIR digital filter and returns the filter
co_efficients in length N+1 vector b.

ABS:
Syntax: abs(x);
Description: Compute the absolute value of the elements of x. When x is complex,
abs(x) is the complex magnitude of the element of x.

ANGLE:
Syntax: angle(x);
Description: Compute the phase angle of each component of the vector x.

REAL:
Syntax: real(x);
Description: To obtain the real power of x.
Eg: r=real(y);

IMAG:
Syntax: imag(x);
Description: To obtain the imaginary power of x.
Eg: i=imag(y);

FILTER:
Syntax: filter(b,a,x);
Description: Solves the differential equation, given the input sequence x and difference
equation coefficient(b,a).
Eg: h=filter(b,a,x);
ZPLANE:
Syntax: plane(b,a);
Description: Plots the zeros and poles in the unit circles for reference.
Eg: zplane(b,a);

ALL:
Syntax: all(v);
Description: Returns ‘1’ if none of the elements of the vector are zero. Otherwise it
returns ‘0’.
Eg: all(abs[a]<=1);

LOG:
(a) Syntax: log10(x);
Description: Computes the logarithm of each of the elements of X.
(b) Syntax: log(x);
Description: Computes the natural logarithm of each of the element of x.

FREQZ:
Syntax: H=freqz(b,a,w);
Description: Returns the frequency response at frequencies designated m vector W, in
radians.

BUTTORD:
Syntax: [N,Wn] = buttord(Wp,Ws,Rp,Rs);
Description: Returns the order of N of the lowest order digital butterworth filter and its
cutoff frequency.
For LPF: Wp<Ws
For HPF: Wp>Ws
For BPF: Wp=[Wp1,Wp2]
Ws=[Ws1,Ws2]
Where Ws1<Wp1<Wp2<Ws2
For BSF: Wp1<Ws1<Ws2<Wp2

CHEB ORD:
(a) Syntax: [N,Wn]=cheb1 ord(Wp,Ws,Rp,Rs);
Description: Returns the order N of the lowest order digital chebychev type1 filter and its
cutoff frequencies.
(b) Syntax: [n,Wn]=cheb2 ord(Wp,Ws,Rp,Rs);
Description: Returns the order N of lowest order digital chebchev type2 filter and its
cutoff frequency.
BUTTER:
Syntax: [b,a]=butter[N,Wn];
Description: Design an Nth order lowpass digital butterworth filter and returns the filter
co-efficient (b,a) in lengh N+1 and Wn in units of ‘Pi’.
If Wn=[Wn1,Wn2], then the function returns an order 2N bandpass filter with 3db
passband W1<W<W2 in Units of ‘Pi’.

Syntax: [b,a]=butter[N,Wn,’high’];
Description: Design an Nth order highpass digital butterworth filter and returns the filter
co-efficient(b,a) in length N+1 and Wn in units of ‘Pi’.

Syntax: [b,a]=butter(N,Wn,’stop’);
Description: Design an bandstop digital butterworth filter of order 2N with 3db stopband
W1<W<W2 in units of ‘Pi’.

CEHBY1:
Syntax: [b,a]=cheby1[N,Rp,Wn];
Description: Design an Nth order lowpass digital chebchev type1 filter with Rp db of
ripples in the pass band and returns the co-efficients(b,a) in length N+1 and Wn in units
of ‘Pi’.
If Wn=[Wn1,Wn2], then the function returns an order 2N bandpass filter with 3db
passband W1<W<W2 in Units of ‘Pi’.

Syntax: [b,a]= cheby1(N,Rp,Wn,’high’);


Description: Design an Nth order highpass digital chebchev type1 filter and returns the
filter co-efficient(b,a) in length N+1 and Wn in units of ‘Pi’.

Syntax: cheby1(N,Rp,Wn,’stop’);
Description: Design an bandstop digital chebchev type1 filter of order 2N with 3db
stopband W1<W<W2 in units of ‘Pi’.

CEHBY2:
Syntax: [b,a]=cheby2[N,Rs,Wn];
Description: Design an Nth order lowpass digital chebchev type2 filter with Rs db of
ripples in the pass band and returns the co-efficients(b,a) in length N+1 and Wn in units
of ‘Pi’.
If Wn=[Wn1,Wn2], then the function returns an order 2N bandpass filter with 3db
passband W1<W<W2 in Units of ‘Pi’.

Syntax: [b,a]= cheby2(N,Rs,Wn,’high’);


Description: Design an Nth order highpass digital chebchev type2 filter and returns the
filter co-efficient(b,a) in length N+1 and Wn in units of ‘Pi’.

Syntax: cheby2(N,Rs,Wn,’stop’);
Description: Design an bandstop digital chebchev type2 filter of order 2N with 3db
stopband W1<W<W2 in units of ‘Pi’.
DISP:
Syntax: disp(‘text’);
Description: Display the parameter which is passed through the function.

FFT:
Syntax: fft(x,N);
Description: Compute the DFT of the sequence x using radix-2, N point FFT algorithm.

IFFT:
Syntax: ifft(x,N);
Description: Compute the IDFT of the sequence x using radix-2, N point FFT algorithm.

LENGTH:
Syntax: length(n);
Description: compute the length of the sequence.

AXIS:
Syntax: axis([Xmin,Xmax,Ymin,Ymax]);
Description: To control axis scaling on the X and Y axis on the current plot.

GRID ON:
Syntax: grid on;
Description: To add grid lines to the current axis.

PAUSE:
Syntax: pause(constant); (or)pause;
Description: To set pause the execution of program. It waits for sometime and then
executes the next statement.

CONVOLUTION:
Syntax: conv();
Description: Compute the convolution of two sequences.
GENERATION OF DISCRETE TIME SIGNALS:

PROGRAM:

1. UNIT IMPULSE SIGNAL


clc;
N=input('enter the N value:');
n=-N:1:N
x=[zeros(1,N),ones(1,1),zeros(1,N)]
stem(n,x);
xlabel('time');
ylabel('amplitude');
title('impulse response');

2. UNIT STEPSIGNAL
clc;
clear all;
close all;
N=input('enter the N value =');
n=-N:1:N
x=[zeros(1,N), ones(1,1), ones(1,N)]
stem(n,x);
xlabel('Time');
ylabel('Amplitede');
title('Unit Step Response');

3. RAMP SIGNAL
clc;
clear all;
close all;
disp('RAMP SIGNAL');
N=input('Number of samples=');
a=input('Amplitude=');
n=-N:1:N
x=a*n
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Ramp Response');
Ex. No. 1a GENERATION OF DISCRETE TIME (ELEMENTARY) SIGNALS
Date:

AIM:
To generate the following discrete time signals using MATLAB 7.0
1. Unit impulse signal
2. Unit step signal
3. Unit ramp signal
4. Exponential growing signal
5. Exponential decaying signal
6. Sine signal
7. Cosine signal

APPARATUS REQUIRED:
Personal computer with MATLAB software.

ALGORITHM:
1. Get the number of samples.
2. Generate the unit impulse, unit step using ‘ones’, ‘zeros’ matrix
command.
3. Generate ramp, sine, cosine and exponential signals using corresponding general
formula.
4. Plot the graph.

PROCEDURE

1. OPEN MATLAB
2. File New Script.
3. Type the program in untitled window
4. File Save type filename.m in matlab workspace path
5. Debug Run. Wave will be displayed at Figure dialog box.
4. EXPONENTIAL GROWING SIGNAL
clc;
clear all;
close all;
disp('EXPONENTIAL GROWING SIGNAL');
N=input('Number of samples=');
a=input('Enter a value greater than 1 ');
n=0:0.2:N;
x=a.^n;
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Exponential Growing Signal Response');

5. EXPONENTIAL DECAYING SIGNAL


clc;
clear all;
close all;
disp('EXPONENTIAL DECAYING SIGNAL');
N=input('Number of samples=');
a=input('Enter a value between 0 and 1');
n=0:0.2:N;
x=a.^n;
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Exponential Decaying Signal Response');

6.SINE SIGNAL
clc;
clear all;
close all;
disp('SINE SIGNAL');
N=input('Number of samples=');
n=0:0.1:N;
x=sin(n);
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Sine Signal');
7. COSINE SIGNAL
clc;
clear all;
close all;
disp('COSINE SIGNAL');
N=input('Number of samples=');
n=0:0.1:N;
x=cos(n);
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Cosine Signal');
RESULT:
PROGRAM:
% PROGRAM FOR LINEAR CONVOLUTION
clc;
clear all;
close all;
x=input('Enter the first sequence);
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 ');
n=0:1:N2-1;
subplot(2,2,2);
stem(n,h);
xlabel('Time');
ylabel('Amplitude');
title('H Sequence ');
y=conv(x,h);
disp(y)
N=N1+N2-1;
n=0:1:N-1;
subplot(2,2,3);
stem(n,y);
xlabel('Time');
ylabel('Amplitude');
title('Convolution of X and H ');
Ex.No. 2 CONVOLUTION OF SIGNALS
Date:

AIM:
To write the program for finding the linear and circular convolution of two sequences
using MATLAB.

APPARATUS REQUIRED:
Personal Computer with MATLAB software.

LINEAR CONVOLUTION:
ALGORITHM:
1. Get the two sequence x(n) and h(n).
2. Perform the linear convolution of the two sequences using ‘conv’ command.
3. Display the result.

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.

PROCEDURE

OPEN MATLAB
1. File New Script.
2. Type the program in untitled window
3. File Save type filename.m in matlab workspace path
4. Debug Run. Wave will be displayed at Figure dialog box.
% 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 ');
n=0:1:N2-1;
subplot(2,2,2);
stem(n,h);
xlabel('Time');
ylabel('Amplitude');
title('H Sequence ');
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');
disp(y);
subplot(2,2,3);
stem(y);
xlabel('Time');
ylabel('Amplitude');
title('Circular Convolution of X&H ');
RESULT:
PROGRAM:
CROSS CORRELATION
% Program for computing cross-correlation of the sequences x[1, 2, 3, 4] and h[4, 3, 2, 1]
clc;
clearall;
close all;
x=input(‘enter the 1st sequence:’);
h=input(‘enter the 2nd sequence’);
y=crosscorr(x,h);
figure;
subplot(3,1,1);
stem(n,x);
ylabel(‘Amplitude’ );
xlabel(‘n’);
title(‘input sequence’);
subplot(3,1,2);
stem(n,h);
ylabel(‘Amplitude’ );
xlabel(‘n’);
title(‘impulse sequence’);
subplot(3,1,3);
stem(fliplr(y));
ylabel(‘Amplitude’);
xlabel(‘ n’);
title(‘Cross correlated sequence’);
disp(‘The resultant signal is’);
fliplr(y);
Ex. No. 1d CORRELATION OF SIGNALS
Date:

AIM:

To develop program for correlation in MATLAB.

APPARATUS REQUIRED:
PC having MATLAB software.

ALGORITHM:

1. Get the input sequences

2. Perform the cross correlation and auto correlation using MATLAB commands.

3. Plot the graph.

PROCEDURE

OPEN MATLAB
1. File New Script.
2. Type the program in untitled window
3. File Save type filename.m in matlab workspace path
4. Debug Run. Wave will be displayed at Figure dialog box.
AUTOCORRELATION
%Programforcomputingautocorrelationfunction
x=input(‘enter the sequence’);
y=crosscorr(x,x);
figure;
subplot(2,1,1);
stem(x);
ylabel(‘Amplitude’);
xlabel(‘(a)n’);
title(‘original signal’);
subplot(2,1,2);
stem(fliplr(y));
ylabel(‘Amplitude’);
xlabel(‘(a)n’);
title(‘Autocorrelatedsequence’);
disp(‘The resultant signal is’);
fliplr(y);
RESULT:
PROGRAM:
% CALCULATION OF FFT AND IFFT
clc;
clear all;
close all;
x=input('Enter the sequence x(n)');
N=length(x);
n=input('Enter the value of n for n-point FFT computation: ');
y=fft(x,n);
v=0:1:N-1;
t=0:1:n-1;
subplot(2,2,1);
stem(v,x);
xlabel('Time');
ylabel('Amplitude');
title('Input Signal');
subplot(2,2,2);
stem(t,abs(y));
xlabel('Time');
ylabel('Amplitude');
title('Magnitude Response of the FT of the input signal');
subplot(2,2,3);
stem(t,angle(y));
xlabel('Time');
ylabel('Amplitude');
title('Phase Response of the FT of the input signal ');
disp('fft of the sequence x(n) is');
disp(y);
y1=ifft(y,n);
subplot(2,2,4);
stem(t,y1);
xlabel('Time');
ylabel('Amplitude');
EX.NO. 5 CALCULATION OF FFT
Date:

AIM:
To write the program for calculating the N-point FFT and IFFT of given input
sequence using MATLAB.

APPARATUS REQUIRED:
Personal computer with MATLAB software.

ALGORITHM:
1. Get the input sequence and its length.
2. Calculate the Fast Fourier Transform and Inverse Fast Fourier Transform of
given sequence using user defined function fft and ifft.
3. Plot the magnitude and phase response of FFT sequence.
4. Plot the IFFT response.
title('IFFT of the sequence');
disp('ifft X(K) is ');
disp(y1);
RESULT:

Вам также может понравиться