EXPERIMENTS USING DSP KIT

1)LINEAR CONVOLUTION:


#include<stdio.h>
#include<math.h>
int y[20];
main()
{
int m=6;
int n=6;
int i=0,j;
int x[15]={1,2,3,4,5,6,0,0,0,0,0,0};
int h[15]={1,2,3,4,5,6,0,0,0,0,0,0};
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
y[i]+=x[j]*h[i-j];
}
printf("linear convolution\n");
for(i=0;i<m+n-1;i++)
printf("%d\n",y[i]);
}


2)CIRCULAR CONVOLUTION:

#include<stdio.h>
#include<math.h>
int m,n,x[30],h[30],i,j,temp[30],y[30],k,x2[30],a[30];
void main
{
printf("Enter the length of first sequence\n");
scanf("%d",&m);
printf("Enter the length of 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)
{
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];
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]);
}


3)N POINT DSP OF SEQUENCE:


#include<stdio.h>
#include<math.h>
int x[8];
void dft(int *x,int k,int *out);
const int n=8;
float pi=3.1416;
float sumre,sumim;
int x[]={1,2,3,4,5,6,7,8};
//short x[n]={0,602,974,602,0,-602,-974,-602,0,602,974,602,0,-602,-974,-602};
int out[2]={0,0};
float real[8],imag[8],k=8;
void main()
{
int j;
dft(x,k,out);
printf("real part is :/n/n");
for(j=0;j<8;j++)
printf("%4f\n",real[j]);
printf("Imaginary part is:\n\n");
for(j=0;j<8;j++)
printf("%4f\n",imag[j]);
}
void dft(int *x,int k,int *out)
{
int temp;
for(temp=0;temp<k;temp++)
{
float sumre=0,sumim=0;
float cs=0,sn=0;
int i;
for(i=0;i<n;i++)
{
cs=cos(2*pi*(temp)*i/n);
sn=sin(2*pi*(temp)*i/n);
sumre=sumre+x[i]*cs;
sumim=sumim-x[i]*sn;
}
out[0]=sumre;
out[1]=sumim;
real[temp]=sumre;
imag[temp]=sumim;
//k++;
//if(k>n) k=0;
//printf("\n%d",sumre);
//printf("\n%d",sumim);
//printf("\n%d",out[0]);
//printf("\n%d",out[1]);
}
}
 


4)IMPLEMENTATION OF FIR FILTERS:


#include "fircfg.h"

#include "C:\CCStudio_v3.1\C6000\dsk6713\include\dsk6713.h"
#include "C:\CCStudio_v3.1\C6000\dsk6713\include\dsk6713_aic23.h"

float filter_Coeff[] ={0.000000,-0.001591,-0.002423,0.000000,0.005728,0.011139,0.010502,
-0.000000,-0.018003,-0.033416,-0.031505,0.000000,0.063010,0.144802,0.220534,0.262448,
0.220534,0.144802,0.063010,0.000000,-0.031505,-0.033416,-0.018003,-0.000000,0.010502,
0.011139,0.005728,0.000000,-0.002423,-0.001591,0.000000


};

static short in_buffer[100];


DSK6713_AIC23_Config config = { \
0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \
0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\
0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */ \
0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \
0x0015, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */ \
0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */ \
0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */ \
0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */ \
0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */ \
0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \
};


/*
* main() - Main code routine, initializes BSL and generates tone
*/

void main()
{
DSK6713_AIC23_CodecHandle hCodec;

Uint32 l_input, r_input,l_output, r_output;

/* Initialize the board support library, must be called first */
DSK6713_init();

/* Start the codec */
hCodec = DSK6713_AIC23_openCodec(0, &config);

DSK6713_AIC23_setFreq(hCodec, 1);

while(1)
{ /* Read a sample to the left channel */
while (!DSK6713_AIC23_read(hCodec, &l_input));

/* Read a sample to the right channel */
while (!DSK6713_AIC23_read(hCodec, &r_input));

l_output=(Int16)FIR_FILTER(&filter_Coeff ,l_input);
r_output=l_output;

/* Send a sample to the left channel */
while (!DSK6713_AIC23_write(hCodec, l_output));

/* Send a sample to the right channel */
while (!DSK6713_AIC23_write(hCodec, r_output));
}

/* Close the codec */
DSK6713_AIC23_closeCodec(hCodec);
}


signed int FIR_FILTER(float * h, signed int x)
{
int i=0;
signed long output=0;

in_buffer[0] = x; /* new input at buffer[0] */

for(i=29;i>0;i--)
in_buffer[i] = in_buffer[i-1]; /* shuffle the buffer */

for(i=0;i<31;i++)
output = output + h[i] * in_buffer[i];

return(output);

}

