PAGE 1
PAGE 15
Matlab Worksheet 3
Part A
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.
Answer:
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];
[y, ny]=conv_m(x, nx,h,nh);
subplot(3,1,1); stem(nx, x);
ylabel('x[n]');
axis([-6 10 -6 12 ]);
title('convolution');
subplot(3,1,2);
stem(nh, h); ylabel('h[n]');
axis([-6 10 -8 12]);
subplot(3,1,3);
stem(ny,y);
xlabel('n'); ylabel('y[n]');
axis([-6 10 -150 250]);
Plot the frequency response over for the following transfer function by letting , where is the frequency (rad/sample)., with appropriate labels and title.
.
Answer:
omega=1:pi/100:pi;
z=exp(j .* omega);
H = z ./ (z.^2 + 1.6 * z + 0.9);
subplot(211);
plot(omega, abs(H));
xlabel('\Omega'),ylabel('|H|');
subplot(212);
plot(omega, atan2(imag(H),real(H)));
xlabel('\Omega');ylabel('Phase of H')
Use fft to analyse following signal by plotting the original signal and its spectrum.
.
Answer:
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);
X=fft(x);
subplot(211);plot(t,x);
xlabel('t/sec');ylabel('x');
axis([min(t) max(t) 1.5*min(x) 1.5*max(x)]);
f=0:N-1;
subplot(212);stem(f,abs(X));
xlabel('f/Hz');ylabel('|X|');
axis([ 0 N/2 0 max(abs(X))]);
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.
.
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.
Answer:
N=1024;
dt=1/N;
t=0:dt:1-dt;
x=sin(2*pi*32.5.*t) + sin(2*pi*137.4.*t) + sin(2*pi*467.7.*t);
X=fft(x);
subplot(321);plot(t,x);
xlabel('t/sec');ylabel('x');
axis([min(t) max(t) 1.5*min(x) 1.5*max(x)]);
f=0:N-1;
subplot(323);stem(f,