Anda di halaman 1dari 21

Sivaramakrishnan, Aishwarya, 19871120-8663

Solutions to Exam Optimal Signal Processing, ET 2410


Sivaramakrishnan, Aishwarya, 19871120-8663

Task 1
Task 1-A
Least Square Polynomial Curve Fitting is a theorem which tells about, Least Squares Method that used to give the best fit for the curve, Polynomial in this LS sense is used to minimize the error between the observed data points to the estimated curve. ,

Here, we use least square polynomial for the given N data pairs Thus, the equation is given by,

where, the output depends on the input parameter

and the white guassian noise with variance

Now, the least square polynomial of degree k is given by,

that can fit the N data pairs of x and y by solving the linear system given by, x . P = y

This can then be converted into vandermonde equation and then, this can be solved by multiplying on both the sides of the system,

Now, we know that,

This is the equation to derive polynomial for the least squares.

Sivaramakrishnan, Aishwarya, 19871120-8663 The error is given by the difference between the measured value with the estimated value as mentioned. Least Mean Square Error is given by, Thus, now we can substitute the value of here, we get,

This is how the variance is derived for the noise signal v, because for the unknown Guassian noise, mean is zero and the variance is given as . So least mean square is equal to variance. Task 1-B Defining and deriving the expression for the polynomial constant p and the variance of the guassian noise(v). Matlab Coding: %Function defining the Least Square Polynomial Curve Fitting% %%p= polynomial coeffecient of least square sense and s - guassian noise vector function [p s]=LSPCF(x,y,K) x=x(:);y=y(:); %Defining the Value of (xn,yn) data points N=length(x); %no. of samples of xn J=N-K; %defining subscript %Vandermonde Function is used to implement the vandermonde matrix for the polynomial coeffecient p vand=vander(x); %Here J is expected to be real valued positive integer or logicals X=vand(:,J:N); %expression for the polynomial coeffecient p a=inv(X.'*X); b=(a*X.'); p=b*y; %Estimated Curve Function

Sivaramakrishnan, Aishwarya, 19871120-8663 y1=X*p; %Error Function is the difference betw. the measured data points to the %estimated curve e=y-y1; s=sum(e.^2)/J;
Table 1 for task coding 1

Task 1-C:
The given lines are coded and the o/p with K=5 as the coefficient, the output is generated. The values of P and S are then determined with the x and y input. P= -0.00078393346777 0.09872199258599 0.00933460439849 -0.98931337214534 1.98587916101385 -2.01305977294848 s= 0.0191

clc clear all load lspcf-polyval-3 [p, s] = LSPCF (x, y, 5); % function call of least square polynomial curve fitting% figure %given datas N = size(x); % it collects the row and column of x in a row n = sqrt(s)*randn(N); %Random noise given as n y1 = polyval(p,x)+n; figure plot(y) title('Comparison of Original Data Pairs vs Estimated data curve') hold on plot(y1,'R') xlabel('samples n'); ylabel('Data Value');

Sivaramakrishnan, Aishwarya, 19871120-8663 legend('sample data pairs','Estimated Data Curve',2);

Table 2 for task coding 1-b

Figure 1-c Least Square polynomial curve fitting

The curve seems to be fitting enough when the coefficient K=5. With the increase in K, there is little a difference in o/p until K=15, but after then again the curve loses track and does not fit to the points. But, K=5 seems to be appropriate for the given signal vectors x and y.

Sivaramakrishnan, Aishwarya, 19871120-8663

