How can i do this matrics please ?

Consider the following operation:
R=A*B*C*D
R1=A*B
R2=R1*C
R=R2*D
Where A, B, C, and D are real 4x4 matrices and (*) is an element by element multiplication operation, i.e. Rij=Aij*Bij*Cij*Dij
The elements of A,B,C, and D are drawn randomly and are represented as 16-bit unsigned integers.
Plot the QSNR vs output word length graph for R1, R2, and R on the same axes for x-axis range from 16-32 bits
The gold standard for measuring QSNR is the noiseless result of multiplication.
After each multiplication, return the result to the 16-bit scale before doing the next multiplication
(Hint: It might help to write a fixed point multiplication function first)
_____________________________________________________
Repeat the above with the following difference:
The scale to which the output is fit does not simply truncate all the difference bits from LSB.
Instead for each single set of 16 results constituting a matrix, the algorithm will examine for the result with the left-most active bit (‘1’). It will then drop all the insignificant bits from the right, and balance the remaining bits from the LSB.
Plot R1,R2, R again.
_____________________________________________________
Write a short conclusion comparing the two methods of matrix multiplication, and give reasons for the difference in performance
I don't know how can started..any one can help me please :)

4 Comments

Well, see the hint:
(Hint: It might help to write a fixed point multiplication function first)
"The elements of A,B,C, and D are drawn randomly and are represented as 16-bit unsigned integers."
The problem there that it does not say what range they are drawn from.
This is a question about fixed point representation and how well you can preserve accuracy. You need to devise a fixed point representation and write a fixed point multiplication function.
ahmed kotb
ahmed kotb on 10 Nov 2017
Edited: ahmed kotb on 10 Nov 2017
But How Can i do this function (fixed point multiplication) ...
i need to define A B C D or what ?
You define it the same way as you define any other function: you define it to accept inputs.
function result = fixed_point_multiply(First, Second)
...
to define A or B ,C and D any one from them
A=[] or what

Sign in to comment.

 Accepted Answer

In MATLAB you can do R
R = ((A .* B) .* C) .* D;
To get random uint16 arrays for A through D, you can do
A = randi(65535, 4, 4, 'uint16')

11 Comments

thanks you for helping me ,but how can i calculate QSNR and iteration with us and plot it
Your professor should have gone over that in class. Do you have the formula for it?
this i just need to plot SQNR Vs output word length graph for R1, R2, and R on the same axes for x-axis range from 16-32 bits
The line
A = randi(65535, 4, 4, 'uint16')
should be
A = randi([0 65535], 4, 4, 'uint16')
We can tell from the reference to rescaling that this question has to do with 16 bit fixed point or floating point representation of numbers; we can tell from the hint to write a fixed point multiplication routine that it is more specifically to be about 16 bit fixed point.
In that situation,
R = ((A .* B) .* C) .* D;
can only be done if you have either used the Fixed Point Toolbox or you have defined your own Class that defines a times method .
But How Can I plotting it
Plot the QSNR vs output word length graph for R1, R2, and R on the same axes for x-axis range from 16-32 bits
You need to configure your fixed point multiplication routine to work with from 16 to 32 bits.
The point of the exercise is to demonstrate that as the number of bits you use increases, the precision of your result increases.
So for example,
for num_bits = 16:32
result(num_bits - 15) = fixed_point_multiply(num_bits, A, B, C, D);
end
plot(16:32, result)
error: Undefined function or variable 'fixed_point_multiply'.
Error in karim (line 24) result(num_bits - 15) = fixed_point_multiply(num_bits, A, B, C, D);
for num_bits = 16:32
result(num_bits - 15) = Insert_Name_of_Your_Own_Fixed_Point_Multiplication_Routine_Here(num_bits, A, B, C, D);
end
plot(16:32, result)
A=randi(2^16-1);
%A=floor(A);
B=randi(2^16-1);
%B=floor(B);
C=randi(2^16-1);
%C=floor(C);
D=randi(2^16-1);
%D=floor(D);
%A = randi(65535, 4, 4, 'uint16')
%B = randi(65535, 4, 4, 'uint16')
%C = randi(65535, 4, 4, 'uint16')
%D = randi(65535, 4, 4, 'uint16')
R = ((A .* B) .* C) .* D;
R1 = A.*B;
R2 = R1.*C;
R =R2.*D ;
for num_bits = 16:32
result(num_bits - 15) = R(num_bits, A, B, C, D);
end
plot(16:32, result)
Index exceeds matrix dimensions.
Error in karim (line 24) result(num_bits - 15) = R(num_bits, A, B, C, D);
Your R is a numeric result, not a function.
Your R is also not doing a fixed point multiplication with a variable number of bits.
"fixed point multiplication" is not the same as integer multiplication. See https://en.wikipedia.org/wiki/Fixed-point_arithmetic
An example fixed point calculation in decimal would be to say that you want to multiply 112.37 by 000.50 and that the result should be either 056.18 or 056.19 . Notice that there are fixed number of digits before the period and a fixed number of digits after the period and there are rules about how to deal with rounding of the results. For any given fixed-point scheme, the number of digits before the decimal point and the number of digit after the decimal point have to be decided ahead of time.
I suspect that in your question, the intent is that the values A, B, C, D, are intended to be numbers in the range 0 to 1, which are being represented as 16 bits, but that the multiplication scheme is to output 16 to 32 bits. Pay attention to the bit about how you have to truncate back to 16 bits before doing the next multiplication.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!