You are on page 1of 77

LINEAR CONVOLUTION

%EXPERIMENT NO 1: LINEAR CONVOLUTION USING FORMULA %NAME :V.VIKAS %R.NO : 08H61A04C2 %AIM:To generate ouput y(n) by using linear convolution(using formula) with the help of matlab software. %APPARATUS: MATLAB 7.5.0,PC %THEORY: %Syntax %w = conv(u,v)Descriptionw = conv(u,v) convolves vectors u and v. %Algebraically, convolution is the same operation as multiplying the polynomials %Then w is the vector of length m+n-1 whose k the element is %The sum is over all the values of j which lead to %legal subscripts for u(j) and v(k+1-j), %specifically j = max(1,k+1-n): min(k,m). %When m = n, this %gives w(1) = u(1)*v(1) %w(2) = u(1)*v(2)+u(2)*v(1) %w(3) = u(1)*v(3)+u(2)*v(2)+u(3)*v(1)... %w(n) = u(1)*v(n)+u(2)*v(n-1)+ ... +u(n)*v(1)... %w(2*n-1) = u(n)*v(n)

SOURCE CODE clc; clear all; close all; %clear the command window %clear the previous workspace %close the figure window

disp('linear convolution program'); %disp(X) displays an array, without printing the array name. If X contains a text string, the string is displayed. X = input('enter input x(n)'); m = length(X); h = input('enter input h(n)'); n = length(h); x = [X , zeros(1,m)]; subplot(2,2,1); are numbered rowwise. %scanning x(n) and storing in x % m stores length of x %scanning h(n) and storing in h % n stores length of h %padding zeros to make unique length %subplot divides the current figure into rectangular panes that

stem(X); %A two-dimensional stem plot displays data as lines extending from a baseline along the x-axis. title('input sequences X(n) is:'); axes. Xlabel('--->n'); Ylabel('--->X(n) is:') grid; h = [h , zeros(1,m)]; subplot(2,2,2); are numbered rowwise. %The title is located at the top and in the center of the

%giving label to x axis %giving label to y axis %grid sets the XGrid, YGrid, and ZGrid properties of the axes. %padding zeros to make unique length %subplot divides the current figure into rectangular panes that

stem(h); %A two-dimensional stem plot displays data as lines extending from a baseline along the h-axis. title('input sequence h(n) is:'); axes. Xlabel('--->n'); %The title is located at the top and in the center of the

%giving label to x axis

Ylabel('--->h(n)'); grid;

%giving label to y axis %grid sets the XGrid, YGrid,and ZGrid properties of the axes.

disp('convolution of X(n) & h(n) is y(n):'); %disp(X) displays an array, without printing the array name. If X contains a text string, the string is displayed. y = zeros(1 , m+n-1); for i=1:m+n-1 y(i)=0; for j=1:m+n-1 if(j<i+1) y(i)=y(i)+x(j)*h(i-j+1); end end end %padding zeros to make unique length %for loop for i varying from 1 to m+n-1 %assigning 0 to y(i) %for loop for j varying from 1 to m+n-1 %if condition %formula %end of if condition %end of 2nd for loop %end of 1st for loop

subplot(2,2,[3,4]); are numbered rowwise.

%subplot divides the current figure into rectangular panes that

stem(y); %A two-dimensional stem plot displays data as lines extending from a baseline along the y-axis. title('convolution of x(n) & h(n) is:'); axes. Xlabel('--->n'); Ylabel('--->y(n)'); grid; %The title is located at the top and in the center of the

%giving label to x axis %giving label to y axis %grid sets the XGrid, YGrid,and ZGrid properties of the axes.

%PROCEDURE %1.Switch on the system and open matlab application. %2.create an m-file,write the program with correct syntax and semantics. %3.save and run the program by using F5 key. %4.check the command window for errors and debug it. %5.observe the waveforms. %RESULT:The sequences [1 2 3 4] is given as input and named as x(n) and %the sequence [4 3 2 1] is given as another input and named as h(n).the %convolution of these two sequences is done and the output [4 11 20 30 20 %11 4] is obtained.
input sequences X(n) is: 4
--->X(n) is:

input sequence h(n) is: 4 3


--->h(n)

3 2 1 0

2 1 0

2 --->n

4 --->n

convolution of x(n) & h(n) is: 30

--->y(n)

20

10

4 --->n

CIRCULAR CONVOLUTION

%EXPERIMENT NO 2: CIRCULAR CONVOLUTION USING FORMULA %NAME :V.VIKAS %R.NO : 08H61A04C2 %AIM:To generate ouput y(n) by using circular convolution(using formula) with the help of matlab software. %APPARATUS: MATLAB 7.5.0,PC %THEORY: Circular convolution is used to convolve two discrete Fourier transform (DFT) sequences. %For very long sequences, circular convolution may be faster than linear convolution. %c = cconv(a,b,n) circularly convolves vectors a and b. n is the length of the resulting vector. %If you omit n, it defaults to length(a)+length(B)-1. %When n = length(a)+length(B)-1. %You can also use cconv to compute the circular cross-correlation of two sequences Circular convolution is used to convolve two discrete Fourier transform(DFT) sequences. For very long sequences, circular convolution may be fasterthan linear convolution.c = cconv(a,b,n) circularlyconvolves vectors a and b. n isthe length of the resulting vector. If you omit n, it defaultsto length(a)+length(B)-1. When n = length(a)+length(B)-1,the circular convolution is equivalent to the linear convolution computedwith conv. You can also use cconv tocompute the circular cross-correlation of two sequences (see the example below).ExamplesThe following example calculates a modulo-4 circular convolution. a = [2 1 2 1]; b = [1 2 3 4]; c = cconv(a,b,4)

%SOURCE CODE: clc; clear all; close all; %clear the command window %clear the previous workspace %close the figure window

disp('circular convolution program'); %disp(X) displays an array, without printing the array name. If X contains a text string, the string is displayed. x=input('enter input x'); Nx=length(x); h=input('enter input h'); Nh=length(h); subplot(2,2,1); numbered rowwise. %scanning x(n) and storing in x % Nx stores length of x %scanning h(n) and storing in h % Nh stores length of h %subplot divides the current figure into rectangular panes that are

