1、数字信号处理实验报告实验一 2-1. R=50; m=0:R-1; s=2*m.*(0.9.^m); d=rand(R,1)-0.5; x=s+d'; x1=0; for n=1:R; d=rand(R,1)-0.5; x=s+d'; x1=x1+x; end x1=x1/R; subplot(2,2,1),stem(m,s),xlabel('Time index n');ylabel('Amplitude');title('Original uncorrupted data') subplot(2,2,2),stem(m,d),xlabel('Time i
2、ndex n');ylabel('Amplitude');title('Noise') subplot(2,2,3),stem(m,x),xlabel('Time index n');ylabel('Amplitude');title('Noise corrupted sequense') subplot(2,2,4),stem(m,x1),xlabel('Time index n');ylabel('Amplitude');title('Ensemble average') 2-2-1. a=input('Type in real exponent ='); b=input('
3、Type in imaginary exponent ='); c=a+b*i; K=input('Type in the gain constant ='); N=input('Type in length of sequence ='); n=1:N; x=K*exp(c*n); stem(n,real(x)); xlabel('Time index n');ylabel('Amplitude');title('Real part'); disp('PRESS RETURN for imaginary part'); pause stem(n,imag(x)); xl
4、abel('Time index n');ylabel('Amplitude');title('Imaginary part'); Type in real exponent =-1/12 Type in imaginary exponent =pi/6 Type in the gain constant =1 Type in length of sequence =40 2-2-2. a = input('Type in argument = '); K = input('Type in the gain constant = '); N = input ('Type
5、 in length of sequence = '); n = 0:N; x = K*a.^n; stem(n,x); xlabel('Time index n');ylabel('Amplitude'); title(['\alpha = ',num2str(a)]); Type in argument = 1.2 Type in the gain constant = 0.2 Type in length of sequence = 30 Type in argument = 0.9 Type in the gain constant = 20 Type in
6、 length of sequence = 30 2-2-3 w = input('Type in argument = '); N = input ('Type in length of sequence = '); n = 0:N; y = 1.5.*cos(w.*n); stem(n,y);axis([0 40 -2 2]); xlabel('Time index n');ylabel('Amplitude'); title(['wo = ',num2str(w/pi),'π']); Type in argument = 0.1*pi Type in len
7、gth of sequence = 40 2-3-1 R=50; d=rand(R,1)-0.5; m=0:1:R-1; s=2*m.*(0.9.^m); x=s+d'; plot(m,d,'r-',m,s,'b--',m,x,'g:') xlabel('Time index n');ylabel('Amplitude'); legend('d[n]','s[n]','x[n]'); pause M=input('Number of input samples ='); b=ones(M,1)/M; y=filter(b,1,x); plot(m,s,'r-',m
8、y,'b--') legend('s[n]','y[n]'); xlabel('Time index n');ylabel('Amplitude');title(['M= ',num2str(M)]); Number of input samples =3 2-3-2 R=50; d=rand(R,1)-0.4; m=0:1:R-1; s=2*m.*(0.9.^m); x=s+d'; M=input('Number of input sample ='); d=rand(R,1)-0.4; x=s+d'; x2=[zeros(1,(M-1)),x]; fo
9、r i=1:R; sum=0; for g=1:M; sum=sum+x2(i+g-1); end y(i)=sum./M; end plot(m,s,'r-',m,y,'b--');length(y) legend('s[n]','y[n]'); xlabel('Time index n');ylabel('Amplitude');title(['M= ',num2str(M)]); Number of input sample =3 2-4-1 N = input('Median Filter Length =
10、 '); R = 50; a = rand(1,R)-0.4; b = round(a); m = 0:R-1; s = 2*m.*(0.9.^m); x = s + b; y = medfilt1(x,N); subplot(2,1,1) stem(m,x);axis([0 50 -1 8]); xlabel('n');ylabel('Amplitude'); title('Impulse Noise Corrupted Signal'); subplot(2,1,2) stem(m,y); xlabel('n');ylabel('Amplitude');
11、 title('Output of Median Filter'); Median Filter Length = 3 2-4-2 R=50; a=rand(1,R)-0.4; b=round(a); m=0:R-1; s=2*m.*(0.9.^m); x=s+b; M=input('Number of input samples = '); x2=[zeros(1,(M-1)/2),x,zeros(1,(M-1)/2)]; for i=1:R; c=sort(x2(i:i+M-1)); if mod(M,2)==1; y(i)=
12、c((M+1)/2); else y(i)=(c(M/2)+c(M/2+1))/2; end end subplot(2,1,1) stem(m,x);axis([0 50 -1 8]); xlabel('n');ylabel('Amplitude'); title('Tmpulse Noise Corrupted Signal'); subplot(2,1,2) stem(m,y); xlabel('n');ylabel('Amplitude'); title('Output of Median Filter')
13、 Number of input samples =3 2-6 a = input('Type in the first sequence = '); b = input('Type in the second sequence = '); c = conv(a, b); M = length(c)-1; n = 0:1:M; disp('output sequence =');disp(c) stem(n,c) xlabel('Time index n'); ylabel('Amplitude'); Type in the first sequence =
14、 [-2 0 1 -1 3] Type in the second sequence = [1 2 0 -1] output sequence = -2 -4 1 3 1 5 1 -3 2-1 2-2-1 2-2-2 2-2-3 2-3-1 2-3-2 2-4-1 2-4-2 2-6