5)IMPLEMENTATION OF IIR FILTERS:






#include "IIRcfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"

const signed int filter_Coeff[] =
{
//12730,-12730,12730,32767,-18324,21137 /*HP 2500 */
312,312,312,32767,-27943,24367 /*LP 800 */
//1455,1455,1455,32767,-23140,21735 /*LP 2500 */
//9268,-9268,9268,32767,-7395,18367 /*HP 4000*/
//7215,-7215,7215,32767,5039,6171, /*HP 7000*/

};

/* Codec configuration settings */
DSK6713_AIC23_Config config = { \
0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \
0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\
0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */ \
0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \
0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */ \
0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */ \
0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */ \
0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */ \
0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */ \
0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \
};


/*
* main() - Main code routine, initializes BSL and generates tone
*/
int i, c[1000];
void main()
{
DSK6713_AIC23_CodecHandle hCodec;

int l_input, r_input, l_output, r_output;

/* Initialize the board support library, must be called first */
DSK6713_init();

/* Start the codec */
hCodec = DSK6713_AIC23_openCodec(0, &config);

DSK6713_AIC23_setFreq(hCodec, 3);

while(1)
{ /* Read a sample to the left channel */
while (!DSK6713_AIC23_read(hCodec, &l_input));

/* Read a sample to the right channel */
while (!DSK6713_AIC23_read(hCodec, &r_input));
l_output=(Int16)IIR_FILTER(&filter_Coeff ,l_input);
for (i=0; i<1000; i++)
{

r_output=l_output;
c[i]= r_output;
}
/* Send a sample to the left channel */
while (!DSK6713_AIC23_write(hCodec, l_output));

/* Send a sample to the right channel */
while (!DSK6713_AIC23_write(hCodec, r_output ));
}


/* Close the codec */
DSK6713_AIC23_closeCodec(hCodec);
}


signed int IIR_FILTER(const signed int * h, signed int x1)
{
static signed int x[6] = { 0, 0, 0, 0, 0, 0 }; /* x(n), x(n-1), x(n-2). Must be static */
static signed int y[6] = { 0, 0, 0, 0, 0, 0 }; /* y(n), y(n-1), y(n-2). Must be static */
int temp=0;

temp = (short int)x1; /* Copy input to temp */

x[0] = (signed int) temp; /* Copy input to x[stages][0] */

temp = ( (int)h[0] * x[0]) ; /* B0 * x(n) */

temp += ( (int)h[1] * x[1]); /* B1/2 * x(n-1) */
temp += ( (int)h[1] * x[1]); /* B1/2 * x(n-1) */
temp += ( (int)h[2] * x[2]); /* B2 * x(n-2) */

temp -= ( (int)h[4] * y[1]); /* A1/2 * y(n-1) */
temp -= ( (int)h[4] * y[1]); /* A1/2 * y(n-1) */
temp -= ( (int)h[5] * y[2]); /* A2 * y(n-2) */

/* Divide temp by coefficients[A0] */

temp >>= 15;

if ( temp > 32767 )
{
temp = 32767;
}
else if ( temp < -32767)
{
temp = -32767;
}
y[0] = temp ;

/* Shuffle values along one place for next time */

y[2] = y[1]; /* y(n-2) = y(n-1) */
y[1] = y[0]; /* y(n-1) = y(n) */

x[2] = x[1]; /* x(n-2) = x(n-1) */
x[1] = x[0]; /* x(n-1) = x(n) */

/* temp is used as input next time through */

return (temp<<2);
}




Procedure for Real time Programs :


1.      Connect a Signal Generator/audio input to the LINE IN Socket or connect a microphone to the MIC IN Socket.

Note:- To use microphone input change the analog audio path control register value (Register no. 4) in Codec Configuration settings of the Source file (Codec.c) from 0x0011  to 0x0015.

2.      Connect CRO/Desktop Speakers to the Socket Provided for LINE OUT or connect a headphone to the Headphone out Socket.

3.      Now Switch on the DSK and Bring Up Code Composer Studio on the PC.

4.      Use the Debug à Connect menu option to open a debug connection to the DSK board

5.      Create a new project with name codec.pjt.

6.      Open the File Menu è new è DSP/BIOS Configuration èselect
      dsk6713.cdb” and save it as “xyz.cdb

7.      Add “xyz.cdb” to the current project.

Projectà Add files to project àxyz.cdb

8.      Automatically three files are added in the Generated file folder in project pane
xyzcfg.cmdà Command and linking file
xyzcfg.s62 à optimized assembly code for configuration
xyzcfg_c.c à Chip support initialization

9.      Open the File Menu è new è Source file
10.  Type the code in editor window. Save the file in project folder. (Eg: Codec.c).

