Sei sulla pagina 1di 9

1.

Verification of Sampling theorem.

1 2 3 4 all;close all; 5 clc;clearto verify the sampling theorem %Program 6 7 %Generate 15Hz sinusoidal signal of 0.1s duration sampled at 1000Hz 8 t=0:0.001:0.1; 9 fm=15; 10x=sin(2*pi*fm*t); figure(1) 11plot(t,x),xlabel('Time'),ylabel('Amplitude'); 12title('Original Analog signal'); 13 14%Analog signal sampled at fs<<2fm 15fs=10; 16n=0:1/fs:0.1; xn=sin(2*pi*fm*n); 17figure(2) 18subplot(2,1,1);stem(n,xn); 19xlabel('Time'),ylabel('Amplitude'); 20title('Undersampled fs<<2fm signal'); subplot(2,1,2);plot(n,xn); 21xlabel('Time'),ylabel('Amplitude'); 22title('Reconstructed undersampled fs<<2fm signal'); 23 24%Analog s ignal sampled at Nyquist rate fs=2fm 25fs=30; 26n=0:1/fs:0.1; xn=sin(2*pi*fm*n); 27figure(3) 28subplot(2,1,1);stem(n,xn); 29xlabel('Time'),ylabel('Amplitude'); 30title('Sampled at Nyquist rate fs=2fm signal''); subplot(2,1,2);plot(n,xn); 31xlabel('Time'),ylabel('Amplitude'); 32title('Reconstructed Nyquist rate fs=2fm signal'); 33 34%Analog signal sampled at oversampling fs>>2fm 35fs=500; 36n=0:1/fs:0.1; xn=sin(2*pi*fm*n); 37figure(4) 38subplot(2,1,1);stem(n,xn); 39xlabel('Time'),ylabel('Amplitude'); 40title('Oversampled fs>>2fm signal'); 41subplot(2,1,2);plot(n,xn); xlabel('Time'),ylabel('Amplitude'); 42title('Reconstructed oversampled fs>>2fm signal'); 43 44 45 46

2.

Impulse response of a given system

1 clc;clear all;close all; 2a=input('Enter the feedback coefficients:'); 3b=input('Enter the feedforward coefficients:'); 4h=impz(b,a); 5n=0:length(h) -1; 6stem(n,h);grid on xlabel('Time');ylabel('Amplitude'); 7title('Impulse Response h[n]'); 8

3.

Linear convolution of two given sequences.

1 2 clc;clear all;close all; 3 x=input('Enter x[n]:'); 4 nx=0:length(x) -1; 5 h=input('Enter h[n]:'); 6 nh=0:length(h) -1; 7 z=conv(x,h); nz=0:length(z) -1; 8 subplot(3,1,1); 9 stem(nx,x); 10xlabel('Time');ylabel('Amplitude'); 11title('Input sequence x[n]'); subplot(3,1,2); 12stem(nh,h); 13xlabel('Time');ylabel('Amplitude'); 14title('Impulse response of the system h[n]'); 15subplot(3,1,3); 16stem(nz,z); xlabel('Time');ylabel('Amplitude'); 17title('Linear Convolution'); 18 19 4. Circular convolution of two given sequences

1 clc;clear all;close all; 2 x=input('Enter x[n]:'); h=input('Enter h[n]:'); 3 xl=length(x); 4 hl=length(h); 5 m=max(xl,hl); 6 z=ifft(fft(x,m).*fft(h,m)); 7 zl=length(z); %Plots 8 nx=0:xl-1; 9 nh=0:hl-1; 10nz=0:zl-1; 11subplot(3,1,1); stem(nx,x); 12xlabel('Time');ylabel('Amplitude'); 13title('Input sequence x[n]'); 14subplot(3,1,2);

15stem(nh,h); 16xlabel('Time');ylabel('Amplitude'); title('Impulse response of the system h[n]'); 17subplot(3,1,3); 18stem(nz,z); 19xlabel('Time');ylabel('Amplitude'); 20title('Circular Convolution'); 21 22 23 24 5. Autocorrelation of a given sequence and verification of its properties.

1 clc;clear all;close all; 2 x=input('Enter x[n]:'); n=0:1:length(x) -1; 3 subplot(2,1,1); 4 stem(n,x); 5 xlabel('Time');ylabel('Amplitude'); 6 title('Input sequence x[n] '); Rxx=xcorr(x); 7 nRxx=-length(x)+1:length(x) -1; 8 subplot(2,1,2); 9 stem(nRxx,Rxx); 10xlabel('Time');ylabel('Amplitude'); 11title('Autocorrelation of x[n]'); 12%Verification of properties 13center_index=ceil(length(Rxx)/2); 14Rxx_0=Rxx(center_index); 15E=sum(x.^2); 16if Rxx_0==E disp('Energy (Mean square value) property is verified.'); 17else 18 disp('Energy property is not verified.'); 19end 20Rxx_right=Rxx(center_index:length(Rxx)); 21Rxx_left=Rxx(center_index: -1:1); if Rxx_right==Rxx_left 22 disp('Autocorrelation is an even function. Hence symmetry property is 23verified.'); 24else 25 disp('Autocorrelation is not even.'); 26end m=max(Rxx); 27if m==Rxx_0 28 disp('Maximum value of autocorrelation function is at zero.'); 29else 30 disp('Maximum value is not at zero.'); end 31z=x.*2; 32Rzz=xcorr(z)/2; 33Rmn=Rxx+Rxx; 34if Rzz==Rmn 35 disp('Linearity property is verified'); else 36 disp('Linearity property is not verified'); 37end

38 39 40 41 42 43 44 6. Cross correlation of given sequences and verification of its properties.

1 2 3 4 clc;clear all;close all; 5 x=input('Enter the first sequence x[n]:'); 6 y=input('Enter the second sequence y[n]:'); 7 nx=length(x); ny=length(y); 8 n=max(nx,ny); 9 Rxy=xcorr(x,y); 10subplot(3,1,1); 11nxl=0:1:nx -1; 12stem(nxl,x); xlabel('Time');ylabel('Amplitude'); 13title('Input sequence x[n]'); 14subplot(3,1,2); 15nyl=0:1:ny -1; 16stem(nyl,y); xlabel('Time');ylabel('Amplitude'); 17title('Input sequence y[n]'); 18subplot(3,1,3); 19l=-n+1:n-1; 20stem(l,Rxy); 21xlabel('Time');ylabel('Amplitude'); title('Cross correlation of x[n] and y[n]'); 22 23%Verification of properties 24z=fliplr(Rxy); 25Ryx=xcorr(y,x); 26if z==Ryx disp('Rxy( -k)=Ryx(k) - Verified.'); 27end 28a=Rxy.*Rxy; 29Rxx=xcorr(x); 30Ryy=xcorr(y); 31c1=ceil(length(Rxx)/2); c2=ceil(length(Ryy)/2); 32Rxx_0=Rxx(c1); 33Ryy_0=Ryy(c2); 34if a<=Rxx_0.*Ryy_0 35 disp('Rxy(k)^2<=Rxx(0).Ryy(0) - Verified.'); 36end 37 38 39

7.

Solving a given difference equation.

+ expand source? 1 2 clc;clear all;close all; 3 a=input('Enter the coefficients of y[n]:'); b=input('Enter the coefficients of x[n]:'); 4 x=input('Enter the input values:'); 5 ic=input('Enter the initial conditions:'); 6 zi=filtic(b,a,ic); 7 y=filter(b,a,x,zi); n=0:length(y) -1; 8 stem(n,y); 9 xlabel('Time');ylabel('Amplitude'); 10title('Solution of difference equation: '); 11 8. Computation of N point DFT of a given sequence and to plot magnitude and phase spectrum. + expand source? 1 2 3 clc;clear all;close all; 4 x=input('Enter x[n]:'); 5 nx=0:length(x) -1; 6 N=32; %Compute DFT 7 n=0:length(x) -1; 8 for k=0:N-1 9 w=exp(-j*2*pi*k*n/N); 10 dot_prod=x.*w; 11 X(k+1)=sum(dot_prod); end 12%Plot the input 13subplot(3,1,1); 14stem(nx,x); 15xlabel('Time');ylabel('Input x[n]'); x[n] 16title('Input seque nce DFT '); '); title('Computation of 17%Plot the magnitude spectrum 18subplot(3,1,2); 19stem(abs(X)); 20xlabel('Time');ylabel('Amplitude'); title('Magnitude Spectrum'); 21%Plot the phase spectrum 22subplot(3,1,3); 23stem(angle(X)); 24xlabel('Time');ylabel('Angle in radian'); 25title('Phase Spectrum'); 26 27 9. . Linear convolution of two sequences using DFT and IDFT.

1 2 3 clc;clear all;close all; 4 x=input('Enter x[n]:'); 5 h=input('Enter h[n]:'); 6 nx=length(x); 7 nh=length(h); n=nx+nh-1; 8 xnew=[x zeros(1,n -nx)]; 9 hnew=[h zeros(1,n -nh)]; 10xf=fft(xnew); 11hf=fft(hnew); 12zf=xf.*hf; z=ifft(zf); 13lx=0:1:nx -1; 14lh=0:1:nh -1; 15nz=0:1:length(z) -1; 16subplot(3,1,1); stem(lx,x); 17xlabel('Time');ylabel('Amplitude'); 18title('Input sequence x[n]'); 19subplot(3,1,2); 20stem(lh,h); 21xlabel('Time');ylabel('Amplitude'); title('Impulse Response h[n]'); 22 23subplot(3,1,3); 24stem(nz,z); 25xlabel('Time');ylabel('Amplitude'); 26title('Linear Convolution '); 27 28%Verification z1=conv(xnew,hnew) 29 30 31 10. Circular convolution of two given sequences using DFT and IDFT

. 1 clc;clear all;close all; 2 x=input('Enter x[n]:'); 3 h=input('Enter h[n]:'); nx=length(x); 4 nh=length(h); 5 n=max(nx,nh); 6 xnew=[x zeros(1,n -nx)]; 7 hnew=[h zeros(1,n -nh)]; xf=fft(xnew); 8 hf=fft(hnew); 9 zf=xf.*hf; 10z=ifft(zf); 11lx=0:1:nx -1; 12lh=0:1:nh -1; nz=0:1:length(z) -1; 13subplot(3,1,1); 14stem(lx,x); 15xlabel('Time');ylabel('Amplitude');

16title('Input sequence x[n] '); 17subplot(3,1,2); stem(lh,h); 18xlabel('Time');ylabel('Amplitude'); 19title('Impulse Response h[n]'); 20subplot(3,1,3); 21stem(nz,z); 22xlabel('Time');ylabel('Amplitude'); title('Circular Convolution'); 23 24 25 26 27 11. Design and implementation of FIR filter to meet given specifications.

. 1 clc;close all;clear all; rp=input('Enter the passband ripple:'); 2 rs=input('Enter the stoopband ripple:'); 3 fp=input('Enter the passband frequency:'); 4 fs=input('Enter the stoopband frequency:'); 5 f=input('Enter the sampling frequency:'); wp=2*fp/f; 6 ws=2*fs/f; 7 num=-20*log10(sqrt(rp*rs)) -13; 8 den=14.6*(fs -fp)/f; 9 n=ceil(num/den); 10n1=n+1; if(rem(n,2)~=0) 11 n1=n; 12 n=n-1; 13end %-----> (1) 14y=boxcar(n1); b=fir1(n,wp,'low',y); %-----> (2) 15[h,o]=freqz(b,1,256); 16m=20*log10(abs(h)); 17an=angle(h); 18subplot(2,1,1);plot(o/pi,m); 19title('Magnitude response'); xlabel('Normalised frequency'); 20ylabel('Gain in dB'); 21subplot(2,1,2);plot(o/pi,an); 22title('Phase response'); 23xlabel('Normalised frequency'); 24ylabel('Gain in rad'); 25 %make relevent changes in (1) for diff. window 26 27% boxcar------->rectangular window 28% bartlett----->bartlett window 29% blackman ----->blackman window 30% chebwin ------>chebyshev window % hamming ------>hamming window 31% hanning ------>hanning window 32 33%make relevent changes in (2) for diff. types 34

35%low pass -------->(n,wp,'low',y); 36%high pass ------->(n,wp,'high',y); %band pass ------->(n,[wp ws],'bandpass',y); 37%band stop ------->(n,[wp ws],'stop',y); 38 39% for kaisar window make these changes 40 41% beta=input('Enter the value of beta ----->after line 6 42%y=kaiser(n1,beta) ------>in line 17 43 44% Eg: (Values w ork for all types of FIR filters) % rp=0.02 rs=0.01 fp=1000 fs=1500 f=10000 beta=5.8 45 46 47 48 49 50 51 52 53 12. Design and implementation of IIR filter to meet given specifications.

. 1 %butterworth filter 2 clc;close all;clear all; format long; 3 rp=input('Enter the passband ripple:'); 4 rs=input('Enter the stoopband ripple:'); 5 fp=input('Enter the passband frequency:'); 6 fs=input('Enter the stoopband frequency:'); 7 f=input('Enter the sampling frequency:'); wp=2*fp/f; 8 ws=2*fs/f; 9 [n,wn]=buttord(wp,ws,rp,rs); %--------- >(1) %--------- >(2) 10[b,a]=butter(n,wn,'low'); 11w=0:0.01:pi; [h,o]=freqz(b,a,w); 12m=20*log10(abs(h)); 13an=angle(h); 14subplot(2,1,1);plot(o/pi,m); 15title('Magnitude response'); 16xlabel('Normalised frequency'); ylabel('Gain in dB'); 17subplot(2,1,2);plot(o/pi,an); 18title('Phase response'); 19xlabel('Normalised frequency'); 20ylabel('Gain in rad'); 21 %chebyshev type I filter 22 23%(1)------>[n,wn]=cheb1ord(wp,ws,rp,rs); 24%(2)------>[b,a]=cheby1(n,rp,wn,'low'); 25 26%chebyshev type II filter 27

28%(1)------>[n,wn]=cheb2ord(wp,ws,rp,rs); 29%(2)------>[b,a]=cheby2(n,rs,wn,'low'); 30 % rp=.035 rs=35 fp=1500 fs=2000 31 32 33 34 35 36

f=8000

B. LIST OF EXPERIMENTS USING DSP PROCESSOR 1. 2. 3. Linear convolution of two given sequences. Circular convolution of two given sequences. Computation of N- Point DFT of a given sequence

4. Realization of an FIR filter (any type) to meet given specifications .The input can be a signal from function generator / speech signal. 5. Audio applications such as to plot time and frequency (Spectrum) display of Microphone output plus a cosine using DSP. Read a wav file and match with their respective spectrograms 6. Noise: Add noise above 3kHz and then remove; Interference suppression using 400 Hz tone. 7. Impulse response of first order and second order system

Potrebbero piacerti anche