stem(x); %A two-dimensional stem plot displays data as lines extending from a baseline along the x-axis. title('x(n) sequence'); xlabel('------>n'); ylabel('------->x(n)'); grid; subplot(2,2,2); numbered rowwise. %The title is located at the top and in the center of the axes. %giving label to x axis %giving label to y axis %grid sets the XGrid, YGrid, and ZGrid properties of the axes. %subplot divides the current figure into rectangular panes that are

stem(h); %A two-dimensional stem plot displays data as lines extending from a baseline along the h-axis.

title('h(n) sequence'); xlabel('------->n'); ylabel('------->h(n)'); grid;

%The title is located at the top and in the center of the axes. %giving label to x axis %giving label to y axis %grid sets the XGrid, YGrid,and ZGrid properties of the axes.

N=max(Nx,Nh); %returns an array the same size as A and B with the largest elements taken from A or B. The dimensions of A and B must match, or they may be scalar. x=[x zeros(1,N-Nx)]; h=[h zeros(1,N-Nh)]; m=0:1:N-1; %adding zeros to sequence x if necessary %adding zeros to sequence h if necessary %initialising m

M=mod(-m,N); %if N ~= 0,returns m - n.*N where n = floor(-m./N).If N is not an integer and the quotient -m./N is within round off error of an integer, then n is that integer. h=h(M+1); for n=1:1:N; m=n-1; p=0:1:N-1; %incrementing the value of the sequence %initialising the loop %equating m to n-1 %intialising p

q=mod(p-m,N); %if N ~= 0,returns m - n.*N where n = floor(p-m./N).If N is not an integer and the quotient p-m./N is within round off error of an integer, then n is that integer. hm=h(q+1); H(n,:)=hm; size(X). end y=x*H' %incrementing the value of the sequence within the loop %size of detail coefficients(N-i+2) for i = 2, ...N+1 and S(N+2,:) =

%ending the loop %multiplying x with H'

k=0:N-1; subplot(2,2,3); numbered rowwise. stem(k,y); matrices of the same size.

%initialising k %subplot divides the current figure into rectangular panes that are

%plots X versus the columns of Y. X and Y must be vectors or

subplot(2,2,[3,4]); % creates an axes at the position specified by a four-element vector. left, bottom, width, and height are in normalized coordinates stem(y); %A two-dimensional stem plot displays data as lines extending from a baseline along the x-axis. title('convolution of x(n) & h(n)'); %The title is located at the top and in the center of the axes. xlabel('----->n'); ylabel('----->y(n)'); grid; %giving label to x axis %giving label to y axis %grid sets the XGrid, YGrid, and ZGrid properties of the axes.

%PROCEDURE: %1.Switch on the system and open matlab application. %2.create an m-file,write the program with correct syntax and semantics. %3.save and run the program by using F5 key. %4.check the command window for errors and debug it. %5.observe the waveforms.

%RESULT:The sequences [1 2 3 2] is given as input and named as x(n) and %the sequence [1 1 1 ] is given as another input and named as h(n).the %circular convolution of these two sequences is done and the output [6 5 6 7] is obtained.

x(n) sequence 3 1

h(n) sequence

------->h(n)

------->x(n)

0.5

2 ------>n

1.5

2 ------->n

2.5

convolution of x(n) & h(n) 8 6


----->y(n)

4 2 0

1.5

2.5 ----->n

3.5

SUM OF SINUSOIDAL SIGNALS

%EXPERIMENT NO 3:SUM OF SINUSOIDAL SIGNALS %ROLL NO.:08H61A04C2 %NAME: V.VIKAS %AIM:To write a program for sum of sinusoidal signals using matlab7.0 %APPARATUS: MATLAB 7.0,PC %THEORY: %The general form of sine is sin(x). %There are to types of sine harmonics. %They are EVEN HARMONiCS and ODD HARMONICS. %The general formula for even harmonics is sin((2*n*t)/(2*n)). %The general formula for odd harmonics is sin((2*n+1)*t/(2*n+1)). %SOURCE CODE(EVEN HARMONICS) clc; %Clear Command Window

clear all; %All functions, global variables, and classes are cleared in both the function workspace and in your base workspace. close all; t=0:0.01:pi; y1=sin(2*t)/2; y2=sin(4*t)/4; %deletes all figures whose handles are not hidden. %initialising t ranging from 0 to pi with interval 0.01 %defining y1 interms of sine %defining y2 interms of sine

y3=sin(6*t)/6; y4=sin(8*t)/8; y5=sin(10*t)/10; y6=sin(12*t)/12; y=y1+y2+y3+y4+y5+y6; subplot(2,1,1); numbered rowwise

%defining y3 interms of sin. %defining y4 interms of sine %defining y5 interms of sine %defining y6 interms of sine %adding y1,y2,y3,y4,y5,y6 and naming it as y %divides the current figure into rectangular panes that are

plot(t,y,t,y1,t,y2,t,y3,t,y4,t,y5,t,y6); %plotting graph y,y1,y2,y3,y4,y5,y6 wrt t title('even harmonics'); axes %outputs the string at the top and in the center of the current

legend('y','y1','y2','y3','y4','y5','y6'); %displays a legend in the current axes using the specified strings to label each set of data. xlabel('amplitude'); ylabel('time period'); %labelling x-axis as amplitude %labelling y-axis as time period

SOURCE CODE(ODD HARMONICS); t=0:0.01:pi; y1=sin(1*t)/1; y2=sin(3*t)/3; y3=sin(5*t)/5; y4=sin(7*t)/7; y5=sin(9*t)/9; %initialising t ranging from 0 to pi with interval 0.01 %defining y1 interms of sine %defining y2 interms of sine %defining y3 interms of sine %defining y4 interms of sine %defining y5 interms of sine

y6=sin(11*t)/11; y=y1+y2+y3+y4+y5+y6; subplot(2,1,2); numbered rowwise

%defining y6 interms of sine %adding y1,y2,y3,y4,y5,y6 and naming it as y %divides the current figure into rectangular panes that are

plot(t,y,t,y1,t,y2,t,y3,t,y4,t,y5,t,y6); %plotting graph y,y1,y2,y3,y4,y5,y6 wrt t title('odd harmonics'); axes %outputs the string at the top and in the center of the current

