Sie sind auf Seite 1von 15

DIGITAL SIGNAL PROCESSING LABORATORY 10MTL78

DIGITAL SIGNAL PROCESSING LABORATORY 10MTL78


CONTENTS
PART A: MATLAB
PROGRAM 01: GENERATION OF BASIC SIGNALS PROGRAM 02: LINEAR CONVOLUTION OF TWO SIGNALS PROGRAM 03: LINEAR CONVOLUTION OF TWO SIGNALS USING FFT & IFFT PROGRAM 04: AUTO CORRELATION OF A SEQUENCE PROGRAM 05: CROSS CORRELATION OF TWO SEQUENCES PROGRAM 06: N POINT DFT PROGRAM 07: IMPULSE RESPONSE OF A SYSTEM PROGRAM 08: DIFFERENCE EQUATION PROGRAM 09: BUTTERWORTH IIR FILTER PROGRAM 10: CHEBYSHEV IIR FILTER PROGRAM 11: FIR FILTER USING RECTANGULAR WINDOW PROGRAM 12: CIRCULAR CONVOLUTION OF TWO SIGNALS PROGRAM 13: CIRCULAR CONVOLUTION OF TWO SIGNALS USING FFT& IFFT PROGRAM 14: SAMPLING THEOREM 2 2 3 3 4 4 4 5 5 7 9 10 10 11

PART B: CODE COMPOSER STUDIO


PROGRAM 01: LINEAR CONVOLUTION OF TWO SIGNALS PROGRAM 02: CIRCULAR CONVOLUTION OF TWO SIGNALS PROGRAM 03: DIFFERENCE EQUATION PROGRAM 04: N POINT DFT PROGRAM 05: IMPULSE RESPONSE OF A SYSTEM 12 12 13 13 14

DIGITAL SIGNAL PROCESSING LABORATORY 10MTL78

DIGITAL SIGNAL PROCESSING LABORATORY 10MTL78

PART A PROGRAM 01: GENERATION OF BASIC SIGNALS


Write a MATLAB program to generate the basic signals: impulse, step, ramp, sine and exponential. IMPULSE x=[-2 -1 0 1 2]; y=[0 0 1 0 0]; subplot(2,3,1); plot(x,y); grid on; title('IMPULSE SIGNAL'); xlabel('TIME'); ylabel('AMPLITUDE'); STEP x1=[-2 -1 0 1 2]; y1=[0 0 1 1 1]; subplot(2,3,2); plot(x1,y1); grid on; title('STEP SIGNAL'); xlabel('TIME'); ylabel('AMPLITUDE'); RAMP x3=[0 1 2 3 4]; y3=[0 1 2 3 4]; subplot(2,3,3); plot(x3,y3); grid on; title('RAMP SIGNAL'); xlabel('TIME'); ylabel('AMPLITUDE'); SINE a=5; f=0.1; t=0:0.5:20; p=0; s=a*sin(2*pi*f*t+p); subplot(2,3,4) grid on; plot(t,s); title('SINE SIGNAL'); xlabel('TIME'); ylabel('AMPLITUDE'); EXPONENTIAL a2=pi; n=[0:10]; y=exp(a2*n); subplot(2,3,5); plot(n,y); grid on; title('EXPONENTIAL SIGNAL'); xlabel('TIME'); ylabel('AMPLITUDE'); a3=-pi; n=[0:10]; y=exp(a3*n); subplot(2,3,6); plot(n,y); grid on; title('EXPONENTIAL SIGNAL'); xlabel('TIME'); ylabel('AMPLITUDE');

PROGRAM 02: LINEAR CONVOLUTION OF TWO SIGNALS


Write a MATLAB program to perform linear convolution of two signals. x=input('INPUT THE FIRST SEQUENCE'); n1=length(x); u1=0:n1-1; subplot(2,2,1); stem(u1,x); grid on; title('FIRST SEQUENCE'); xlabel('TIME'); ylabel('AMPLITUDE'); h=input('INPUT THE SECOND SEQUENCE'); n2=length(h); u2=0:n2-1; subplot(2,2,2); stem(u2,h); grid on; title('SECOND SEQUENCE'); xlabel('TIME'); ylabel('AMPLITUDE'); y1=conv(x,h); u=0:length(y1)-1; subplot(2,2,3); stem(u,y1); grid on; title('CONVOLOUTION'); xlabel('TIME'); ylabel('AMPLITUDE');
2