Important note: Save your source code with preferred language extension. For ASM codes save the file as code(.asm) For C and C++ codes code (*.c,*.cpp) respectively.


11.  Add the saved “Codec.c” file to the current project which has the main function and calls all the other necessary routines.
              Project à Add files to Project à Codec.c

12.  Add the library file “dsk6713bsl.lib  to the current project
     Path à  C:\CCStudio_v3.1\C6000\dsk6713\lib\dsk6713bsl.lib
      Files of type   à Object and library files (*.o*, *.l*)


13.  Copy header files “dsk6713.h” and “dsk6713_aic23.h” from and paste it in current project folder.
                     C:\CCStudio_v3.1\C6000\dsk6713\include.

14.  Add the header file generated within  xyzcfg_c.c to codec.c

Note:- Double click on xyzcfg_c.c. Copy the first line header (eg.#include “xyzcfg.h”) and paste that in source file (eg.codec.c).
       
15.  Compile  the program using the ‘Project-compile’ pull down menu or by 
      Clicking the shortcut icon on the left side of program window.

16.  Build the program using the ‘Project-Build’ pull down menu or by clicking the shortcut icon on the left side of program window.

17.  Load the program (Codec. Out) in program memory of DSP chip using the
File-load program’ pull down menu.

18.  Debugà Run

19.  You can notice the input signal of 500 Hz. appearing on the CRO verifying the codec configuration.
20.  You can also pass an audio input and hear the output signal through the speakers.
21.  You can also vary the sampling frequency using the DSK6713_AIC23_setFreq Function in the “codec.c” file and repeat the above steps.


EXPERIMENTS USING MATLAB:

1)CORRELATION:

x=input('Enter the first input');
h=input('Enter the second input');
y=xcorr(x,h)
z=xcorr(h,x)
l1=length(x);
l2=length(h);
l=max(l1,l2);
n1=0:1:l1-1;
n2=0:1:l2-1;
n3=-l+1:1:l-1;
subplot(411),stem(n1,x),xlabel('time'),ylabel('amplitude');
subplot(412),stem(n2,h),xlabel('time'),ylabel('amplitude');
subplot(413),stem(n3,y),xlabel('time'),ylabel('amplitude');
subplot(414),stem(n3,z),xlabel('time'),ylabel('amplitude');


2)MOVING AVERAGE FILTER:

v=.01;
f=input('enter input signal frequency');
fs=input('enter sampling frequency');
t=0:(1/fs):.03;
x=sin(2*pi*f*t);%originalsignal
r=sqrt(v)*randn(1,length(t));%noise
xw=x+r;
for n=3:length(xw)
y(n)=(xw(n)+(xw(n-1))+(xw(n-2)))/3;
end
plot(t,x,'K',t,y,'m',t,r,'k',t,xw,'g');
legend('input','output','noise','signal+noise');
  
3)BUTTERWORTH IIR FILTERS:

A) BUTTERWORTH DIGITAL IIR LOW PASS FILTER:

rp=input('enter pass band ripple');
rs=input('enter stop band ripple');
wp=input('enter the pass band frequency');
ws=input('enter the stop band frequency');
fs=input('enter smapling frequency');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn);
w=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');
title('frequency responce');
subplot(2,1,2); plot(om/pi,an);
ylabel('phase in radians-->');
xlabel('(b) normalized frequency');
title('phase responce');



B)BUTTERWORTH HIGH PASS FILTER:

format long
rp=input('enter the pass band frrequency');
rs=input('enter the stop band ripple');
wp=input('enter the stop band frequency');
ws=input('enter the stop band fequency');
fs=input('enter the sampling frequency');
w1=2*wp/fs;
w2=2*ws/fs;
[n.wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn,'high');
w=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');
title('frequency responce')
subplot(2,1,2); plot(om/pi,an);
ylabel('phase in radians-->');
xlabel('(b)normalized frequency');
title('phase responce');
4)CHEBYSHEV IIR FILTERS:

LOW PASS:

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;
[n,wn]=cheb1ord(w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn);
w=0:0.01:pi;
[h,om]=freqz(b,a,w)
m=20*log(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);
ylabel('phase in radians');
xlabel('(a) normalized frequency');
 
 HIGH PASS:

format long
rp=input('enter the pass band ripple');
rp=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;
[n,wn]=cheb1ord(w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn,'high')
w=0:0.01:pi;
[h,om]=frreqz(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);
ylabel('phase in radians');
xlabel('(b) normalized frequency');

 

 BAND PASS:

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;
[n]=cheb1ord(w1,w2,rp,rs);
wn=[w1,w2];
[b,a]=cheby1(n,rp,wn,'bandpass');
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);
ylabel('phase in radians-->');
xlabel('(b) normalized frequency');


