Sunteți pe pagina 1din 7

# FUNDAMENTAL SIGNAL PROCESSING

MATLAB Exercise
Exercise 1
L = 256;
for n=0 : L-1
s(n+1)=sin((0.2).*2*pi*n);
end
w = randn(1,L);
x = s+w;
auto_corr_xn=xcorr(x);
Fourier_tx_sin=abs(fft(s,L));
Fourier_tx_xcorr=abs(fft(auto_corr_xn,L));
PSD_sin=Fourier_tx_sin.^2
PSD_xcorr=Fourier_tx_xcorr.^2
figure (1)
plot(Fourier_tx_sin);
title('PSD of Sequence');
figure (2)
plot(Fourier_tx_xcorr);
title('PSD of Fourier');

## Adang Prianto | 26520338

Exercise 2

() = () + 0.5 ( 1)
In z domain
() = () + 0.5. () 1
() = ()(1 + 0.5 1 )
()
= (1 + 0.5 1 )
( )
|()|2 = |1 + 0.5 1 |2
2

2

2

2

## Generated Plot of Input Spectrum and Output Spectrum

By observing attenuation of the output spectrum, we know that filter spectra form a band pass filter
with specific range.

## Adang Prianto | 26520338

Exercise 3
%% generate gaussian white noise signal v(n) with L = 256
L=256;
vn=randn(1,L);
%% generate difference equation x(n)
for n=1 :L
if (n-2)<=0
xn(n)=0+vn(n)
else
xn(n)=0.9*xn(n-1)-0.5*xn(n-2)+vn(n)
end
end
%% computing autocorrelation of x(n)
auto_corr_seq_xn=xcorr(xn,L)
%% auto correlation matrix with the first six value of autocorrelation seq.
auto_corr_Mat_xn=auto_corr_seq_xn(1:6);
toep=toeplitz(auto_corr_Mat_xn)
%% calculate AR
a=inv(toep)*(auto_corr_Mat_xn');

## We got AR value as follow :

a=

1.0000
0.0000
-0.0000
0.0000
-0.0000
0.0000

__________________________________________________________________________________

Exercise 4
a. Generating White Gaussian Noise
Matlab Script :
%% genarating N=1000 samples of white Gaussian noise
N = 1000; %% Sample length
mu = 0; %% zero mean
noise = randn(1,N)+mu; %% white gaussian noise

## b. Estimate First 100 lags of autocorrelation sequence using sample autocorrelation

Matlab Script :
%% Estimate first 100 lags of autocorrelation sequence using sample
autocorrelation
k = 100; %% lags
for j=0:k
for i=1 : 999
int = i-j;
if int <=0
xn(i)=0; %% Since x(n) within interval 0-(N-1), x(n) outside
interval assumed to be 0
else
xn(i)=(noise(i-j)).*(noise(i));
end
end
rk_est(j+1)=sum(xn)/N; %% Estimation of first 100 lags
end
dk=autocorr(noise,100); %% True autocorrelation from matlab syntax
est_err = dk-rk_est; %% Estimate error
%%
figure();
Rxx=1/N*conv(flipud(noise),noise)
lags=(-N+1):1:(N-1);
plot(lags,Rxx);
title('Auto-correlation Function of white noise');
xlabel('Lags')
ylabel('Correlation')
hold on
plot(rk_est);
legend('True value','Estimated value');
grid on;
%%
err(1:100)=Rxx(1:100)-rk_est(1:100)
for er=1 : k
sq_err(er) = (Rxx(er)-rk_est(er)).^2;
end
msq_err = sum(sq_err)/k; %% mean square error

Matlab output
msq_err =
0.0111

## Adang Prianto | 26520338

The estimate value is close enough with the true autocorrelation. Mean square error of
difference true value and estimate value is 0.0111.

## c. Segment white noise

%% Segment white noise to 10 different noise as Given Formula
k=100; %% lags
for l= 0:k
for m=0 : 9 %% 10 different segment noise
for n=1 : 99 %% 100 sample
int = n-l;
if int <=0
xn(n)=0;
else
xn(n)= noise(n+(100*m))* noise(n-l+(100*m));
end
end
rk(m+1)=sum(xn)/99;
end
rk_est(l+1)=sum(rk)/1000;
end

## Matlab output for segmented noise

msq_err =
1.0004e-03

Compared to part (b), it gives better estimation, with mean square error estimation between
estimate & true value 0.001.
d. Matlab output for 10000 sample

## Adang Prianto | 26520338

msq_err =
0.0098

The estimate value of N=10000 is closer to the true autocorrelation value compared to
estimate value of N=1000. Mean square error of difference true value and estimate value of
10000 sample 0.0098.