You are on page 1of 14

DSP Architecture Mini Project

DSP Architecture -Mini Project

Submitted to – Dr. Jonathan Dell

Name- Krishnav B. Dave


Exam Number –Y6355282

MSc Communications Engineering


Department of Electronics
The University of York

Date – 16/05/2011

Name- Krishnav B. Dave The University of York


Exam Number-Y6355282
Page 1
DSP Architecture Mini Project

Phase 1

1.1 Mean Square Error calculation

 Problem statement:

The task is to calculate a motion vector for a small group of pixels.

 Solution:

The algorithm mentioned below explains the solution to the above mentioned problem
statement.

 Algorithm for MATLAB CODE:

1) Start.

2) Generate two 4x4 matrixes as a source of random numbers between 1 and 255 each 8
bit long which will act as pixel sources. These matrices are represented as frames
specifically 2 in number.

3) Use a well-defined loop for calculation of mean square error (MSE).

a) Function takes in two input values as row and column of the first matrix which
needs to be searched within the second matrix. This is done using subtraction and
calculating the error. Square this difference value.

b) Find the total sum of all the squared differences calculated (total error).

c) Repeat the loop till all the elements of second matrix are subtracted with the
desired row and column of the first matrix.

4) Calculate the mean square error using the following formula:

5) Display the mean square error.

Name- Krishnav B. Dave The University of York


Exam Number-Y6355282
Page 2
DSP Architecture Mini Project

6) End
 MATLAB code for the above algorithm

The code consists of defining a function which allows the user to input a particular row and
column within the first matrix which needs to be searched in the second matrix. The function
is shown below:

function [ ] = mean_square_4x4(row, column)

Pixel_1_src = randsrc(4,4,[1:255]); % pixel sources defined for some random numbers


between 1 and 255

Pixel_2_src = randsrc(4,4,[1:255]);

mat_diff=0;

sum=0;

for i=1:4 % loop used to calculate the difference between two matrices

for j=1:4
mat_diff = Pixel_1_src (row,column)- Pixel_2_src (i,j);
sum = sum + mat_diff ^2;
end
end

Mean_Square_Error = (1/16) * sum % mean square error

end

Name- Krishnav B. Dave The University of York


Exam Number-Y6355282
Page 3
DSP Architecture Mini Project

 MATLAB output window for the above code

>> mean_square_4x4 (1,3 )

Pixel_1_src =

71 178 112 48

12 81 98 125

25 243 196 114

210 9 203 165

Pixel_2_src =

181 168 245 192

193 42 87 66

71 31 150 130

174 128 58 179

Mean_Square_Error =

4.2314e+003

Name- Krishnav B. Dave The University of York


Exam Number-Y6355282
Page 4
DSP Architecture Mini Project

1.2 Block search implementation


 Problem statement:

The task is to implement a block search for small group of pixels and should be extended to
larger block.

 Solution:

The algorithm mentioned below explains the solution to the above mentioned problem
statement.

 Algorithm for MATLAB CODE:

1) Start.

2) Generate two 4x4 matrixes as a source of random numbers between 1 and 255 each 8
bit long which will act as pixel sources.

3) Define a motion vector of size 2x2. The user inputs the row and column to be
searched.

4) Function takes in two input values as row and column of the first matrix which needs
to be searched (subtracted) in second matrix.

a) Error is calculated using the following formula:

Error = (1/ ) * [Determinant(motion vector)]

b) Square the calculated error.

c) Find the total sum of all the squared errors.

d) Repeat the loop 9 times as the combination of the number of all possible locations
is 9, so the number of steps of the loop is set to 9.

5) Calculate the mean square error using the following formula:

Name- Krishnav B. Dave The University of York


Exam Number-Y6355282
Page 5
DSP Architecture Mini Project

6) Display the mean square error.


7) End

This algorithm can be extended to a larger block of pixels as explained in Phase 2 section of
the report.

 MATLAB code for the above algorithm

I have made a function as shown below:

function [] = Block_search_4x4(row, column)

Pixel_1_src = randsrc(4,4,[1:255]) % pixel sources defined for random numbers between


