why I cannot create a rigid3d object from this rotation and translation? - matlab

Here's my code
pose2 = rigid3d(R,T');
or
pose2 = rigid3d([R,T;0 0 0 1]');
I do check my rotation matrix R' = inv(R), but I get this error.
Error using rigid3d (line 143)
The transformation matrix is not rigid.
A rigid transformation matrix must only contain a rotation and a translation.
The final column must consist of zeros, except for a one in the last row.
Error in SyntheticCalibFace (line 106)
pose2 = rigid3d(R,T');
R =
-4.306559634198784e-01 1.050608066598688e-01 -8.963803144173090e-01
1.050608066598688e-01 9.922848166308009e-01 6.582605554000008e-02
-8.963803144173090e-01 6.582605554000008e-02 4.383711467890774e-01
T =
3.114542669304700e+01
-2.287177166140948e+00
1.951422849770145e+01

Related

Noise cancellation with fft failing - unable to assign elements

I have the following code for noise cancellation:
[z,fs] = audioread('noisy_voices.wav'); % Use >>soundsc(z, fs) to hear the unprocessed signal
zproc_vec=zeros(1,length(z));
tail = zeros(1,256);
for k = 0:128:length(z)-256
Z = fft(z(k +1:k + 256).* hann(256));
[zmax, zl] = max(abs(Z(1:128)));
Z(zl-3: zl +3)=0;
Z(256-(zl-3:zl +3)+2)=0;
zproc = ifft(Z);
zproc = zproc+tail;
tail(1:128) = zproc(129:256);
zproc_vec(k+1:k+256)=zproc;
end
soundsc(zproc_vec , fs)
Could anyone tell me why I get this error?
Unable to perform assignments because the left and right sides have a different number of elements
Error in task_one (line 12)
zproc_vec(k+1:k+256)=zproc;
I think the output of your Z = fft( ___ ) line will be a column vector, but you initialise tail to be a row vector with tail = zeros(1,256);
So on this line:
zproc = zproc+tail;
Implicit expansion would make zproc a square 256*256 matrix.
Then your indexing fails, as specified by the error message, because you're trying to assign this square matrix to the 256 elements you're indexing with zproc_vec(k+1:k+256).
Initialising tail to a column vector should solve the issue.
Alternatively you could take the "lazy" way out and make sure you're only operating on column vectors to create zproc
zproc = zproc(:)+tail(:); % Make both terms column vectors for addition
''Unable to perform assignments because the left and right sides have a different number of elements''
What part of the error message do you not understand? It means that the variables on the left and the right side of the equal sign have different sizes so you can't assign the right thingy to the left thingy.
Check the sizes and make sure they are the same.

Calculating numerical integral using MATLAB

I have an equation of the following form:
where A,B,C, and q are 3-by-3 matrix and Tr[...] represent trace. And
here b is a constant. The explicit form of A,B(x,y,E),C(x,y,E), q(x,y) matrices is written in the below MATLAB code. I am trying to solve it using the integral3() function of MATLAB. But it is giving me errors.
I wrote the function for the integrant in two different ways. And run the script:
integral3(#fun1,-pi,pi,-pi,pi,-inf,inf)
function file 1:
function out = fun1(x,y,E)
%=============just some constants==========
DbyJ = 2/sqrt(3);
T = 1e-2;
eta = 1e-3;
b = 1/T;
D = 1+1i*DbyJ;
fk1 = 1+exp(1i*x);
fk2 = 1+exp(1i*y);
fk1k2 = 1+exp(1i*(x-y));
%=============Matrices==========
A = eye(3); A(1,1) = 1;
q = [0, 1i*D*exp(-1i*x), 0 ;
-1i*conj(D)*exp(1i*x), 0,-1i*D*exp(1i*(x-y));
0,1i*conj(D)*exp(1i*(y-x)),0];
h = [0 -D*conj(fk1) -conj(D)*conj(fk2);
-conj(D)*fk1 0 -D*fk1k2;
-D*fk2 -conj(D)*conj(fk1k2) 0];
B = ((E-1i*eta)*eye(3) - h)^(-1);
C = conj(B);
Term1 = A*(B-C)*q*(B-C);
trc = trace(Term1);
N = -b*exp(b*E)/((exp(b*E)-1)^2);
out = trc*E*N;
It gave me the following error:
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in fun1 (line 19)
q = [0, 1i*D*exp(-1i*x), 0 ;
Then I tried to solve Tr[...] part symbolically and removed the matrices from integrant. The function file is very large for this, so, I am not putting it here. Anyway, it give me error that
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'.
Error in fun1 (line 33)
trc = (D*exp(-x*1i)*((exp(conj(x ... (it is a very long expression that I calculated symbolically to remove matrices.)
Question:
Why integral3() is not working?
Is there any other way to solve this kind of integrals numerically? (In Python or in any other software/language).
Thank you for reading.
TLDD:
How can I solve the above given integral numerically?

Given a pixel coordinates, how can I extract all his neighbors?

I want to build a 3x3 block for a given matrix point with that point in the center of the block. This is my code :
function frmBlock = fetchNeighbors(frame, row, column)
%Create a 3x3 matrix contains the neighbors of the point(x, y)
%[n, m] = size(frame);
frmBlock = zeros(3, 3);
x = floor(row);
y = floor(column);
frmBlock(1) = frame(x-1, y-1);
frmBlock(2) = frame(x, y-1);
frmBlock(3) = frame(x+1, y+1);
frmBlock(4) = frame(x-1, y);
frmBlock(5) = frame(x, y);
frmBlock(6) = frame(x+1, y);
frmBlock(7) = frame(x-1, y+1);
frmBlock(8) = frame(x, y+1);
frmBlock(9) = frame(x+1, y-1);
end
As you can see, I create a 3x3 matrix initialized by 0. What I want to do is to fill that matrix with all the neighbors of the coordinate in input(row, column). If I can't get the neighbors for some reason I do nothing (i.e let that position in the 3x3 block as 0).
When I run this code I got an error saying:
Error using fetchNeighbors (line 12) Index exceeds matrix dimensions.
Can someone help ?
I'm guessing that the error is due to the fact that you are taking row and column to be on the boundaries of the matrix frame, and then when you try to access the element just right or left or below or above (depends on which boundary you are on), you are out of bounds and this raises the error. For example, if row equals 1, this means that at some point you are trying to access frame(0,column), which is illegal.
You can fix this by adding a check (using an if statement) before any access to the matrix, to make sure you are in bounds. I add here an alternative approach:
function frmBlock = fetchNeighbors(frame, row, column)
% Create a 3x3 matrix that contains the neighbors of the point (row,column)
[n,m] = size(frame);
neighbors_x = max(row-1,1):min(row+1,n);
neighbors_y = max(column-1,1):min(column+1,m);
frmBlock = zeros(3,3);
frmBlock(neighbors_x-row+2,neighbors_y-column+2) = frame(neighbors_x,neighbors_y);
end

Matlab invalid vector using lpsolve

I am using a function in Matlab based on lp_solve. In my case, lp_solve is structured as follows:
A = rand (13336,3); %A is made of real numbers between 0 and 1. For this mwe, I thought 'rand' was fine
W = [0; 0; 1];
C = A(:,3);
B = 1E+09;
e = -1;
m= 13336;
xint = linspace(1,13336,13336);
xint = xint';
obj = lp_solve(A*W,C,B,e,zeros(m,1),ones(m,1),xint)
But when I run it, I get this error:
Error using mxlpsolve
invalid vector.
Error in lp_solve (line 46)
mxlpsolve('set_rh_vec', lp, b);
Error in mylpsolvefunction (line 32) %This is my function that uses lp_solve
obj = lp_solve(A*W,C,B,e,zeros(m,1),ones(m,1),xint);
I looked in the documentation, and it say, under the chapter "Matrices" that:
[...] if a dense matrix is provided, the dimension must exactly match the dimension that is expected by mxlpsolve. Matrices with too few or too much elements gives an 'invalid vector.' error. Sparse matrices can off course provide less elements (the non provided elements are seen as zero). However if too many elements are provided or an element with a too large index, again an 'invalid vector.' error is raised.
I did not understand what they mean when they say that the dimension "must exactly match the dimensions that is expected by mxlpsolve". Anyway, since they say that the error my also occur "if too many elements are provided", I tried to "cut" my inputs from 13336 elements to 50 (I am sure it works with 58 and I am quite sure it does also with 2000), but also this way I receive the same error. What may the problem be?

Matlab error: Index exceeds matrix dimensions

I'm trying to perform STFT on an audio file. I need to get the fft of each window.
I used the follwing code.
[wave,fs] = wavread('40.wav');
w_length = 1024;
for v = 1:w_length:length(wave)
data_sub = wave(v:v+w_length);
subsection_fft = fft(data_sub);
figure(1)
plot(subsection_fft)
end
But i get the following error.
??? Index exceeds matrix dimensions.
Error in ==> chk at 7
data_sub = wave(v:v+w_length);
Can you tell me what I can do to rectify this.
As the error message says, you are trying to access a position in wave tat does not exist.
See this example:
a = rand(7,1);
step = 4;
1:step:7
ans =
1 5
when v = 5, you will try to access position v:v+step, i.e. 5 to 9, but a is only defined up to 7 elements.
In your case, wave is defined up to length(wave), but on the last iteration you will go out of bounds.
To avoid it, on approach would be to sample the end sequences and subtract the length of the sequence:
pos = (1+w_length:w_length:length(wave))-w_length
for v = pos
% do stuff
end
However, you will be left with some unprocessed part which you will have to do outside of the loop as last iteration.