BANDSTOP:

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;
[n]=cheb1ord(w1,w2,rp,rs);
wn=[w1,w2];
[b,a]=cheby1(n,rp,wn,'stop');
w=0:0.01:pi;
[h,om]=freqz(b,a,w)
m=20*log(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);
ylabel('phase in radians-->');
  

5)FIR USING WINDOWING TECHNIQUES:

RECTANGULAR WINDOW:

'rectangular window'
close all;
clear;
clc;
format long
rp=input('enter the pass band ripple');
rs=input('enter the stop band ripple');
fp=input('enter the pass band frequency');
fs=input('enter the stop band frequency');
f=input('enter the sampling frequency');
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
y=boxcar(n1);
%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('(a) normalized frequency');
title('low pass response');
%high pass 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('(b) normalized frequency');
title('high pass response');
%band pass filter'%
wn=[wp,ws];
b=fir1(n,wn,'bandpass',y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);plot(om/pi,m);
ylabel('gain in db-->');
xlabel('(c) normalized frequency');
title('band pass filter');
%band stop filter%
b=fir1(n,wn,'stop',y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);plot(om/pi,m);
ylabel('gain in db-->');
xlabel('(d) normalized frequency');
title('band stop filter');


BARLETT WINDOW:

'bartlett window'
close all;
clear;
clc;
format long
rp=input('enter the pass band ripple');
rs=input('enter the stop band ripple');
fp=input('enter the pass band frequency');
fs=input('enter the stop band frequency');
f=input('enter the sampling frequency');
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
y=bartlett(n1);
%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('(a) normalized frequency');
title('low pass response');
%high pass 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('(b) normalized frequency');
title('high pass response');
%band pass filter'%
wn=[wp,ws];
b=fir1(n,wn,'bandpass',y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);plot(om/pi,m);
ylabel('gain in db-->');
xlabel('(c) normalized frequency');
title('band pass filter');
%band stop fl ter %
b=fir1(n,wn,'stop',y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);plot(om/pi,m);
ylabel('gain in db-->');
xlabel('(d) normalized frequency');
title('band stop filter');  
 

HAMMING WINDOW:

'hamming window'
close all;
clear;
clc;
format long
rp=input('enter the pass band ripple');
rs=input('enter the stop band ripple');
fp=input('enter the pass band frequency');
fs=input('enter the stop band frequency');
f=input('enter the sampling frequency');
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
y=hamming(n1);
%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('(a) normalized frequency');
title('low pass response');
%high pass 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('(b) normalized frequency');
title('high pass response');
%band pass filter'%
wn=[wp,ws];
b=fir1(n,wn,'bandpass',y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);plot(om/pi,m);
ylabel('gain in db-->');
xlabel('(c) normalized frequency');
title('band pass filter');
%band stop filter%
b=fir1(n,wn,'stop',y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);plot(om/pi,m);
ylabel('gain in db-->');
xlabel('(d) normalized frequency');
title('band stop filter');
  

 
BLACKMAN WINDOW: 

'blackman window'
close all;
clear;
clc;
format long
rp=input('enter the pass band ripple');
rs=input('enter the stop band ripple');
fp=input('enter the pass band frequency');
fs=input('enter the stop band frequency');
f=input('enter the sampling frequency');
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
y=blackman(n1);
%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('(a) normalized frequency');
title('low pass response');
%high pass 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('(b) normalized frequency');
title('high pass response');
%band pass filter'%
wn=[wp,ws];
b=fir1(n,wn,'bandpass',y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);plot(om/pi,m);
ylabel('gain in db-->');
xlabel('(c) normalized frequency');
title('band pass filter');
%band stop filter%
b=fir1(n,wn,'stop',y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);plot(om/pi,m);
ylabel('gain in db-->');
xlabel('(d) normalized frequency');
title('band stop filter');


6)POWER SPECTRAL DENSITY OF A SEQUENCE :

%number of samples%
N=input('enter the no of samples of input sequence');
%crate data with filter%
num=1;
den=[1 -0.5 0.2];
x=filter(num,den,randn(1,N));
%do ('lpc analasys to estimate inverse filter')%
[den_hat,num_hat]=lpc(x,2);
den_hat=real(den_hat);
num_hat=sqrt(num_hat);
%caluclate num parametric power spectrum%
sxx=abs(fft(x,2*N)/(2*N)).^2;
%clauclate a parametric power spectrum%
sxx_parametric=(abs(fft(impz(num_hat,den_hat,2*N))).^2)/(2*N);
%plot results%
plot(sxx);
hold;
plot(sxx_parametric,'ro');
hold;
 

 
 


 


 


 
 
;