DIGITAL SIGNAL PROCESSING LABORATORY 10MTL78

PROGRAM 03: LINEAR CONVOLUTION OF TWO SIGNALS USING FFT & IFFT
Write a MATLAB program to perform linear convolution of two signals using FFT and IFFT. x=input('INPUT THE FIRST SEQUENCE'); n1=length(x); u1=0:n1-1; subplot(2,2,1); stem(u1,x); grid on; title('FIRST SEQUENCE'); xlabel('TIME'); ylabel('AMPLITUDE'); h=input('INPUT THE SECOND SEQUENCE'); n2=length(h); u2=0:n2-1; subplot(2,2,2); stem(u2,h); grid on; title('SECOND SEQUENCE'); xlabel('TIME'); ylabel('AMPLITUDE'); n=n1+n2-1; x1=fft(x,n); x2=fft(h,n); u=0:n-1; y=x1.*x2 y1=ifft(y,n); subplot(2,2,3); stem(u,y1); grid on; title('CONVOLOUTION'); xlabel('TIME'); ylabel('AMPLITUDE');

PROGRAM 04: AUTO CORRELATION OF A SEQUENCE


Write a MATLAB program to perform auto correlation of a sequence, and to prove the energy and symmetry property. x=input('INPUT THE A SEQUENCE'); u1=0:length(x)-1; subplot(2,1,1); stem(u1,x); grid on; title('INPUT SEQUENCE'); xlabel('TIME'); ylabel('AMPLITUDE'); r=xcorr(x,x) u2=0:length(r)-1; subplot(2,1,2); stem(u2,r); grid on; title('AUTO CORELATED SEQUENCE'); xlabel('TIME'); ylabel('AMPLITUDE'); e=sum(x.^2) ci=ceil(length(r)/2); if(r(ci)==e) display('ENERGY PROPERTY PROVED'); else display('ENERGY PROPERTY NOT PROVED'); end; t1=ci; t2=ci; if(r(t1)==r(t2)) display('SYMMETRY PROPERTY PROVED'); else display('SYMMETRY PROPERTY NOT PROVED'); end

DIGITAL SIGNAL PROCESSING LABORATORY 10MTL78

PROGRAM 05: CROSS CORRELATION OF TWO SEQUENCES


Write a MATLAB program to perform cross correlation of two sequences. x=input('INPUT THE FIRST SEQUENCE'); u1=0:length(x)-1; subplot(2,2,1); stem(u1,x); grid on; title('FIRST SEQUENCE'); xlabel('TIME'); ylabel('AMPLITUDE'); y=input('INPUT THE SECOND SEQUENCE'); u2=0:length(y)-1; subplot(2,2,2); stem(u2,y); grid on; title('SECOND SEQUENCE'); xlabel('TIME'); ylabel('AMPLITUDE'); r=xcorr(x,y) u3=0:length(r)-1; subplot(2,2,3); stem(u3,r); title('CROSS CORELATED SEQUENCE'); xlabel('TIME'); ylabel('AMPLITUDE');

PROGRAM 06: N POINT DFT


Write a MATLAB program to find the N point DFT of the given sequence. x=input('INPUT A SEQUENCE'); N=length(x); n=0:N-1; k=n'; subplot(2,2,1); stem(n,x); title('INPUT SEQUENCE'); xlabel('TIME'); ylabel('AMPLITUDE'); w=exp(-j*2*pi*k*n/N) x=w*x' subplot(2,2,2); stem(n,x); grid on; title('OUTPUT SEQUENCE'); xlabel('TIME'); ylabel('AMPLITUDE'); m=abs(x) subplot(2,2,3); stem(n,m); grid on; title('MAGNITUDE'); xlabel('TIME'); ylabel('AMPLITUDE'); p=angle(x) subplot(2,2,4); stem(n,p); grid on; title('PHASE'); xlabel('TIME'); ylabel('AMPLITUDE');