1 and 255

Pixel_2_src = randsrc(4,4,[1:255])

Motion_vector = [0 0 ; 0 0];

Mat_diff = 0;

error=0;

for i=1:3 % loop used to calculate the error and difference


for j=1:3

C = Pixel_1_src (row:row+1 , column:column+1) - Pixel_2_src (i:i+1 , j:j+1);

error = (1/4)*(det(Motion_vector));

Mat_diff = Mat_diff + error^2;

end

end

Mean_Sqare_Error = (1/9) * Mat_diff % MSE is calculation .

end

Name- Krishnav B. Dave The University of York


Exam Number-Y6355282
Page 6
DSP Architecture Mini Project

 MATLAB output window for the above code

Pixel_1_src =

196 71 237 206

54 244 148 46

73 232 34 149

207 41 163 21

Pixel_2_src =

133 25 87 96

25 91 150 232

127 69 163 212

192 164 149 106

Mean_Sqare_Error =

1.0748e+007

Name- Krishnav B. Dave The University of York


Exam Number-Y6355282
Page 7
DSP Architecture Mini Project

Phase 2
 Problem statement:

The task is to implement a block search for larger group of pixels.

 Solution:

The algorithm mentioned below explains the solution to the above mentioned problem
statement.

 Algorithm for MATLAB CODE:

1) Start.

2) Generate random numbers between 1 and 255 each 8 bit long which will act as pixel
sources.

Pixel source 1 Pixel source 2

48x48
48x48

3) Motion vector of size 16x16 is defined.

4) Function inputs row and column values which is the position of motion vector in the
first frame.

5) Use a well-defined loop for calculation of motion vector and the differences between
the two pixel sources (matrix). The number of all possible 16x16 matrixes is 1089
(33x33) in size. So the loop repetition is set to 1089 times.

Name- Krishnav B. Dave The University of York


Exam Number-Y6355282
Page 8
DSP Architecture Mini Project

a) At each step, a 16x16 matrix is chosen in the first frame and this is compared to
one of all possible 16x16 matrixes in the second frame as shown below:

16x16 ………………….
16x16

……………………. 16x16
48x48 48x48
Pixel source 1 Pixel source 2

b) Find the total sum of all the differences calculated. If the sum is negative then
remove the negative sign and make it positive.

d) Repeat the loop for 1089 times.

6) To get Minimum Square Error, there is a need to find the minimum value of the
difference and also the position of it in order to know the positions of the most similar
matrix which is known by index value. Find the matrix index.

7) Find the minimum value of the pixel difference in order to find the most similar
matrix. Using this calculate the mean square error.

8) Find the row and column of the matched matrix using index value.

9) Display the mean square error, matched matrix index, matched matrix row, matched
matrix column and the two matched matrices.

10) End

Name- Krishnav B. Dave The University of York


Exam Number-Y6355282
Page 9
DSP Architecture Mini Project

 MATLAB code for the above algorithm

I have made a function as shown below:

function [ ] = block_mean_2(Row, Column)

% random number sources between 1 to 255 representing the pixel


Pixel_1_src = randsrc(48,48,[1:255]);

Pixel_2_src = randsrc(48,48,[1:255]);

% Motion vector initialization


motion_vector = randsrc(16,16,[0]);

% variable used to store the differences between two matrices


mat_diff = 0;

% used as a vector address


count = 1;

% loop to calculate the motion vector

for i= 1:33;
for j=1:33;

% motion vector calculation


motion_vector = abs(Pixel_1_src(Row:Row+15 , Column:Column+15) - Pixel_2_src(i:i+15 ,
j:j+15));

for c=1:16
for d =1:16

% finds the total difference


mat_diff = mat_diff + motion_vector(c,d);

end
end
temp_mat_diff(count) = abs(mat_diff);
% absolute value of total difference is stored as a vector
Name- Krishnav B. Dave The University of York
Exam Number-Y6355282
Page 10
DSP Architecture Mini Project

mat_diff = 0;
% matrix difference variable is made zero for the second time for loop execution

count = count + 1;

end
end