legend('y','y1','y2','y3','y4','y5','y6'); %displays a legend in the current axes using the specified strings to label each set of data. xlabel('amplitude'); ylabel('time period'); %PROCEDURE: %1)Open the MATLAB7.0 %2)Go to file,open new file and click on M-file. %3)Write the source code in editing. %4)Go to file & save the file. %5)Then go to debug & click on RUN. %6)Observe the obtain graph. %labelling x-axis as amplitude %labelling y-axis as time period

%RESULT : Hence the even and odd harmonics of the given sine signals is computed.

FAST FOURIER TRANSFORMATION

%EXPERIMENT NO 4: FAST FOURIER TRANSFORMATION %NAME :V.VIKAS %R.NO : 08H61A04C2 %Aim:To perform fast fourier transformation of a sequence using MATLAB %Apparatus:MATLAB7.0,Computer %Theory: %The FFT block computes the fast Fourier transform (FFT) of each channel of a P-by-N or length-P input, u. %When the Inherit FFT length from input dimensions check box is selected, %the input length P must be an integer power of two, and the FFT length M is equal to P. %When the check box is not selected, P can be any length, and the value of %the FFT length parameter must be a positive integer power of two. %For user-specified FFT lengths, when M is not equal to P, zero padding or %modulo-M data wrapping happens before the FFT operation. %y = fft(u,M).

%SOURCE CODE: xn=input('enter sequence'); N=input('enter length'); L=length(xn); subplot(3,1,1); numbered rowwise %scanning x(n) and storing in xn %scanning the length and stores in L % L stores length of x %subplot divides the current figure into rectangular panes that are

stem(xn); %plots the data sequence Y as stems that extend from equally spaced and automatically generated values along the x-axis. if(N<L) %initializing if statement

error('N must be >= L'); %displays an error message and returns control to the keyboard end %ending the if statement %defining x1 %initialising the loop %initialising the another loop within the main loop

x1=[xn,zeros(1,N-L)]; for k=0:1:N-1 for n=0:1:N-1

p=exp(-i*2*pi*n*k/N); %defining p x2(k+1,n+1)=p; end end xk=x1*x2; magxk=abs(xk); argxk=angle(xk); %defining x2 %ending the loop present in the main loop %ending the main loop %defining xk %defining magxk %definig argxk

k=0:N-1; subplot(3,1,2); numbered rowwise

%k ranges fron 0 to N-1 %subplot divides the current figure into rectangular panes that are

stem(k,magxk); %plots X versus the columns of Y. X and Y must be vectors or matrices of the same size. Additionally, X can be a row or a column vector and Y a matrix with length(X) rows. xlabel('k'); ylabel('|x(k)|'); subplot(3,1,3); numbered rowwise %giving label to x axis %giving label to y axis %subplot divides the current figure into rectangular panes that are

stem(k,argxk); %plots X versus the columns of Y. X and Y must be vectors or matrices of the same size. Additionally, X can be a row or a column vector and Y a matrix with length(X) rows. xlabel('k'); ylabel('argxk'); %giving label to x axis %giving label to y axis

%PROCEDURE: %1.Switch on the system and open matlab application. %2.create an m-file,write the program with correct syntax and semantics. %3.save and run the program by using F5 key. %4.check the command window for errors and debug it. %5.observe the waveforms.

%RESULT:Hence the fast fourier transformation is performed for the sequence %[1 2 4 8 3 2] and the obtained magnitude response is %[20 12.32 4 4.014 4 4.014 4 12.32] and the phase response is %[0 -2.24 1.57 -0.42 -3.14 0.42 -1.57 2.24].

FREQUENCY RESPONE OF THE LOW PASS/HIGH PASS BUTTERWORTH FILTER

%EXPERIMENT NO 5: FREQUENCY RESPONSE OF THE LOW PASS/HIGH PASS %BUTTERWORTH FILTER %NAME :V.VIKAS %R.NO : 08H61A04C2 %Aim:To perform Frequency response of the low pass/High pass Butterworth filter using %MATLAB %Apparatus:MATLAB7.0,Computer %BUTTER WORTH LOW PASS FILTER : %Butter designs lowpass, bandpass, highpass, and bandstop digital andanalog Butterworth filters. %Butterworth filters are characterized by a magnitude response that is maximally flatin the %passband and monotonic overall. %Digital Domain

%[b,a] = butter(n,Wn) %designs an order n lowpass digital Butterworth filter with normalized cutoff frequency Wn.It %returns the filter coefficients in length n+1 row vectors b and a, with coefficients in descending %powers of z. %Analog Domain %[b,a] = butter(n,Wn,'s') designs an order n lowpass analog Butterworth %filter with angular cutoff frequency Wn rad/s.

SOURCE CODE

rp = input('Enter Passband Ripple'); rs = input('Enter Stopband ripple'); wp = input('Enter Passband Frequency'); ws = input('Enter Stop Band Frequency'); fs = input('sampling frequency'); w1 = 2*wp/fs; w2 = 2*ws*fs;

% Input for passband ripple %scanning input for stopand ripple %scanning input for passband frequency %scanning input for stopband frequency %Scanning Input for sampling frequency

[n,wn] = buttord(w1,w2,rp,rs,'s'); %buttord calculates the minimum order of a digital or analog Butterworth filter required to meet a set of filterdesign specifications. [b,a] = butter(n,wn,'high','s'); object w=0:0.01:pi; [h,om] = freqs(b,a,w); m = 20*log(abs(h)); plot(om/pi,m); ylabel('gain in dB'); xlabel('Normalized Frequency'); %Butterworth IIR filter design using specification

%w ranges form 0 to pi %Frequency response of analog filters %Calculating values of m using absolute value of h %Plotting om/pi vs m % Labelling X - axis % Labelling y - axis

%PROCEDURE : % 1. OPEN MATLAB 7.0. % 2. GO TO FILE MENU AND OPEN A NEW M-FILE. %3. WRITE THE SOURCE CODE IN EDITING %4. GO TO FILE AND SAVE THE PROGRAM. %5. GO TO DEBUG AND RUN THE FIEL. %6. OBSERVE THE OBTAINED GRAPH. %RESULT:Hence the frequency response of the low pass/high pass butterworth filter is conducted.