PROGRAM 07: IMPULSE RESPONSE OF A SYSTEM


Write a MATLAB program to generate the impulse response of a system. N=input(ENTER NUMBER OF SAMPLES:); subplot(1,2,1); u1=0:length(n)-1; stem(u1, n); grid on; title(IMPULSE SIGNAL); xlabel(TIME); ylabel(AMPLITUDE); b=[1, -1/3]; a=[1 -3/4, 1/8]; h=impz(b,a,n) subplot(1,2,2); u2=0:length(h)-1; stem(u2, h); grid on; title(IMPULSE RESPONSE); xlabel(TIME); ylabel(AMPLITUDE);

DIGITAL SIGNAL PROCESSING LABORATORY 10MTL78

PROGRAM 08: DIFFERENCE EQUATION


Write a MATLAB program to solve a difference equation. x1=[zeros(1,5),ones(1,15)]; x2=[zeros(1,10),ones(1,10)]; xi=x1-x2; n=0:19; subplot(2,2,1); stem(n,x1); grid on; title('FIRST INPUT SEQUENCE'); xlabel('TIME'); ylabel('AMPLITUDE'); subplot(2,2,2); stem(n,x2); grid on; title('SECOND INPUT SEQUENCE'); xlabel('TIME'); ylabel('AMPLITUDE'); subplot(2,2,3); stem(n,xi); grid on; title('DIFFERENCE OF INPUT SEQUENCES'); xlabel('TIME'); ylabel('AMPLITUDE'); a=[1,-3/4,1/8]; b=[1,-1/3]; h=filter(b,a,xi) subplot(2,2,4); plot(n,h); grid on; title('DIFFERENCE EQUATION'); xlabel('TIME'); ylabel('AMPLITUDE');

PROGRAM 9.A: BUTTERWORTH LOW PASS DIGITAL IIR FILTER


Write a MATLAB program to implement Butterworth low pass digital IIR filter. rp=input('PASSBAND ATTENUATION='); rs=input('STOPBAND ATTENUATION='); wp=input('PASSBAND FREQUENCY='); ws=input('STOPBAND FREQUENCY='); fs=input('SAMPLING FREQUENCY='); w1=2*wp/fs; w2=2*ws/fs; [n,wn]=buttord(w1,w2,rp,rs); [b,a]=butter(n,wn); w=0.0:0.01:pi; [h,om]=freqz(b,a,w); m=20*log10(abs(h)); ph=angle(h); subplot(2,1,1); plot(om/pi,m); grid on; title('MAGNITUDE RESPONSE'); xlabel('NORMAL FREQUENCY'); ylabel('GAIN'); subplot(2,1,2); plot(om/pi,ph); grid on; title('FREQUENCY RESPONSE'); xlabel('NORMAL FREQUENCY'); ylabel('GAIN'); n

DIGITAL SIGNAL PROCESSING LABORATORY 10MTL78

PROGRAM 9.B: BUTTERWORTH HIGH PASS DIGITAL IIR FILTER