Task 2:
Speech Coding is the process of compressing the speech data available in the digital audio signal. Speech signal that is understood by the human auditory system is only transmitted by preserving intelligibility and pleasantness. The speech signal is temporally compressed into low bits/per second and then reconstructed back by preserving most of the speech content. Task 2-A: Now, in this task, the signal transmitted is expected to be compressed when passing through the channel with limited bandwidth but without missing its quality in the receiver end. Here, speechcoding.mat is given as the input containing the values of speech signals, sample data rate and the error. Now, we derive a function called stepup to be carried out in the speech coding. It steps up the data with every corresponding value of the column vector. function a = stepup(gamma) gamma(:); a = gamma(1); for n=2:length(gamma) m=length(a); b=[a' 0]; c=gamma(n); d=-a(m:-1:1)'; a = b + c*[d 1]; a = a(:); end Here, in the speech coding, c1 and e1 column vectors are utilized to develop the code, stepping up the reflection coefficient, filtering and then reconstructing back at the receiver end without any too much loss in quality and intelligibility. Plotting the reconstructed signal gives us a clear picture. clear all clear all close all clc load speechcoding% loading the speechsignal [Z1,Z2] = size(c1);%row and column of c1 for i = 1:Z2 % Picking column vector to find a. J=2:Z1; gama = c1(J,i); % Finding stepping up gama to find a

Sivaramakrishnan, Aishwarya, 19871120-8663 a = stepup(gama); PredEF = [1 -a']; % Predictor error Filter A = sqrt(c1(1,i)); e = e1(:,i); % Passing the Error Signal from inverse of H(z) x(:,i) = filter(A,PredEF,e); end L = length(e1); % signal Reconstruction. y = reconstruction(x,L); plot(1:length(y),abs(fft(y))) xlabel('Time in Seconds'); ylabel('Sample amplitude'); title('SPEECH CODING');
Table 3 for task coding 2-a

Figure 2-a Speechcoding

Sivaramakrishnan, Aishwarya, 19871120-8663

Task 2-B
Since, e2 is not available, a command called awgn is used in order to get a new white guassian noise signal.

clear all close all clc load speechcoding% loading the speechsignal [Z1,Z2] = size(c1);%row and column of c1 for i = 1:Z2 % Picking column vector to find a. J=2:Z1; gama = c1(J,i); % Finding stepping up gama to find a a = stepup(gama); PredEF = [1 -a']; % Predictor error Filter A = sqrt(c1(1,i)); e = awgn(PredEF,0.9);%white guassian noise % Passing the Error Signal from inverse of H(z) x(:,i) = filter(A,PredEF,e); end L = length(e); % signal Reconstruction. y = reconstruction(x,L); plot(1:length(y),abs(fft(y)),'r') xlabel('Time in Seconds'); ylabel('Sample amplitude'); title('SPEECH CODING');
Table 3 for task coding 2-a

Sivaramakrishnan, Aishwarya, 19871120-8663

Figure 2-b Speechcoding with white guassian noise.

Task 3:
Beamforming is a process of collecting all the signals together in an array from the sensor, filter each signal and give out together as one single sensitive signal out which can be received by a loud speaker the receiver end. It involves space and time.

Task 3-A
This task ask us to define a function called filterbf of the filtered input and the input weights. The beamformer filter is used to filter the input signal. Here, the column vector is considered for the filtering operation and also for the input signal. Each column vector of H is considered everytime using the for loop to filter the corresponding column vector of X. Thus, the sum of all the filtered signal are given as the output of the beamformer. function y=filterbf(H,X) %initializing the o/p signal y=0; % No. of Rows and Columns in the filtered signal;

Sivaramakrishnan, Aishwarya, 19871120-8663 hk=size(H); % Column Vector of the Filtered Signal is only considered colvector=hk(2); %To Generate Filter of the Input Signal but the Filtering Signal for p=1:colvector a=H(:,p); b=X(:,p); y=filter(a,1,b)+y; end
Table 4 for task coding 3-a

Task 3-B
The cross correlation vector of the spatiotemporal domain is given by,

So this can be written in the vector form when length of the vector is from 1 to k.

The vector length or the dimension is considered to be K*L. So this length of vector is the stacked vector of the spatiotemporal domain. Similarly, the autocorrelation of the spatiotemporal domain is given by,

Since its the multiplication vector of the input signal with its same transpose vector, the matrix form is defined as below,

Here, for the matrix, the vector length is considered to be K*L by K*L. So, this length of the matrix is the stacked matrix of the spatiotemporal domain.

Sivaramakrishnan, Aishwarya, 19871120-8663

Task 3-C
stcorrmtx Spatio temporal correlation matrix X . Each columns -sensor signal no. of columns - no. of sensors. L- coefficient Rxx=Autocorrelation Matrix

%function defining the stacked correlation matrix function Rxx=stcorrmtx(X,L) %corresponding row nd column of X [R,C]=size(X); Rxxmain=[];%autocorrelation matrix initialized to zero for p=1:C x=convmtx(X(:,p),L);%convoluting X with L x1=x'*x; Rxxmain=[Rxxmain; x1];%matrix formation end Rxx=Rxxmain;
Table 5 for task coding 3-c

stcorrvec Spatio-temporal Correlation vector d with matrix X Each columns -sensor signal no. of columns - no. of sensors. L- coefficient Rdx=Cross-correlation VEctor

%Function determining the stacked correlation vector function rdX=stcorrvec(d,X,L) [rows,columns]=size(X)% rows nd columns takes the corresponding row nd column of X for i=1:columns %initialization x1=convmtx(X(:,i),L);%function call of convolution matrix d(length(x1),1)=0;%defining d at length y1 as zero rdx1(:,i)=x1.'*d;%cross correlation vector end

Sivaramakrishnan, Aishwarya, 19871120-8663 rdX=rdx1(:);%all the rows and columns of rdx

Table 6 for task coding 3-c

Task 3-D
Wiener beamformer filter helps in filtering out the unwanted portions. Here, Wiener Beamformer Filter Coefficient is derived as h. Further described in the script. %function defining the wiener filter of beamformer function h=wienerbf(X,d,L) rdX=stcorrvec(d,X,L);%corrlation vctor function caaling Rxx=stcorrmtx(X,L);%correlation matrix function call [R,C]=size(X); for p=1:C a=p*L; %correlation process autocorr=Rxx(a-L+1:a,1:L); crosscorr=rdX(a-L+1:a,1); %optimal filter of beamformer wopt=Rxx\rdX; %normalizing the optimal filter coeffecient W=norm(wopt); h(:,p)=wopt/W; end h=h./norm(h);
Table 7 for task coding 3-D

Task 3-E
The file beamforming gives the input signal containing the required values of d,Fs. close all clear all clc load beamforming %loading the given signal L=25;%taps %wiener beamform filter function call H=wienerbf(X,d,L); % H=[1:4;4:7];

Sivaramakrishnan, Aishwarya, 19871120-8663 %values defined in the source F=(0:200)/201*Fs/2; A=(-90:90); G=beampattern(H,d,Fs,F,A);%beampattern function call imagesc(A,F,G);%image with scaling full range image data xlabel('Direction (degrees)'); ylabel('frequency (Hz)');
Table 8 for task coding 3-E

Figure 3e-a. Beam pattern after wiener filtering in space.

It is observed that the direction extends from -90 to 90 in the upper frequency region and it slows down and gets attenuated at the bottom frequencies. In the bottom, it is observed that the direction of angles -20 to 20 only shows high gain and in the other angles, the beamformation is out of phase. From 0 to 1500KHz, the beam pattern seems to have a high gain.

Sivaramakrishnan, Aishwarya, 19871120-8663

This is the function to define the signal to noise interference ratio. It is expected to keep this ratio high where the signal power is high while the noise power is low.

S-Input Signal N-Noise Signal Each column of S and N- Sensor Signal

%function defining the signal to noise and interference ratio beamformer function h=snirbf(S,N,L) %rows determine the sensor signal and the columns determine the total no.of sensors [sensorsig,senscount]=size(S); %correlation matrix function call Rss=stcorrmtx(S,L);%for signal Rnn=stcorrmtx(N,L);% for noise for p=1:senscount a=p*L; Rssj=Rss(a-L+1:a,1:L); Rnnj=Rnn(a-L+1:a,1:L); %v determines the eigen vector and lambda being the eigen value [v1 lamda]=eig(Rssj,Rnnj); h=v1(:,end);%entire eigen vector end h=h./norm(h);%normalizing the filter

Table 9 for task coding 3-F

Task 3-G
The file beamforming gives the input signal containing the required values of d,Fs,S,N.

close all clear all clc load beamforming %loading the given signal

Sivaramakrishnan, Aishwarya, 19871120-8663 % values are given as mentioned L=25;%taps H=snirbf(S,N,L);%sig. to noise nd interf. filter % H=[1:4;4:7]; F=(0:200)/201*Fs/2; A=(-90:90); G=beampattern(H,d,Fs,F,A);%function call of beam pattern imagesc(A,F,G); xlabel('Direction (degrees)'); ylabel('frequency (Hz)');
Table 10 for task coding 3-G

Figure 3g-a. Beam pattern using signal and noise ratio interference.

From the figure, it is deduced that the beam formation happened in the very central part in the entire direction from -90 to 90. Even when the angles exceed,there is no change in the beampattrn which tells that the gain is extremely strong in the direction( at all the angles) but

Sivaramakrishnan, Aishwarya, 19871120-8663 only at the central frequency. Then, it is attenuated and is slowly faded out at the other remaining part of frequency, out of (1950 -2050 KHz) for Fs-8KHz.

Task 3-H
The beamformer filter is designed to have the linear constrained minimum variance. This is developed in order to minimize the output power of the beamformer. The beamformer filter is defined by,

Where w is the normalised frequency as stated. Thus, the fourier transform can be rewritten as,

We can very well understand from the constraint that it minimizes the output power, it seems to be very much similar to the Minimum Variance Spectrum Estimation. It is given that the minimum delay is given by,

As the sensors are placed at a certain distance in space,the delay filter is been designed which is a pure delay,

So the total beamformer filter including the delay is given by,

Using vector stacking, the total transfer function is rewritten as,,

L being the length of the filter, The o/p power in discrete form can be written as, P=

Sivaramakrishnan, Aishwarya, 19871120-8663 Then, this equation can be written as, h The minimization problem is given by, (This derivation is similar to the LECTURE 7 for minimum variance spectrum estimation) The constraint that is subject to a certain frequency and at certain direction shall be passed through the beamformer undistorted which makes the total beamformer filter shall be unity. ) which means, Constrained optimization using Lagrange Multiplier, J Because, the lagrange multiplier converts the constrained problem into non-constrained problem. So the cost function J(h) results as above. Choose h and to minimize J,

So, acc. to constraint, Therefore,

being unknown.

Inserting this into the optimal filter equation,

This is the optimal filter coefficient of a beamformer in estimating the power at frequency at the direction of undistorted.


This function lcmvbf defines the Linear Constrained Minimum Variance Beamformer which has some specific frequency at specific direction in which a signal is passed, undistorted.

%% Function to determine the Linear constrained Minimum Variance Beamformer function h=lcmvbf(K,L,t0,f0,Fs,d)

Sivaramakrishnan, Aishwarya, 19871120-8663 Rxx=eye(L); %identity matrix of L for k=0:K-1%initialization for l=0:L-1%initialization C=344;%speed of sound mindelay=(sin(t0*pi/180)*d*Fs)/(C); %relative minimum delay of signal w=f0/Fs;%omega e=exp(-j*2*pi*l*w); Dfilter=exp(-j*2*pi*w*k*mindelay);%Delayed filter e1(l+1,k+1)=Dfilter*e; end e2=e1(:,k+1); h(:,k+1)=(inv(Rxx)*e2)/(e2'*inv(Rxx)*e2);%optimal filter coefficients of the LCMV beamformer filter end
Table 11 for task coding 3-H

Task 3-I LCMV Beamformer is designed with the given file as the input signal.

Sivaramakrishnan, Aishwarya, 19871120-8663 close all clear all clc load beamforming L=25; K=4; % values are given as mentioned % h=[1:4;4:7];%tried with this values F=(0:200)/201*Fs/2;%frequency range from 0 to Fs/2 A=(-90:90);%direction from -90 to 90 C=344;%speed of sound t0=45; f0=2000; H=lcmvbf(K,L,t0,f0,Fs,d);% function call of LCMV beamformer filter figure G=beampattern(H,d,Fs,F,A);%function call of forming a beam pattern % imagesc(A,F,G) plot(A,G)%plot against direction and gain xlabel('Direction (degrees)'); ylabel('gain (dB)'); figure G=beampattern(H,d,Fs,F,45); % imagesc(A,F,G) % wi=linspace(0,pi,Fs);% tried with line spacing plot(F,(G))%plot against frequency and gain with constant direction of 45 degree xlabel('frequency (Hz)'); ylabel('gain (dB)');
Table 12 for task coding 3-I

Sivaramakrishnan, Aishwarya, 19871120-8663

Figure 3i-a. Beam pattern using LCMV with direction between -90 to 90.

Figure 3i-b. Beam pattern using LCMV with direction of 45 degrees and varying frequency.

Sivaramakrishnan, Aishwarya, 19871120-8663 From the figure a and b, it is deduced that both of them satisfy the optimization criterion and design constraint. its is seen that, the gain is strong and high at the direction of -20 to 100 and more. In the lesser angles than -20, the beam pattern starts attenuating. Also, the beam pattern shows a sinc with high main lobe at 45 degrees at 2000Hz without any distorted beamformation.