OBSERVED WAVEFORMS:
Low Pass Butterworth Filter
x 10
-11

0 -1 -2 -3

gain in dB

-4 -5 -6 -7 -8

0.1

0.2

0.3

0.4 0.5 0.6 Normalized Frequency

0.7

0.8

0.9

High Pass Butterworth Filter

-240

-260

-280

gain in dB

-300

-320

-340

0.1

0.2

0.3

0.4 0.5 0.6 Normalized Frequency

0.7

0.8

0.9

POWER SPECTRAL DENSITY

%EXPERIMENT NO 6: POWER SPECTRAL DENSITY %NAME :V.VIKAS %R.NO : 08H61A04C2 %Aim:To obtain power spectral density of a signal using MATLAB %Apparatus:MATLAB7.0,Computer %THEORY: %The goal of spectral estimation is to describe the %distribution (over frequency) of the power contained in a signal, based on %a finite set of data. Estimation of power spectra is useful in a variety of %applications, including the detection of signals buried in wide-band noise.The power spectral density (PSD) %of a stationary random process xn is %mathematically related to the correlation sequence by the discrete-time %Fourier transform. In terms of normalized frequency

%SOURCE CODE: clc; clear all; close all; t=0:0.01:1; %Clear Command Window %Remove items from workspace %Close the figure window %Assign values from 0 to 1

x=(2*sin(2*pi*50*t))+(2*sin(2*pi*100*t)); y=x+800*randn(size(t)); subplot(2,2,1); plot(y); F=fft(y); subplot(2,2,2); plot(abs(F)); c=xcorr(F); subplot(2,2,3); plot(abs(c)); %Adding normally distributed random numbers %Create axes in tiled positions %2-D line plot %Compute fast Fourier transform %Create axes in tiled positions %2-D line plot %Correlation %Create axes in tiled positions %2-D line plot

%PROCEDURE: %Open MATLAB 7.0 %Go to file, click on new M-file to open editor window. %Write the source code in editor window. %Save the file with '.m' extension. %Click on 'run' in debug menu to execute code. %Check for errors in command window. %Observe the output in figure window. %RESULT: %Observed the power spectral density of the given signal.

FREQUENCY RESPONSE OF FIR LPF UNSIG KAISER WINDOW

%EXPERIMENT NO 7: FREQUENCY RESPONSE OF FIP LPF USING KAISER WINDOW %NAME :V.VIKAS %R.NO : 08H61A04C2 %Aim:To obtain frequency response of FIR LPF unsing KAISER Window using MATLAB %Apparatus:MATLAB7.0,Computer %THEORY: %A Finite Impulse Response (FIR) filter is a discrete linear time-invariant system %whose output is based on the weighted summation of a finite number of past inputs. %An FIR transversal filter structure can be obtained directly from the equation for %discrete-time convolution. %FIR filter is a finite impulse response filter. Order of the filter should be specified. %Infinite response is truncated to get finite impulse response. placing a window of %finite length does this. Types of windows available are Rectangular, Barlett, %Hamming, Hanning, Blackmann window etc. This FIR filter is an all zero filter. %SOURCE CODE: clc; clear all; close all; n=40; fp=200; fs=1000; fn=2*fp/fs; %Clear Command Window %Remove items from workspace %Remove items from workspace %Number of samples %Passband frequency %Stopband frequency %Normalised frequency

window=kaiser(n+1); b=fir1(n,fn,window); [H,w]=freqz(b,1,128); gain=abs(H); an=angle(H); subplot(2,1,1); plot(w/pi,gain);

%Triangular window %window-based finite impulse response filter design %Compute the frequency response of filter %Absolute value and complex magnitude %Phase angle %Create axes in tiled positions %Linear 2-D plot

title('magnitude response of lpf'); %Add title to current axes xlabel('gain in dB'); subplot(2,1,2); plot(w/pi,an); title('phase response'); %PROCEDURE: %Open MATLAB 7.0 %Go to file, click on new M-file to open editor window. %Write the source code in editor window. %Save the file with '.m' extension. %Click on 'run' in debug menu to execute code. %Check for errors in command window. %Observe the output in figure window. %Label the x-axis %Create axes in tiled positions %Linear 2-D plot %Add title to current axes

%RESULT: %Observed the frequency response of FIR LPF using Kaiser window.

FREQUENCY RESPONSE OF FIP LPF USING RECTANGULAR WINDOW

%EXPERIMENT NO 8: FREQUENCY RESPONSE OF FIP LPF USING RECTANGULAR %WINDOW %NAME :V.VIKAS %R.NO : 08H61A04C2 %Aim:To obtain frequency response of FIR LPF unsing RECTANGULAR Window using %MATLAB %Apparatus:MATLAB7.0,Computer %THEORY: %A Finite Impulse Response (FIR) filter is a discrete linear time-invariant system %whose output is based on the weighted summation of a finite number of past inputs. %An FIR transversal filter structure can be obtained directly from the equation for %discrete-time convolution. %FIR filter is a finite impulse response filter. Order of the filter should be specified. %Infinite response is truncated to get finite impulse response. placing a window of %finite length does this. Types of windows available are Rectangular, Barlett, %Hamming, Hanning, Blackmann window etc. This FIR filter is an all zero filter. %SOURCE CODE: clc; clear all; close all; n=20; fp=200; fs=1000; fn=2*fp/fs; %Clear Command Window %Remove items from workspace %Remove items from workspace %Number of samples %Passband frequency %Stopband frequency %Normalised frequency

window=rectwin(n+1); b=fir1(n,fn,window); [H,w]=freqz(b,1,128); gain=abs(H); an=angle(H); subplot(2,1,1); plot(w/pi,gain);

%Rectangular window %window-based finite impulse response filter design %Compute the frequency response of filter %Absolute value and complex magnitude %Phase angle %Create axes in tiled positions %Linear 2-D plot