Write a MATLAB program to implement Butterworth high pass digital IIR filter. rp=input('PASSBAND ATTENUATION='); rs=input('STOPBAND ATTENUATION='); wp=input('PASSBAND FREQUENCY='); ws=input('STOPBAND FREQUENCY='); fs=input('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.0:0.01:pi; [h,om]=freqz(b,a,w); m=20*log10(abs(h)); ph=angle(h); subplot(2,1,1); plot(om/pi,m); grid on; title('MAGNITUDE RESPONSE'); xlabel('NORMAL FREQUENCY'); ylabel('GAIN'); subplot(2,1,2); plot(om/pi,ph); grid on; title('FREQUENCY RESPONSE'); xlabel('NORMAL FREQUENCY'); ylabel('GAIN'); n

PROGRAM 9.C: BUTTERWORTH BAND PASS DIGITAL IIR FILTER


Write a MATLAB program to implement Butterworth band pass digital IIR filter. rp=input('PASSBAND ATTENUATION='); rs=input('STOPBAND ATTENUATION='); wp=input('PASSBAND FREQUENCY='); ws=input('STOPBAND FREQUENCY='); fs=input('SAMPLING FREQUENCY='); w1=2*wp/fs; w2=2*ws/fs; [n,wn]=buttord(w1,w2,rp,rs); wn=[0.3 0.74315]; [b,a]=butter(n,wn); w=0.0:0.01:pi; [h,om]=freqz(b,a,w); m=20*log10(abs(h)); ph=angle(h); subplot(2,1,1); plot(om/pi,m); grid on; title('MAGNITUDE RESPONSE'); xlabel('NORMAL FREQUENCY'); ylabel('GAIN'); subplot(2,1,2); plot(om/pi,ph); grid on; title('FREQUENCY RESPONSE'); xlabel('NORMAL FREQUENCY'); ylabel('GAIN'); n

DIGITAL SIGNAL PROCESSING LABORATORY 10MTL78

PROGRAM 9.D: BUTTERWORTH BAND STOP DIGITAL IIR FILTER


Write a MATLAB program to implement Butterworth band stop digital IIR filter. rp=input('PASSBAND ATTENUATION='); rs=input('STOPBAND ATTENUATION='); wp=input('PASSBAND FREQUENCY='); ws=input('STOPBAND FREQUENCY='); fs=input('SAMPLING FREQUENCY='); w1=2*wp/fs; w2=2*ws/fs; [n,wn]=buttord(w1,w2,rp,rs); wn=[0.3 0.74315]; [b,a]=butter(n,wn,'stop'); w=0.0:0.01:pi; [h,om]=freqz(b,a,w); m=20*log10(abs(h)); ph=angle(h); subplot(2,1,1); plot(om/pi,m); grid on; title('MAGNITUDE RESPONSE'); xlabel('NORMAL FREQUENCY'); ylabel('GAIN'); subplot(2,1,2); plot(om/pi,ph); grid on; title('FREQUENCY RESPONSE'); xlabel('NORMAL FREQUENCY'); ylabel('GAIN'); n

PROGRAM 10.A: CHEBYSHEV LOW PASS DIGITAL IIR FILTER


Write a MATLAB program to implement Chebyshev low pass digital IIR filter. rp=input('PASSBAND ATTENUATION='); rs=input('STOPBAND ATTENUATION='); wp=input('PASSBAND FREQUENCY='); ws=input('STOPBAND FREQUENCY='); fs=input('SAMPLING FREQUENCY='); w1=2*wp/fs; w2=2*ws/fs; [n,wn]=cheb1ord(w1,w2,rp,rs); [b,a]=cheby1(n,rs,wn); w=0.0:0.01:pi; [h,om]=freqz(b,a,w); m=20*log10(abs(h)); ph=angle(h); subplot(2,1,1); plot(om/pi,m); grid on; title('MAGNITUDE RESPONSE'); xlabel('NORMAL FREQUENCY'); ylabel('GAIN'); subplot(2,1,2); plot(om/pi,ph); grid on; title('FREQUENCY RESPONSE'); xlabel('NORMAL FREQUENCY'); ylabel('GAIN'); n

DIGITAL SIGNAL PROCESSING LABORATORY 10MTL78

PROGRAM 10.B: CHEBYSHEV HIGH PASS DIGITAL IIR FILTER


Write a MATLAB program to implement Chebyshev high pass digital IIR filter. rp=input('PASSBAND ATTENUATION='); rs=input('STOPBAND ATTENUATION='); wp=input('PASSBAND FREQUENCY='); ws=input('STOPBAND FREQUENCY='); fs=input('SAMPLING FREQUENCY='); w1=2*wp/fs; w2=2*ws/fs; [n,wn]=cheb1ord(w1,w2,rp,rs); [b,a]=cheby1(n,rs,wn,'high'); w=0.0:0.01:pi; [h,om]=freqz(b,a,w); m=20*log10(abs(h)); ph=angle(h); subplot(2,1,1); plot(om/pi,m); grid on; title('MAGNITUDE RESPONSE'); xlabel('NORMAL FREQUENCY'); ylabel('GAIN'); subplot(2,1,2); plot(om/pi,ph); grid on; title('FREQUENCY RESPONSE'); xlabel('NORMAL FREQUENCY'); ylabel('GAIN'); n

PROGRAM 10.C: CHEBYSHEV BAND PASS DIGITAL IIR FILTER


Write a MATLAB program to implement Chebyshev band pass digital IIR filter. rp=input('PASSBAND ATTENUATION='); rs=input('STOPBAND ATTENUATION='); wp=input('PASSBAND FREQUENCY='); ws=input('STOPBAND FREQUENCY='); fs=input('SAMPLING FREQUENCY='); w1=2*wp/fs; w2=2*ws/fs; [n,wn]=cheb1ord(w1,w2,rp,rs); wn=[0.3 0.74315]; [b,a]=cheby1(n,rs,wn); w=0.0:0.01:pi; [h,om]=freqz(b,a,w); m=20*log10(abs(h)); ph=angle(h); subplot(2,1,1); plot(om/pi,m); grid on; title('MAGNITUDE RESPONSE'); xlabel('NORMAL FREQUENCY'); ylabel('GAIN'); subplot(2,1,2); plot(om/pi,ph); grid on; title('FREQUENCY RESPONSE'); xlabel('NORMAL FREQUENCY'); ylabel('GAIN'); n

DIGITAL SIGNAL PROCESSING LABORATORY 10MTL78

PROGRAM 10.D: CHEBYSHEV BAND STOP DIGITAL IIR FILTER


Write a MATLAB program to implement Chebyshev band stop digital IIR filter. rp=input('PASSBAND ATTENUATION='); rs=input('STOPBAND ATTENUATION='); wp=input('PASSBAND FREQUENCY='); ws=input('STOPBAND FREQUENCY='); fs=input('SAMPLING FREQUENCY='); w1=2*wp/fs; w2=2*ws/fs; [n,wn]=cheb1ord(w1,w2,rp,rs); wn=[0.3 0.74315]; [b,a]=cheby1(n,rs,wn,'stop'); w=0.0:0.01:pi; [h,om]=freqz(b,a,w); m=20*log10(abs(h)); ph=angle(h); subplot(2,1,1); plot(om/pi,m); grid on; title('MAGNITUDE RESPONSE'); xlabel('NORMAL FREQUENCY'); ylabel('GAIN'); subplot(2,1,2); plot(om/pi,ph); grid on; title('FREQUENCY RESPONSE'); xlabel('NORMAL FREQUENCY'); ylabel('GAIN'); n

PROGRAM 11: FIR FILTER USING RECTANGULAR WINDOW


Write a MATLAB program to implement FIR filter using rectangular window. rp=input('PASSBAND RIPPLE='); rs=input('STOPBAND RIPPLE='); fp=input('PASSBAND FREQUENCY='); fs=input('STOPBAND FREQUENCY='); f=input('SAMPLING FREQUENCY='); wp=2*fp/f; ws=2*fs/f; num=-20*log10(sqrt(rp*rs))-13; den=14.6*(fs-fp)/f; n=ceil(num/den); n1=n+1; if(rem(n,2)~=0); n1=n; n=n-1; 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); grid on; title('LOW PASS FILTER'); xlabel('NORMAL FREQUENCY'); ylabel('GAIN'); %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); grid on; title('HIGH PASS FILTER'); xlabel('NORMAL FREQUENCY'); ylabel('GAIN'); %BAND PASS FILTER wn=[wp ws]; b=fir1(n,wn,y); [h o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,2,3); plot(o/pi,m); grid on; title('BAND PASS FILTER'); xlabel('NORMAL FREQUENCY'); ylabel('GAIN'); %BAND STOP FILTER wn=[wp ws]; b=fir1(n,wn,'stop',y); [h o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,2,4); plot(o/pi,m); grid on; title('BAND STOP FILTER'); xlabel('NORMAL FREQUENCY'); ylabel('GAIN');

