东南大学matlab第三次大作业 下载本文

内容发布更新时间 : 2024/5/19 17:47:22星期一 下面是文章的全部内容请认真阅读。

Matlab Worksheet 3

Part A

1. Using function conv_m.m to make convolution between the following to functions (x and h):

x=[3, 11, 7, 0, -1, 7, -5, 0, 2]; h=[11, 9, 0, -7, -3, 2, 0 -1]; nx=[-2:6]; nh=[0:7];

Plot the functions and convolution results.

x=[3, 11, 7, 0, -1, 7,5,0, 2]; nx=[-2:6];

h=[11, 9, 0, -7, -3,2,0,-1]; nh=[0:7];

[y, ny]=conv_m(x,nx,h,nh); subplot(3,1,1); stem(nx,x); ylabel('x[n]');

axis([-6 10 -20 20]); subplot(3,1,2); stem(nh,h); ylabel('h[n]');

axis([-4 10 -20 20]); subplot(3,1,3); stem(ny,y); xlabel('n'); ylabel('y[n]');

axis([-6 15 -200 200]);

2. Plot the frequency response over 0????for the following transfer function by letting

z?ej?, where ?is the frequency (rad/sample)., with appropriate labels and title.

zH(z)?2 .

z?1.6z?0.9

delta=0.01;

Omega=0:delta:pi;

H= (exp(j .* Omega)) ./ ((exp(j .* Omega)).^2+1.6*exp(j .* Omega)+0.9); subplot(2,1,1);

plot(Omega, abs(H)); xlabel('0<\\Omega<\\pi'); ylabel('|H(\\Omega)|');

axis([0 pi 0 max(abs(H))]); subplot(2,1,2);

plot(Omega,atan2(imag(H),real(H))); xlabel('0<\\Omega<\\pi');

ylabel(' -\\pi < \\Phi_H <\\pi') axis([0 pi -pi pi]);

3. Use fft to analyse following signal by plotting the original signal and its spectrum.

1

% fft N=1024; dt=1/N;

t=0:dt:1-dt;

x=sin(2*pi*32 .*t) +sin(2*pi*137 .*t)+sin(2*pi*467 .*t) ; subplot(2,1,1);

plot(t,x), xlabel('t sec'),ylabel('x'); title('Signal and its Fourier Transform'); axis([min(t) max(t) 1.5*min(x) 1.5*max(x)]); X=fft(x); f=0:N-1;

subplot(2,1,2);

stem(f,abs(X)), xlabel('Hz'), ylabel('|X|'); axis([ 0 N/2 0 1.5*max(abs(X))]);

n?n?n????x[n]?sin?2?32??sin?2?137??sin?2?467?.

102410241024??????

4. Use the fast Fourier transform function fft to analyse following signal. Plot the original signal,

and the magnitude of its spectrum linearly and logarithmically. Apply Hamming window to reduce the leakage.

n?n?n????x[n]?sin?2?32.5??sin?2?137.4??sin?2?467.7?.

1024?1024?1024????

The hamming window can be coded in Matlab as

for n=1:N

hamming(n)=0.54+0.46*cos((2*n-N+1)*pi/N); end;

where N is the data length in the FFT.

%Examine signal components %sampling rate 1024Hz N=1024; dt=1/N;

t=0:dt:1-dt;

%****define the signal**

x=0.1*sin(2*pi*32.5 .*t ) + ... 0.2*sin(2*pi*137.4 .*t )+ ... 0.15*sin(2*pi* 467.7 .*t ) ; %*********************** subplot(3,1,1); plot(t,x);

axis([0 1 -1 1]);

xlabel('nT (seconds)'); ylabel('x[n]');

%hamming window for n=1:N

w(n)=0.54+0.46*cos((2*n-N+1)*pi/N); end;

x1=x .*w;

subplot(3,1,2); plot(t,x1);

axis([0 1 -5 5]); 2

xlabel('nT (seconds)');

ylabel('x[n] Hamming win'); X=fft(x1); df=1;

f=0:df:N-1; subplot(3,1,3);

plot(f,20*log10(abs(X))); axis([0 N/2 -60 60]); xlabel('k (Hz)');

ylabel('|X[k]| (db)');

3