title('magnitude response of lpf'); %Add title to current axes xlabel('gain in dB'); subplot(2,1,2); plot(w/pi,an); title('phase response'); %PROCEDURE: %Open MATLAB 7.0 %Go to file, click on new M-file to open editor window. %Write the source code in editor window. %Save the file with '.m' extension. %Click on 'run' in debug menu to execute code. %Check for errors in command window. %Observe the output in figure window. %Label the x-axis %Create axes in tiled positions %Linear 2-D plot %Add title to current axes

%RESULT: %Observed the frequency response of FIR LPF using Rectangular window.

FREQUENCY RESPONSE OF FIP LPF USING TRIANGULAR WINDOW

%EXPERIMENT NO 9: FREQUENCY RESPONSE OF FIP LPF USING TRIANGULAR %WINDOW %NAME :V.VIKAS %R.NO : 08H61A04C2 %Aim:To obtain frequency response of FIR LPF unsing TRIANGULAR Window using %MATLAB %Apparatus:MATLAB7.0,Computer %THEORY: %A Finite Impulse Response (FIR) filter is a discrete linear time-invariant system %whose output is based on the weighted summation of a finite number of past inputs. %An FIR transversal filter structure can be obtained directly from the equation for %discrete-time convolution. %FIR filter is a finite impulse response filter. Order of the filter should be specified. %Infinite response is truncated to get finite impulse response. placing a window of %finite length does this. Types of windows available are Rectangular, Barlett, %Hamming, Hanning, Blackmann window etc. This FIR filter is an all zero filter. %SOURCE CODE: clc; clear all; close all; n=20; fp=200; fs=1000; fn=2*fp/fs; %Clear Command Window %Remove items from workspace %Remove items from workspace %Number of samples %Passband frequency %Stopband frequency %Normalised frequency

window=triang(n+1); b=fir1(n,fn,window); [H,w]=freqz(b,1,128); gain=abs(H); an=angle(H); subplot(2,1,1); plot(w/pi,gain);

%Triangular window %window-based finite impulse response filter design %Compute the frequency response of filter %Absolute value and complex magnitude %Phase angle %Create axes in tiled positions %Linear 2-D plot

title('magnitude response of lpf'); %Add title to current axes xlabel('gain in dB'); subplot(2,1,2); plot(w/pi,an); title('phase response'); %PROCEDURE: %Open MATLAB 7.0 %Go to file, click on new M-file to open editor window. %Write the source code in editor window. %Save the file with '.m' extension. %Click on 'run' in debug menu to execute code. %Check for errors in command window. %Observe the output in figure window. %Label the x-axis %Create axes in tiled positions %Linear 2-D plot %Add title to current axes

%RESULT: %Observed the frequency response of FIR LPF using Rectangular window.

TO VERIFY LINEAR CONVOLUTION USING TMS320 C6713 DSP PROCESSOR

EXPERIMENT:TO VERIFY LINEAR CONVOLUTION USING C6713DSP PROCESSOR NAME :V.VIKAS R.NO : 08H61A04C2 Aim:To verify linear convolution of any two sequences by using C6713DSP processor. Apparatus: DSP 6713 Kit ,Computer THEORY: Syntax w = conv(u,v)Descriptionw = conv(u,v) convolves vectors u and v. Algebraically, convolution is the same operation as multiplying the polynomials Then w is the vector of length m+n-1 whose k the element is The sum is over all the values of j which lead to legal subscripts for u(j) and v(k+1-j), specifically j = max(1,k+1-n): min(k,m). When m = n, this gives w(1) = u(1)*v(1) w(2) = u(1)*v(2)+u(2)*v(1) w(3) = u(1)*v(3)+u(2)*v(2)+u(3)*v(1)... w(n) = u(1)*v(n)+u(2)*v(n-1)+ ... +u(n)*v(1)... w(2*n-1) = u(n)*v(n)

SOURCE CODE: /* prg to implement linear convolution */ #include<stdio.h> #define LENGHT1 6 /*Lenght of i/p samples sequence*/ #define LENGHT2 4 /*Lenght of impulse response Co-efficients */ int x[2*LENGHT1-1]={4,3,2,1}; /*Input Signal Samples*/

};

int h[2*LENGHT1-1]={1,2,3,4}; /*Impulse Response Coefficients*/ int y[LENGHT1+LENGHT2-1]; main() { int i=0,j; for(i=0;i<(LENGHT1+LENGHT2-1);i++) { y[i]=0; for(j=0;j<=i;j++) y[i]+=x[j]*h[i-j]; } for(i=0;i<(LENGHT1+LENGHT2-1);i++) printf("%d\n",y[i]); }

PROCEDURE: Open Code Composer Studio, make sure the DSP kit is turned on. Start a new project using Project-new pull down menu, save it in a separate directory (c:\ti\myprojects) with name linc.pjt. Add the source files linc.C in the project using Project->add files to project pull down menu. Add the linker command file hello.cmd. Add the rts file rts6700.lib Compile the program using the Project-compile pull down menu or by clicking the shortcut icon on the left side of program window. Load the program in program memory of DSP chip using the File-load program pull down menu. Run the program and observe output using graph utility.

RESULT:The sequences [1 2 3 4] is given as input and named as x(n) and the sequence [4 3 2 1] is given as another input and named as h(n).the convolution of these two sequences is done and the output [4 11 20 30 20 11 4] is obtained.

TO VERIFY CIRCULAR CONVOLUTION USING TMS320C6713 DSP PROCESSOR

EXPERIMENT:TO VERIFY CIRCULAR CONVOLUTION USING TMS320C6712 DSP PROCESSOR NAME :V.VIKAS R.NO : 08H61A04C2 AIM:To generate ouput y(n) by using circular convolution(using formula) with the help of TMS320C6712 DSP processor. APPARATUS:TMS320C6713 DSP PROCESSOR,PC. THEORY: Circular convolution is used to convolve two discrete Fourier transform (DFT) sequences. For very long sequences, circular convolution may be faster than linear convolution. c = cconv(a,b,n) circularly convolves vectors a and b. n is the length of the resulting vector. If you omit n, it defaults to length(a)+length(B)-1. When n = length(a)+length(B)-1. You can also use cconv to compute the circular cross-correlation of two sequences Circular convolution is used to convolve two discrete Fourier transform(DFT) sequences. For very long sequences, circular convolution may be fasterthan linear convolution.c = cconv(a,b,n) circularlyconvolves vectors a and b. n isthe length of the resulting vector. If you omit n, it defaultsto length(a)+length(B)-1. When n = length(a)+length(B)-1,the circular convolution is equivalent to the linear convolution computedwith conv. You can also use cconv tocompute the circular cross-correlation of two sequences (see the example below).ExamplesThe following example calculates a modulo-4 circular convolution. a = [2 1 2 1]; b = [1 2 3 4]; c = cconv(a,b,4)