DIGITAL SIGNAL PROCESSING LABORATORY 10MTL78

PROGRAM 12: CIRCULAR CONVOLUTION OF TWO SIGNALS


Write a MATLAB program to perform circular convolution of two signals. x=input('ENTER THE FIRST SEQUENCE:'); u1=0:length(x)-1; subplot(2,2,1); stem(u1,x); grid on; title('FIRST SEQUENCE'); xlabel('TIME'); ylabel('AMPLITUDE'); h=input('ENTER THE SECOND SEQUENCE:'); u2=0:length(h)-1; subplot(2,2,2); stem(u2,h); grid on; title('SECOND SEQUENCE'); xlabel('TIME'); ylabel('AMPLITUDE'); a1=x'; h1=fliplr(h); a=circshift(h1,[0,1]); b=circshift(a,[0,1]); c=circshift(b,[0,1]); d=circshift(c,[0,1]); h2=[a;b;c;d]; y=h2*a1 subplot(2,2,3); u3=0:length(y)-1; stem(u3,y); grid on; title('CIRCULAR CONVOLOUTION'); xlabel('TIME'); ylabel('AMPLITUDE');

PROGRAM 13: CIRCULAR CONVOLUTION OF TWO SIGNALS USING FFT& IFFT


Write a MATLAB program to perform circular convolution of two signals using FFT & IFFT. x=input('ENTER THE FIRST SEQUENCE:'); u1=0:length(x)-1; subplot(2,2,1); stem(u1,x); grid on; title('FIRST SEQUENCE'); xlabel('TIME'); ylabel('AMPLITUDE'); h=input('ENTER THE SECOND SEQUENCE:'); u2=0:length(h)-1; subplot(2,2,2); stem(u2,h); grid on; title('SECOND SEQUENCE'); xlabel('TIME'); ylabel('AMPLITUDE'); a1=x'; h1=fliplr(h); a=circshift(h1,[0,1]); b=circshift(a,[0,1]); c=circshift(b,[0,1]); d=circshift(c,[0,1]); h2=[a;b;c;d]; m=length(a1); n=length(h2); N=max(m,n); x=fft(x,N); h=fft(h,N); Y=x.*h; y=ifft(Y) subplot(2,2,3); u3=0:length(y)-1; stem(u3,y); grid on; title('CIRCULAR CONVOLOUTION'); xlabel('TIME'); ylabel('AMPLITUDE');