[min_value index] = min(temp_sum)


% minimum value and the index value are calculated

column_found = mod(index , 33);


% represents the match found for column

row_found = floor(index / 33);


% represents the match found for row

if(column_found == 0)
column_found = 33; % column and row search
else
row_found = row_found + 1;
end

if(index < 33)


row_found = 1;
end

Mean_Square_Error = min_value % Mean square error

row_found

column_found

disp('The matched matrix is')

Pixel_1_src (row_found:row_found+15 , column_found:column_found+15)

Pixel_2_src (row_found:row_found+15 , column_found:column_found+15)

end % end of function

Name- Krishnav B. Dave The University of York


Exam Number-Y6355282
Page 11
DSP Architecture Mini Project

 MATLAB output window for the above code

Mean_Square_Error =

20025

row_found =

24

column_found =

21

The matched matrix is

ans =

77 239 8 107 221 128 226 233 135 199 88 90 150 243 120 3

72 164 25 200 215 188 241 70 65 250 62 52 114 110 184 215

149 139 153 166 39 38 98 206 74 225 136 42 97 202 116 120

92 218 102 137 184 87 17 186 253 173 23 39 175 37 167 5

245 215 112 197 191 236 217 223 185 2 43 216 13 229 206 247

154 51 63 87 224 235 227 138 80 114 5 13 112 177 64 117

248 140 128 52 35 215 41 32 15 13 111 99 233 247 42 10

253 111 128 23 161 43 100 208 13 220 197 190 52 249 115 178

124 235 27 35 74 200 47 187 154 82 220 186 235 236 81 239

14 112 169 40 9 63 72 132 43 87 243 133 196 76 175 206

141 160 190 69 19 246 56 227 246 93 198 27 22 112 127 14

25 70 46 182 255 222 71 109 21 150 77 158 159 230 237 136

222 255 16 35 152 245 58 110 252 83 63 194 67 178 43 150

135 197 133 202 106 81 140 147 160 10 121 216 254 79 18 106

110 7 184 206 196 108 149 143 106 82 114 192 204 47 126 110

Name- Krishnav B. Dave The University of York


Exam Number-Y6355282
Page 12
DSP Architecture Mini Project

251 99 223 102 76 30 236 72 192 74 147 150 180 211 151 117

The most similar matrix

ans =

107 182 125 154 117 23 57 44 65 30 186 241 190 206 173 146

166 170 242 10 15 122 82 117 71 25 141 227 231 156 127 24

242 82 75 190 249 167 249 201 242 199 42 194 50 206 244 147

161 71 117 218 83 175 216 116 183 3 195 88 172 18 128 50

171 29 158 10 40 197 121 197 50 182 1 43 72 95 188 7

75 246 58 224 171 63 119 87 213 192 197 103 126 168 155 71

242 75 154 36 150 251 90 171 110 207 251 80 250 239 111 71

213 84 203 157 116 204 198 228 117 192 164 159 171 67 238 87

205 188 68 229 208 88 68 100 158 105 202 198 119 199 86 186

164 115 19 190 254 255 184 22 253 140 26 158 98 119 18 72

165 127 81 251 45 128 177 174 224 29 4 15 28 20 119 154

24 161 150 122 159 181 119 227 59 99 221 255 203 77 8 220

164 238 14

0 23 155 125 38 96 168 145 43 79 66 22 247 49

188 168 48 253 79 73 251 167 113 173 121 170 24 196 42 17

44 250 18 26 175 242 154 186 17 46 90 250 144 184 109 73

117 189 41 67 53 4 249 195 152 57 80 230 112 149 165 239

Name- Krishnav B. Dave The University of York


Exam Number-Y6355282
Page 13
DSP Architecture Mini Project

 Conclusion:
The report shows three codes for Mean square error, block search implementation and
fast search implementation which performs the task of calculating Mean square error for a
given motion vector. Mean square error leads to higher capacity for searching; this comes as
an advantage for image processing while on the other side the high computing time for Mean
square error brings down the speed performance.

Name- Krishnav B. Dave The University of York


Exam Number-Y6355282
Page 14

You might also like