SOURCE CODE: #include<stdio.h> intm,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30]; void main() { printf( enter the length of the first sequence\n); scanf(%d,&m); printf( enter the length of the second sequence\n) scanf(%d,&n); printf( enter the first sequence\n); for(i=0;i<m;i++) scanf(%d,&x[i]); printf( enter the second sequence\n); for(j=0;j<n;j++) scanf(%d,&h[j]); if(m-n!=0) { If(m>n) /* pad the smaller seqeucne with zero*/ /&if length of both sequences are not eqal*/

{ for(i=n;i<m;i++) h[i]=0; n=m; } for(i=m;i<n;i++) x[i]=0; m=n; } y[0]=0; a[0]=h[0]; for(j=1;j<n;j++?) a[j]=h[n-j]; /*circular convolution*/ for(i=0;i<n;i++) y[0]+=x[i]*a[i]; /*folding h(n) to h(-n)*/

for(k=1;k<n;k++) { y[k]=0; /*circular shift*/ for(j=1;j<n;j++) x2[j]=a[j-1]; x2[0]=a[n-1]; for(i=0;i<n;i++] { a[i]=x2[i]; y[k]+=x[i]*x2[i]; } } /*displaying the result*/ printf( the circular convolution is\n); for(i=0;i<n;i++) printf(%d\t,y[i]);
}

PROCEDURE: Open Code Composer Studio, make sure the DSP kit is turned on. Start a new project using Project-new pull down menu, save it in a separate directory (c:\ti\myprojects) with name cconv.pjt. Add the source files cconv.c in the project using Project->add files to project pull down menu. Add the linker command file hello.cmd. Add the rts file rts6700.lib Compile the program using the Project-compile pull down menu or by clicking the shortcut icon on the left side of program window. Load the program in program memory of DSP chip using the File-load program pull down menu. Run the program and observe output using graph utility.

RESULT:The sequences [1 2 3 2] is given as input and named as x(n) and the sequence [1 1 1 ] is given as another input and named as h(n).the circular convolution of these two sequences is done and the output [6 5 6 7] is obtained.

TO VERIFY N-POINT FAST FOURIER TRANSFORM (FFT) ALGORITHM USING TMS320C6713 DSP PROCESSOR

EXPERIMENT:N-POINT FAST FOURIER TRANSFORMATION NAME :V.VIKAS R.NO : 08H61A04C2 Aim:To verify fast fourier transformation of a sequence using TMS320C6713 DSP processor Apparatus:TMS320C6713 DSP PROCESSOR,Computer Theory: The FFT block computes the fast Fourier transform (FFT) of each channel of a P-by-N or length-P input, u. When the Inherit FFT length from input dimensions check box is selected, the input length P must be an integer power of two, and the FFT length M is equal to P. When the check box is not selected, P can be any length, and the value of the FFT length parameter must be a positive integer power of two. For user-specified FFT lengths, when M is not equal to P, zero padding or modulo-M data wrapping happens before the FFT operation. y = fft(u,M).

SOURCE CODE: Main.c (fft 256.c): #include <math.h> #define PTS 64 #define PI 3.14159265358979 typedefstruct {float real,imag;} COMPLEX; void FFT(COMPLEX*Y<int n); floatiobuffer[PTS]; float x 1[PTS]; short i; shortbuffercount = 0; short flag = 0; COMPLEX w[PTS]; COMPLEX samples [PTS]; main() { for (i = 0 ; i<PTS ; i++) { w[i].real = cos(2*PI*i/(PTS*2.0)); //Re component of twiddle constants w[i].imag = sin(2*PI*i/(PTS*2.0)); //Im component of twiddle constants } // set up twiddle constants in w //FFT prototype //as input and output buffer //intermediate buffer //general purpose index variable //number of new samples in iobuffer //set to 1 by ISR when iobuffer full //twiddle constants stored in w //primary working buffer //# of points for FFT

for (i = 0 ; i < PTS ; i++) {

//swap buffers

iobuffer[i] = sin?(2*PI*10*i/64.0);/* 10-> freq. 64-> sampling freq*/ samples[i].real=0.0; samples[i].imag=0.0; } for (i = 0 ; i < PTS ; i++) { Samples[i].real=iobuffer[i]; //buffer with new data } for (i = 0 ; i < PTS ; i++) samples [i].imag = 0.0; FFT (samplex, PTS); for (i = 0 ; i < PTS ; i++) { x1[i] = sqrt(samples[i].real*samples[i].real +samples[i].imag*samples[i].imag); } } //end of main //imag components = 0 //call function FFT.c //compute magnitude // swap buffers

fft.c: #define PTS 64 //# of points for FFT

typedefstruct {float real.imag;} COMPLEX; extern COMPLEX w[PTS]; void FFT(COMPLEX *Y, int N) { COMPLEX temp1,temp2; inti,j,k; //temporary storage variables //twiddle constant stored in w //input sample array, # of points

//loop counter variables

intupper_leg, lower_leg; intleg_diff; intnum_stages = 0; int index, step; i = 1; do { num_stages +=1; i = i*2; }

//index of upper/lower butterfly leg

//difference between upper/lower leg //number of FFT stages (iterations) //index/step through twiddle constant //log(Base2) of N points = # of stages

while (i!=N); leg_diff=N/2; step = (PTS*2)/N; //difference between upper and lower legs //step between values in twiddle.h

for (i=0;i <num_stages; i++) //for N-point FFT { index = 0 for (j = 0; j <leg_diff; j++) for (upper_leg = j; upper_leg< N; upper_leg +=(2*leg_diff)) { lower_leg = upper_leg+leg_diff; temp1.real = (Y[upper_leg]).real + (Y[lower_leg]).real;

temp1.imag = (Y[upper_leg]).imag + (Y[lower_leg]).imag; temp2.imag = (Y[upper_leg]).real - (Y[lower_leg]).real; temp2.imag = (Y[upper_leg]).imag - (Y[lower_leg]).imag; (Y[lower_leg).real=temp2.real (w[index]).real-temp2.imag* (w[index]).imag; y[lower_leg].imag=temp2.real* (w[index].imag+temp2.imag* (w[index]).real;

(Y[upper_leg]).real = temp1.real; (Y[upper_leg]).imag = temp1.imag; } index + = step; } leg_diff = leg_diff/2; step *=2; } j = 0; for (i =1; i <(N-1) ; i++) //bit reversal for resequencing data

{ k = N/2 while (k <=j) { j = j - k; k = k/2; } j=j+k;

if (i<j) { temp1.real = (Y[j]).real; temp1.imag = (Y[j]).imag; (Y[j]).real = (Y[i]).real; (Y[j]).imag = (Y[i]).imag; (Y[i]).real = temp1.real; (Y[i]).imag = temp1.imag; } } return; }