10

DIGITAL SIGNAL PROCESSING 10MTL78

PROGRAM 14: SAMPLING THEOREM


Write a MATLAB program to implement sampling theorem. p=4; a1=5; a2=10; f1=50; f2=50; fs=200; t=0:0.000001:p*(1/f1); s1=a1*sin(2*pi*f1*t); subplot(2,3,1); plot(t,s1); title('FIRST SINE WAVE'); xlabel('TIME'); ylabel('AMPLITUDE'); s2=a2*sin(2*pi*f2*t); subplot(2,3,2); plot(t,s2); title('SECOND SINE WAVE'); xlabel('TIME'); ylabel('AMPLITUDE'); s=s1+s2; subplot(2,3,3); plot(t,s); title('SUMMED SINE WAVE'); xlabel('TIME'); ylabel('AMPLITUDE'); ts=0:1/fs:p*(1/f1); sa=a1*sin(2*pi*f1*ts)+a2*sin(2* pi*f2*ts); subplot(2,3,4); stem(ts,sa); title('SAMPLED SINE WAVE'); xlabel('TIME'); ylabel('AMPLITUDE'); tn=0:(0.01/fs):p*(1/f1); sr=interp1(ts,sa,tn,'cubic'); subplot(2,3,6) plot(tn,sr); title('RECONSTRUCTED WAVE'); xlabel('TIME'); ylabel('AMPLITUDE'); n=p*(fs/max(f1,f2))

11

DIGITAL SIGNAL PROCESSING 10MTL78

PART B PROGRAM 01: LINEAR CONVOLUTION OF TWO SIGNALS


Write a C program to perform linear convolution of two signals. #include<stdio.h> #include<conio.h> #include<math.h> void main() { int m=4; int n=4; int i,j; int x[10]={1,2,3,4,0,0,0,0,0,0}; int h[10]={1,2,3,4,0,0,0,0,0,0}; int y[10]; for(i=0;i<(m+n-1);i++) { y[i]=0; for(j=0;j<=i;j++) { y[i]+=x[j]*h[i-j]; } } clrscr(); printf("LINEAR CONVOLOUTION OUTPUT\n\n"); for(i=0;i<(m+n-1);i++) { printf("=>%d\n",y[i]); } getch(); }

