Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1. 2. 3. 4.
CCS PROGRAMMING LINEAR CONVOLUTION31-31 CIRCULAR CONVOLUTION..31-32 COMPUTATION OF N-POINT DFT...32-32 IMPULSE RESPOSE OF THE DIFFERENT ORDER SYSTEM.32-33
Page 2
Page 3
Page 4
Page 5
RESULT: the output sequence y(n) of the system =[1 2 1 1 0 -1] the input sequence of the sysytem =[1 1 1 1] the impulse response of the system is = 1 1 -1 the verified output sequence is 1 2 1 1 0 -1 GRAPH:
Page 6
RESULT: enter first sequence [1 2 3 4] enter second sequence [2 3 2 4] linear convolution of x1&x2 is y= 2 7 14 25 26 20 16 GRAPH:
Page 7
Page 8
15
-3
Page 9
Page 10
5.COMPUTATION OF N-POINT DFT OF A GIVEN SEQUENCE AND TO PLOT MAGNITUDE AND PHASE SPECTRUM:
x=[1 2 3 6]; N=4; xk=fft(x,N); n=0:1:N-1; figure(1); stem(n,abs(xk)); xlabel('k'); ylabel('|x(k)|'); title('magnitude spectrum'); figure(2); stem(n,angle(xk)); xlabel('k'); ylabel('angle(xk)'); title('phase spectrum'); figure(3); n1=0:1:length(x)-1; stem(n1,x); xlabel('n'); ylabel('x[n]'); title('original signal');
GRAPHS:
Page 11
Page 12
LINEAR 6.LINEAR CONVOLUTION OF TWO GIVEN SEQUENCES USING DFT AND IDFT: LINEAR CONVOLUTION:
x1=[1 2 3 4]; x2=[1 2 3 4]; N=length(x1)+length(x2)-1; X1=fft(x1,N); X2=fft(x2,N); y=X1.*X2; yn=ifft(y,N); disp('linear convolution of x1 & x2 is yn=' 'linear yn='); disp('yn'); disp('output using convolution' 'output convolution'); yv=conv(x1,x2); disp(yv); stem(yn); title('linear convolution output y(n)' 'linear y(n)');
Page 13
Page 14
Page 15
Yxx[0]=
x [n]
MATLAB IMPLEMENTATION:
n=-5:5; N=10; x1=ones(1,11); Y=xcorr(x1); disp('autocorrelated sequence'); disp('y'); figure(2); subplot(2,1,1); stem(n,x1); title('square sequence'); subplot(2,1,2); k=-N:N; stem(k,Y); title('autocorrelated output'); xlabel('lag index');
Page 16
Page 17
GRAPHS:
Page 18
9.CROSSCORRELATION:
x=input('type in the reference sequence ='); y=input('type in the second seq='); n1=length(y)-1; n2=length(x)-1; r=conv(x,fliplr(y)); disp('crosscorrelation output is='); disp(r); k=(-n1):n2; stem(k,r); xlabel('lag index'); ylabel('amplitude');
RESULT: type in the reference sequence =[1 3 -2 1 2 -1 4 4 2] type in the second seq=[2 -1 4 1 -2 3] crosscorrelation output is= 3 7 -11 14 13 -15 28 6 -2 21 12 GRAPH:
12
Page 19
7.0000
2.0000
2.0000
2.0000
Page 20
Properties-2:
x1=[1 2 3 -2 0 0]; x2=[0 0 1 2 3 -1]; y=xcorr(x1,x2); disp(y); subplot(1,1,1); stem(y);
5.0000 16.0000
0.0000 -0.0000
5.0000 16.0000
0.0000 -0.0000
Page 21
Page 23
METHOD-2
wpa=input('enter passband freq in hz='); wsa=input('enter stopband freq in hz='); ws1=input('enter sampling freq in hz='); wpd=2*pi*wpa/ws1; wsd=2*pi*wsa/ws1; tb=wsd-wpd; N=ceil(6.6*pi/tb); wc=(wsd+wpd)/2; wc=wc/pi; hw=hamming(N+1); figure(1); stem(hw); title('fir filter window sequence hamming window'); h=fir1(N,wc,hamming(N+1)); figure(2); [m,w]=freqz(h,1,128); mag=20*log10(abs(m)); plot(w,mag); title('fir filter frequency response '); grid; figure(3); n=1:30; f1=50;f2=300;f3=200;fs=1000; x=[]; x1=sin(2*pi*n*f1/fs); x2=sin(2*pi*n*f2/fs);
Page 24
RESULT: ans = 4 enter passband freq in hz=100 enter stopband freq in hz=200 enter sampling freq in hz=1000 GRAPHS:
Page 25
Page 26
GRAPHS:
Frequency response
Page 27
METHOD-2:
close all; clear all; rp=1; rs=40; w1=800; w2=1200; ws=3600; aw1=2*pi*w1/ws; aw2=2*pi*w2/ws; pw1=2*tan(aw1/2); pw2=2*tan(aw2/2); [n,wc]=buttord(pw1,pw2,rp,rs,'s'); [b,a]=butter(n,wc,'s'); fs=1; [num,den]=bilinear(b,a,1); figure(1); [mag,freq1]=freqz(num,den,128); freq=freq1*ws/(2*pi); m=20*log10(abs(mag)); plot(freq,m) title('frequency response'); grid; n=1:30; f1=100;f2=300;f3=170;fs=1000; x=[]; x1=sin(2*pi*n*f1/fs); x2=sin(2*pi*n*f2/fs); x3=sin(2*pi*n*f3/fs); x=[x1 x2 x3];
Page 28
GRAPHS:
Page 29
Page 30
12.2-STEP RESPONSE:
close all; clear all; N=input('length of response required'); b=[1]; a=[1 -1 0.9]; x=[ones(1,N)]; n=0:1:N-1; y=filter(b,a,x); subplot(2,1,1); stem(n,x); title('step input'); xlabel('n'); ylabel('u(n)'); subplot(2,1,2); stem(n,y); title('step response'); xlabel('n'); ylabel('y(n)');
Page 31
12.3-STEADY STATE:
close all; clear all; N=input('length of response required'); b=[1]; a=[1 -1 0.8]; n=0:1:N-1; x=cos(0.05*pi*n); y=filter(b,a,x); subplot(2,1,1); stem(n,x); title('steady input'); xlabel('n'); ylabel('u(n)'); subplot(2,1,2); stem(n,y); title('steady response'); xlabel('n'); ylabel('y(n)');
Page 32
1.3596
5.0281
Page 33
Page 34
RESULT: 41 51 51
46
36
RESULT: Result will come in complex form like11+j0.00 -0.40755+j-7.66 etc 4. TO FIND THE IMPULSE RESPONSE OF THE GIVEN FIRST ORDER/SECOND ORDER SYSTEM:
#include<stdio.h> float x[60],y[60]; main() { float a1,a2,b0,b1,b2; int i,j,N=20; a1=-1.1430; a2=0.4128; b0=0.0675; b1=0.1349; b2=0.0675; x[0]=1; for(i=1;i<N;i++) {
Page 35
Page 36
Page 38
*QUESTIONS WHICH WILL BE ASKED IN THE EXAMINATION WILL BE IN THE FORM OF LIKE THIS DSP LAB QUESTIONS 1. Write a MATLAB program so that output signal is sampled with a rate a) greater than twice the max frequency content in the input signal and b) for equal to maximum frequency content in the input signal. Given input signal is a cos function and the spacing between the samples is 50s and total time duration is 0.05 seconds. 2. Write a MATlAB program to find the system function of the causal LTI system with input x(z)= 1+2z-1+2z-2+z-3 and output y(z)= 1+z-1+2z-2+z-3 so plot input, output and impulse response. 3. Write a MATLAB program to find convolution of unit imulse function with X(z)= 1+3z1 +4z-2 and convoluted output length is equal to sum of two input lengths-1. 4. Write a MATLAB program to find the output of given system whose frequency response is Y(z)= X(z).H(z) and given x(n)= (1,2,3,4), h(n)= (1,2,3,4) and output length is equal to maximum length of x(n) and h(n). 5. Write a MATLAB program to find convolution of two given sequences in time domain X1(z)= 1+2z-1+3z-2 & X2(z)= 2+z-1+4z-2 and convoluted output length is equal to sum of two input lengths minus one. 6. Write a MATLAB program to find the similarities between the given sequence x(n)= Sin(2*pi*n/N) for N=4 and the time shifted version of same sequences in terms of convolution and write and verify a) Energy property b) periodicity property and draw the graph for the same. 7. Write a program using MATLAB code for the received signal replected from the target is the delayed uerreon of the transmitted signal. Assume delay in two time units. Assume transmitted signal is {3, -1, 2, 1}. 8. Write a MATLAB program to find the similarities between the two given sequence X1 (n)= [1 3 -2 1 2 -1 4 4 2] and X2(n)= [2 -1 4 1 -2 3] is its time shifted version which is shifted by two units, in terms of convolution and prove i) xy[l]= xy[-l] and 2) cross correlation of two sequences x(n) and y(n)= x(n-k) is having peak at the value of k. 9. Write a MATLAB program to find the steady state response for the given difference equation y(n)-0.8y(n-1)=x(n) and x(n)= cos(0.05*pi*n); n=0 to N-1 where N=20 and plot the respective graph. 10. Write a MATLAB program to find the first 8 samples of the complete response y(n) for the difference equation y[n]= 1/3 {x[n]+x[n-1]+x[n-2]}+0.95y[n-1]-0.9025y[n-2]; n>=0 where x(n)=cos(n*pi/3)u(n) and initial conditions are y[-1]=-2, y[-2]=-3, x[-1]=1, x[2]=1. 11. Write a MATLAB program to find the impulse response of a given difference equation y(n)+0.8y(n-2)+0.6y(n-3)=x(n)+0.7x(n-1)+0.5x(n-2). Plot the graph for N=20. 12. Find steady state response using MATLAB for the difference equation y(n)-0.8y(n-1)= x(n) and x(n)= Cos(wn); n=0 to N-1 where N=20. 13. Write a MATLAB program to find the multiplication of two frequencies domain aperiodic signals in the domain x1=[1 1 1 1] and x2=[1 2 3 4].
Page 39
Page 40