PROCEDURE: Open Code Composer Studio, make sure the DSP kit is turned on. Start a new project using Project-new pull down menu, save it in a separate directory (c:\ti\myprojects) with name FFT.pjt. Add the source files FFT256.c and FFT.C in the project using Project->add files to project pull down menu. Add the linker command file hello.cmd. Add the rts file rts6700.lib

Compile the program using the Project-compile pull down menu or by clicking the shortcut icon on the left side of program window. Load the program in program memory of DSP chip using the File-load program pull down menu. Run the program and observe output using graph utility.

RESULT:Hence the fast fourier transformation is performed for the sequence [1 2 4 8 3 2] and the obtained magnitude response is [20 12.32 4 4.014 4 4.014 4 12.32] and the phase response is [0 -2.24 1.57 -0.42 -3.14 0.42 -1.57 2.24]. INPUT WAVEFORM:

OUTPUT WAVEFORM:

TO VERIFY POWER SPECTRAL DENSITY USING TMS320C6713 DSP PROCESSOR

EXPERIMENT: POWER SPECTRAL DENSITY NAME :V.VIKAS R.NO : 08H61A04C2 Aim:To verify power spectral density of a signal using TMS320C6713 DSP processor Apparatus: TMS320C6713 DSP processor ,Computer THEORY: The goal of spectral estimation is to describe the distribution (over frequency) of the power contained in a signal, based on a finite set of data. Estimation of power spectra is useful in a variety of applications, including the detection of signals buried in wide-band noise.The power spectral density (PSD) of a stationary random process xn is mathematically related to the correlation sequence by the discrete-time Fourier transform. In terms of normalized frequency

SOURCE CODE: #include <math.h> #define PTS 128 //# of points for FFT

#define PI 3.14159265358979 typedef struct {float real,imag;} COMPLEX; void FFT(COMPLEX *Y, int n); float iobuffer[PTS]; float x1[PTS],x[PTS]; short i; short buffercount = 0; short flag = 0; float y[128]; COMPLEX w[PTS]; COMPLEX samples[PTS]; main() { float j,sum=0.0 ; int n,k,i,a; for (i = 0 ; i<PTS ; i++) // set up twiddle constants in w //twiddle constants stored in w //primary working buffer //FFT prototype

//as input and output buffer //intermediate buffer //general purpose index variable //number of new samples in iobuffer //set to 1 by ISR when iobuffer full

{ w[i].real = cos(2*PI*i/(PTS*2.0)); //Re component of twiddle constants w[i].imag =-sin(2*PI*i/(PTS*2.0)); /*Im component of twiddle constants*/ } /****************Input Signal X(n) ********************************************************/ for(i=0,j=0;i<PTS;i++) { x[i] = sin(2*PI*5*i/PTS); samples[i].real=0.0; samples[i].imag=0.0; } /********************Auto Correlation of X(n)=R(t) *********************************/ for(n=0;n<PTS;n++) { sum=0; for(k=0;k<PTS-n;k++) { sum=sum+(x[k]*x[n+k]); // Auto Correlation R(t) } iobuffer[n] = sum; } // Signal x(Fs)=sin(2*pi*f*i/Fs);

/********************** FFT of R(t) *****************************/ for (i = 0 ; i < PTS ; i++) { samples[i].real=iobuffer[i]; //buffer with new data } for (i = 0 ; i < PTS ; i++) samples[i].imag = 0.0; FFT(samples,PTS); //imag components = 0 //call function FFT.c //swap buffers

/******************** PSD *******************************************/ for (i = 0 ; i < PTS ; i++) { x1[i] = sqrt(samples[i].real*samples[i].real + samples[i].imag*samples[i].imag); } } /*****FFT******/ #define PTS 128 //# of points for FFT //end of main //compute magnitude

typedef struct {float real,imag;} COMPLEX; extern COMPLEX w[PTS]; //twiddle constants stored in w

void FFT(COMPLEX *Y, int N) { COMPLEX temp1,temp2; int i,j,k;

//input sample array, # of points

//temporary storage variables

//loop counter variables //index of upper/lower butterfly leg

int upper_leg, lower_leg; int leg_diff; int num_stages = 0; int index, step; i = 1; do { num_stages +=1; i = i*2; }while (i!=N); leg_diff = N/2; step = (PTS*2)/N;

//difference between upper/lower leg //number of FFT stages (iterations) //index/step through twiddle constant //log(base2) of N points= # of stages

//difference between upper&lower legs //step between values in twiddle.h // 512

for (i = 0;i < num_stages; i++) //for N-point FFT { index = 0; for (j = 0; j < leg_diff; j++) { for (upper_leg = j; upper_leg < N; upper_leg += (2*leg_diff)) {

lower_leg = upper_leg+leg_diff; temp1.real = (Y[upper_leg]).real + (Y[lower_leg]).real; temp1.imag = (Y[upper_leg]).imag + (Y[lower_leg]).imag; temp2.real = (Y[upper_leg]).real - (Y[lower_leg]).real; temp2.imag = (Y[upper_leg]).imag - (Y[lower_leg]).imag; (Y[lower_leg]).real = temp2.real*(w[index]).real -temp2.imag*(w[index]).imag; (Y[lower_leg]).imag = temp2.real*(w[index]).imag +temp2.imag*(w[index]).real; (Y[upper_leg]).real = temp1.real; (Y[upper_leg]).imag = temp1.imag; } index += step; } leg_diff = leg_diff/2; step *= 2; } j = 0; for (i = 1; i < (N-1); i++) { k = N/2; while (k <= j) { //bit reversal for resequencing data

j = j - k; k = k/2; } j = j + k; if (i<j) { temp1.real = (Y[j]).real; temp1.imag = (Y[j]).imag; (Y[j]).real = (Y[i]).real; (Y[j]).imag = (Y[i]).imag; (Y[i]).real = temp1.real; (Y[i]).imag = temp1.imag; } } return; }