PROGRAM 02: CIRCULAR CONVOLUTION OF TWO SIGNALS


Write a C program to perform circular convolution of two signals. #include<stdio.h> #include<conio.h> #include<math.h> void main() { int x[8],h[8],y[8]; int cirmat[8][8]; int circnv[8]; int i,j,k,n; clrscr(); printf("ENTER THE LENGTH OF THE FIRST & SECOND SEQUENCE\n\n"); scanf("%d",&n); printf("\nENTER THE ELEMENTS OF THE FIRST SEQUENCE\n"); for(i=0;i<n;i++) { printf("\n=>"); scanf("%d",&x[i]); } printf("\nENTER THE ELEMENTS OF THE SECOND SEQUENCE\n"); for(i=0; i<n; i++) { printf("\n=>"); scanf("%d",&y[i]); } h[0]=y[0]; j=1; for(i=n-1;i>0;i--) { h[j]=y[i]; j++; } for(i=0;i<1;i++) for(j=0; j<n; j++) cirmat[i][j]=h[j]; k=n-1; for(i=1; i<n; i++) { cirmat[i][0]=h[k]; for(j=0; j<n; j++) { cirmat[i][j+1]=cirmat[i-1][j]; } k=k-1; } for(j=0; j<n; j++) { circnv[j]=0; for(k=0; k<n; k++) { circnv[j]+=cirmat[j][k]*x[k]; } } printf("\nCIRCULAR CONVOLUTION OUTPUT:\n\n"); for(i=0;i<n;i++) { printf("=>%d\n\n",circnv[i]); } getch(); }
12

DIGITAL SIGNAL PROCESSING 10MTL78

PROGRAM 03: DIFFERENCE EQUATION


Write a MATLAB program to solve a difference equation. #include<stdio.h> #include<conio.h> void main() { float y[32]={0,0,0}; float x[32]={0,0,0,1,2,3,4}; int n; for(n=3;n<7;n++) { y[n]=(x[n]-(1.0/3.0)*x[n1]+(3.0/4.0)*y[n-1](1.0/8.0)*y[n-2]); } clrscr(); printf("\nDIFFERENCE EQUATION OUTUPTS OF 1,2,3,4:"); for(n=3;n<7;n++) { printf("\n\n=>%f",y[n]); } getch(); }

PROGRAM 04: N POINT DFT


Write a C program to find the N point DFT of the given sequence. #include<stdio.h> #include<conio.h> #include<math.h> void dft(short*x,short k,int*out); int N=4; float pi=3.1416; int sumRe,sumIm; short x[4]={1,2,3,4}; int out[2]={0,0}; int real[4],image[4],k=0; void dft(short*x,short k,int*out) { int sumRe=0,sumIm=0; float cs=0,sn=0; int i=0; for(i=0;i<N;i++) { cs=cos(2*pi*(k)*i/N); sn=sin(2*pi*(k)*i/N); sumRe=sumRe+x[i]*cs; sumIm=sumIm-x[i]*sn; } out[0]=sumRe; out[1]=sumIm; real[k]=sumRe; image[k]=sumIm; k++; if(k>N) k=0; printf("\n\n%d",out[0]); } void main() { clrscr(); printf("N-POINT DFT 1,2,3,4:"); int j; for(j=0;j<N;j++) { dft(x,j,out); } getch(); }

OF

13

DIGITAL SIGNAL PROCESSING 10MTL78

PROGRAM 05: IMPULSE RESPONSE OF A SYSTEM


Write a C program to find the impulse response of a system. #include<stdio.h> #include<conio.h> #define order 2 #define len 10 float y[len]={0,0,0},sum; void main() { clrscr(); int j,k; float a[order+1]={1,-0.7500, 0.1250}; float b[order+1]={1,-0.3333}; for(j=0;j<len;j++) { sum=0; for(k=1;k<=order;k++) { if((j-k)>=0) sum=sum+(a[k]*y[j-k]); } if(j<=order) { y[j]=b[j]-sum; } else { y[j]=-sum; } printf("\n\nIMPULSE RESPONSE [%d]=%f\n",j,y[j]); } getch(); }

14

Das könnte Ihnen auch gefallen