PROCEDURE: Open Code Composer Studio, make sure the DSP kit is turned on. Start a new project using Project-new pull down menu, save it in a separate directory (c:\ti\myprojects) with name psd.pjt. Add the source files psd.c and FFT.C in the project using Project->add files to project pull down menu. Add the linker command file hello.cmd. Add the rts file rts6700.lib Compile the program using the Project-compile pull down menu or by clicking the shortcut icon on the left side of program window. Load the program in program memory of DSP chip using the File-load program pull down menu. Run the program and observe output using graph utility.

RESULT: I verified the power spectral density of a signal using TMS320C6713 DSP processor.

INPUT SIGNAL:

OUTPUT SIGNAL:

TO VERIFY FIR FILTER USING TMS320C6713 DSP PROCESSOR

EXPERIMENT:FIR FILTERS NAME :V.VIKAS R.NO : 08H61A04C2 Aim:To verify FIR(finite impulse response) filters using TMS320C6713 DSP processor Apparatus:TMS320C6713 DSP PROCESSOR,Computer Theory: A finite impulse response (FIR) filter is a type of a signal processing filter whose impulse response (or response to any finite length input) is of finite duration, because it settles to zero in finite time. The impulse response of an Nth-order discrete-time FIR filter lasts for N+1 samples, and then dies to zero. FIR filters can be discrete-time or continuous-time, and digital or analog. For a discrete-time FIR filter, the output is a weighted sum of the current and a finite number of previous values of the input. The operation is described by the following equation, which defines the output sequence y[n] in terms of its input sequence x[n]:

SOURCE CODE: #include<stdio.h> #include<math.h> #define pi 3.1415 int n,N,c; float wr[64],wt[64]; void main() {

printf("\n enter no. of samples,N= :"); scanf("%d",&N); printf("\n enter choice of window function\n 1.rect \n 2. triang \n c= :"); scanf("%d",&c); printf("\n elements of window function are:"); switch(c) { case 1: for(n=0;n<=N-1;n++) { wr[n]=1; printf(" \n wr[%d]=%f",n,wr[n]); } break; case 2: for(n=0;n<=N-1;n++) { wt[n]=1-(2*(float)n/(N-1)); printf("\n wt[%d]=%f",n,wt[n]); } break; }}

PROCEDURE: Open Code Composer Studio, make sure the DSP kit is turned on. Start a new project using Project-new pull down menu, save it in a separate directory (c:\ti\myprojects) with name firf.pjt. Add the source files firf.c in the project using Project->add files to project pull down menu. Add the linker command file hello.cmd. Add the rts file rts6700.lib Compile the program using the Project-compile pull down menu or by clicking the shortcut icon on the left side of program window. Load the program in program memory of DSP chip using the File-load program pull down menu. Run the program and observe output using graph utility.

RESULT: I verified FIR(finite impulse response) filter using TMS320C6713 DSP processor.

TO VERIFY IIR USING TMS320C6713 DSP PROCESSOR

EXPERIMENT: IIR FILTERS NAME :V.VIKAS R.NO : 08H61A04C2 Aim:To verify IIR (infinite impulse response) filters using TMS320C6713 DSP processor Apparatus: TMS320C6713 DSP processor ,Computer THEORY: Infinite impulse response (IIR) is a property of signal processing systems. Systems with this property are known as IIR systems or, when dealing with filter systems, as IIR filters. IIR systems have an impulse response function that is non-zero over an infinite length of time. This is in contrast to finite impulse response (FIR) filters, which have fixed-duration impulse responses. The simplest analog IIR filter is an RC filter made up of a single resistor (R) feeding into a node shared with a single capacitor (C). This filter has an exponential impulse response characterized by an RC time constant. IIR filters may be implemented as either analog or digital filters. In digital IIR filters, the output feedback is immediately apparent in the equations defining the output. Note that unlike FIR filters, in designing IIR filters it is necessary to carefully consider the "time zero" case in which the outputs of the filter have not yet been clearly defined.

SOURCE CODE: #include<stdio.h> #include<math.h> int i,w,wc,c,N; float H[100]; float mul(float, int);

void main() { printf("\n enter order of filter "); scanf("%d",&N); printf("\n enter the cutoff freq "); scanf("%d",&wc); printf("\n enter the choice for IIR filter 1. LPF 2.HPF "); scanf("%d",&c); switch(c) { case 1: for(w=0;w<100;w++) { H[w]=1/sqrt(1+mul((w/(float)wc),2*N)); printf("H[%d]=%f\n",w,H[w]); } break; case 2: for(w=0;w<=100;w++) { H[w]=1/sqrt(1+mul((float)wc/w,2*N)); printf("H[%d]=%f\n",w,H[w]); }

break; }} float mul(float a,int x) {

PROCEDURE: Open Code Composer Studio, make sure the DSP kit is turned on. Start a new project using Project-new pull down menu, save it in a separate directory (c:\ti\myprojects) with name iirf.pjt. Add the source files iirf.c in the project using Project->add files to project pull down menu. Add the linker command file hello.cmd. Add the rts file rts6700.lib Compile the program using the Project-compile pull down menu or by clicking the shortcut icon on the left side of program window. Load the program in program memory of DSP chip using the File-load program pull down menu. Run the program and observe output using graph utility.

RESULT: I verified IIR (infinite impulse response) LPF/HPF filters using TMS320C6713 DSP processor.

LPF(low pass filter) OUTPUT:

HPF(high pass filter) OUTPUT: