Setting Boundary Conditions in Finite Element - matlab

EDIT: See solution in the full code, following #bgb2's comment.
I'm currently trying to code a Finite Element Analysis to solve a 2D heat conduction problem. For now I'm looking at the steady state system:
where k is the thermal conductivity of the material.
Here is my code. I have verified that the stiffness matrix is correct, so I really think I'm doing something wrong when assigning the boundary conditions before solving for temperature.
Here is my commented code:
%% Input Geometry
% Local node geometry
% 4____3
% | |
% | |
% 1____2
% Global geometry
% 2____3____6(T=10)
% | | |
% | | |
% 1____4____5
% (T=3.5)
% Node 1 is at 3.5 degrees, and node 6 at 10 degrees.
% node global coordinates
node = [ 0 0 ;
0 0.05;
0.05 0.05;
0.05 0 ;
.1 0 ;
.1 0.05];
% element connections, row=element, col=nodes
conn = [1, 4, 3, 2;
4, 5, 6, 3];
%% Material Inputs
k_r = 1.4;
%% Boundary Conditions
T = zeros(6,1);
T(1) = 3.5; % node 1 fixed at 3.5 degrees
T(6) = 10; % node 6 fixed at 10 degrees
isol = [ 2, 3, 4, 5]; % unconstrained dofs,
%% Integration inputs
% Gauss Quadrature Points and weights for 2D quadrilateral elements
% local coordinates
GQ_coord = [-sqrt(1/3) -sqrt(1/3);
sqrt(1/3) -sqrt(1/3);
-sqrt(1/3) sqrt(1/3);
sqrt(1/3) sqrt(1/3)];
% GQ weights
GQ_w = [1 1 1 1];
%% SOLVER
nn = size(node,1); % number of nodes
ndof = nn; % number of dofs in the problem
ne = size(conn,1); % number of elements
K = zeros(ndof, ndof); %global stiffness matrix
f = zeros(ndof,1); % Heat flux vector
for e = 1:ne
n1 = conn(e, 1); % node id for first node in element e
n2 = conn(e, 2); % node id for second node in element e
n3 = conn(e, 3); % node id for first node in element e
n4 = conn(e, 4); % node id for second node in element e
x1 = node(n1,1); y1 = node(n1,2); % x and y coordinates for the 1st node
x2 = node(n2,1); y2 = node(n2,2); % x and y coordinates for the 2nd node
x3 = node(n3,1); y3 = node(n3,2); % x and y coordinates for the 3rd node
x4 = node(n4,1); y4 = node(n4,2); % x and y coordinates for the 4th node
global_coord = [x1, y1; x2, y2; x3 y3; x4 y4];
%Compute Stiffness of element e
ke = Ke(global_coord, GQ_coord, GQ_w, Vx, Vy, k_r)
% locations where ke is to scatter to in the global stiffness matrix
sctr = [ n1, n2 , n3, n4];
%Add ke into global K
K(sctr,sctr) = K(sctr,sctr) + ke;
end
% Accounting for boundary conditions
EDIT following #bg2b's comment
f(2) = -K(1,2) * T(1);
f(3) = -K(6,3) * T(6) + -K(1,3) * T(1);
f(4) = -K(1,4) * T(1) + -K(6,4) * T(6);
f(5) = -K(6,5) * T(6);
% computing temperature
T(isol) = K(isol,isol)\f(isol);
%% FUNCTIONS
% Shape function
% takes local coord
function s = S(ni, coord)
switch ni
case 1
s = 1/4 * (1-coord(1)) * (1-coord(2));
case 4
s = 1/4 * (1+coord(1)) * (1-coord(2));
case 3
s = 1/4 * (1+coord(1)) * (1+coord(2));
case 2
s = 1/4 * (1-coord(1)) * (1+coord(2));
end
end
% Shape function derivative
% takes local coord as an [eta nu] pair
function ds = dS(ni, dim, coord)
switch ni
case 1
if dim == 1
ds = 1/4 * (coord(2)-1);
else
ds = 1/4 * (coord(1)-1);
end
case 4
if dim == 1
ds = 1/4 * (-coord(2)-1);
else
ds = 1/4 * (1-coord(1));
end
case 3
if dim == 1
ds = 1/4 * (coord(2) + 1);
else
ds = 1/4 * (coord(1) + 1);
end
case 2
if dim == 1
ds = 1/4 * (1-coord(2));
else
ds = 1/4 * (-coord(1)-1);
end
end
end
% Computation of the element's Jacobian
function J = Je(global_coord, GQ_coord)
S = [dS(1,1, GQ_coord(1,:)) dS(2,1, GQ_coord(1,:)) dS(3,1, GQ_coord(1,:)) dS(4,1, GQ_coord(1,:));
dS(1,2, GQ_coord(1,:)) dS(2,2, GQ_coord(1,:)) dS(3,2, GQ_coord(1,:)) dS(4,2, GQ_coord(1,:))];
J = S * global_coord;
end
% Computation of the element stifness matrix
function ke = Ke(global_coord, GQ_coord, GQ_w, Vx, Vy, k_r)
J = Je(global_coord, GQ_coord)
ke = zeros(4,4);
Jinv = inv(J);
for i = 1:4
for j = 1:4
ke(i,j) = 0;
for n = 1:4
A = (Jinv(1,1) * dS(i,1, GQ_coord(n,:)) + Jinv(1,2) * dS(i,2, GQ_coord(n,:)));
B = (Jinv(1,1) * dS(j,1, GQ_coord(n,:)) + Jinv(1,2) * dS(j,2, GQ_coord(n,:)));
C = (Jinv(2,1) * dS(i,1, GQ_coord(n,:)) + Jinv(2,2) * dS(i,2, GQ_coord(n,:)));
D = (Jinv(2,1) * dS(j,1, GQ_coord(n,:)) + Jinv(2,2) * dS(j,2, GQ_coord(n,:)));
ke(i,j) = ke(i,j) + k_r * (A*B + C*D) * det(J)*GQ_w(i)*GQ_w(j);
end
end
end
end
To save having to put the code for the stiffness matrix here it is:
K =[ 0.9333 -0.2333 -0.4667 -0.2333 0 0;
-0.2333 0.9333 -0.2333 -0.4667 0 0;
-0.4667 -0.2333 1.8667 -0.4667 -0.4667 -0.2333;
-0.2333 -0.4667 -0.4667 1.8667 -0.2333 -0.4667;
0 0 -0.4667 -0.2333 0.9333 -0.2333;
0 0 -0.2333 -0.4667 -0.2333 0.9333]
So here is the cut down test code for you:
%% Input Geometry
% Local node geometry
% 4____3
% | |
% | |
% 1____2
% Global geometry
% 2____3____6(T=10)
% | | |
% | | |
% 1____4____5
% (T=3.5)
% Node 1 is at 3.5 degrees, and node 6 at 10 degrees.
%% Boundary Conditions
T = zeros(6,1);
T(1) = 3.5; % node 1 fixed at 3.5 degrees
T(6) = 10; % node 6 fixed at 10 degrees
isol = [ 2, 3, 4, 5]; % unconstrained dofs
f = zeros(ndof,1); % Heat flux vector
%global stiffness matrix
K =[ 0.9333 -0.2333 -0.4667 -0.2333 0 0;
-0.2333 0.9333 -0.2333 -0.4667 0 0;
-0.4667 -0.2333 1.8667 -0.4667 -0.4667 -0.2333;
-0.2333 -0.4667 -0.4667 1.8667 -0.2333 -0.4667;
0 0 -0.4667 -0.2333 0.9333 -0.2333;
0 0 -0.2333 -0.4667 -0.2333 0.9333]
% Accounting for boundary conditions
% I THINK THAT'S WHERE I'M GOING WRONG
f(2) = K(2,1) * T(1); % Heat outflow
f(5) = -K(5,6) * T(6); % Heat inflow
% computing temperature
T(isol) = K(isol,isol)\f(isol);
Here is what I obtain, x is the global node index, y is the temperature.
Because the only place for heat to leave the system is node 1 (as far as I can tell) I wouldn't expect to see temperature values below 3.5 degrees.
PS: I know Matlab has a FEM toolbox, but this is really a learning exercise I've set myself.
PS 2: Feel free to leave answers in Python as I am familiar with that language as well

Related

The camera calibration "Dual Absolute Quadric" cost function isn't converging

I tried to implement the cost function of the Dual Absolute Quadric in Matlab according to the following equation mentioned in this paper, with this data.
My problem is that the results didn't converge.
The code is down.
main code
%---------------------
% clear and close all
%---------------------
clearvars
close all
clc
%---------------------
% Data type long
%---------------------
format long g
%---------------------
% Read data
%---------------------
load('data.mat')
%---------------------------
% Display The Initial Guess
%---------------------------
disp('=======================================================')
disp('Initial Intrinsic parameters: ');
disp(A);
disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
%=========================================================================
DualAbsoluteQuadric = Optimize(A,#DAQ);
%---------------------
% Display The Results
%---------------------
disp('=======================================================')
disp('Dual Absoute Quadric cost function: ');
disp(DualAbsoluteQuadric);
disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
The optimization function used is:
function output = Optimize(A,func)
%------------------------------
options = optimoptions('lsqnonlin','Algorithm','levenberg-marquardt',...
'Display','iter','FunctionTolerance',1e-16,'Tolx',1e-16,...
'MaxFunctionEvaluations', 1000, 'MaxIterations',39,...
'OptimalityTolerance',1e-16);
%------------------------------
% NonLinear Optimization
%------------------------------
output_line = lsqnonlin(func,[A(1,1), A(1,3), A(2,2), A(2,3), A(1,2)],...
[],[],options);
%------------------------------------------------------------------------
output = Reshape(output_line);
The Dual Absolute Quadric Function:
function cost = DAQ(params)
Aj = [params(1) params(5) params(2) ;
0 params(3) params(4) ;
0 0 1 ];
Ai = [params(1) params(5) params(2) ;
0 params(3) params(4) ;
0 0 1 ];
% W^-1 (IAC Image of the Absolute Conic)
W_inv = Ai * Aj';
%----------------
%Find plane at infinity from MQM' ~ w (Dual Absolute Quadric)
Plane_at_infinity = PlaneAtInfinity(W_inv);
%Find H_Infty = [e21]F+e21*n'
Homography_at_infty = H_Infty(Plane_at_infinity);
%----------------
% Initialization
%----------------
global Fs;
% Initialize the cost as a vector
% (N-1 * N-2)/2: 9*8/2 = 36
vector_size = (size(Fs,3)-1)*(size(Fs,4)-2)/2;
cost = zeros(1, vector_size);
% Cost Function
k = 0;
loop_size = 3 * vector_size;
Second_Term = W_inv / norm(W_inv,'fro');
for i=1:3:loop_size
k = k+1;
First_Term = Homography_at_infty(:,i:i+2) * W_inv * ((Homography_at_infty(:,i:i+2))');
First_Term = First_Term / norm(First_Term, 'fro');
cost(k) = norm(First_Term - Second_Term,'fro');
end
end
Plane at infinity function:
function P_infty = PlaneAtInfinity(W_inv)
global PPM;
% Symbolic variables
X = sym('X', 'real');
Y = sym('Y', 'real');
Z = sym('Z', 'real');
L2 = sym('L2','real');
n = [X; Y; Z];
% DAQ
Q = [W_inv , (W_inv * n) ;
(n' * W_inv) , (n' * W_inv * n)];
% Get one only camera matrix (any)
M = PPM(:, :, 3);
% Autocalibration equation
m = M * Q * M';
% solve linear equations
solution = solve(m(1, 1) == (L2 * W_inv(1, 1)), ...
m(2, 2) == (L2 * W_inv(2, 2)), ...
m(3, 3) == (L2 * W_inv(3, 3)), ...
m(1, 3) == (L2 * W_inv(1, 3)));
P_infty = [double(solution.X(1)) double(solution.Y(1))...
double(solution.Z(1))]';
Homography at infinity function:
function H_Inf = H_Infty(planeInf)
global Fs;
k = 1;
% (3 x 3) x ((N-1)*(N-2) /2)
H_Inf = zeros(3,3*(size(Fs,3)-1)*(size(Fs,4)-2)/2);%(3*3)*36
for i = 2:size(Fs,3)
for j = i+1:size(Fs,4)
[~, ~, V] = svd(Fs(:,:,i,j)');
epip = V(:,end);
H_Inf(:,k:k+2) = epipole(Fs(:,:,i,j)) * Fs(:,:,i,j)+ epip * planeInf';
k = k+3;
end
end
end
Reshape function:
function output = Reshape(input)
%---------------------
% Reshape Intrinsics
%---------------------
% K = [a skew u0 ;
% 0 B v0 ;
% 0 0 1 ];
output = [input(1) input(5) input(2) ;
0 input(3) input(4) ;
0 0 1 ];
end
Epipole Function:
function epip = epipole(Fs)
% SVD Decompostition of (Fs)^T
[~,~,V] = svd(Fs');
% Get the epipole from the last vector of the SVD
epi = V(:,end);
% Reshape the Vector into Matrix
epip = [ 0 -epi(3) epi(2);
epi(3) 0 -epi(1);
-epi(2) epi(1) 0 ];
end
The plane at infinity has to be calculated as following:
function plane = computePlaneAtInfinity(P, K)
%Input
% P - Projection matrices
% K - Approximate Values of Intrinsics
%
%Output
% plane - coordinate of plane at infinity
% Compute the DIAC W^-1
W_invert = K * K';
% Construct Symbolic Variables to Solve for Plane at Infinity
% X,Y,Z is the coordinate of plane at infinity
% XX is the scale
X = sym('X', 'real');
Y = sym('Y', 'real');
Z = sym('Z', 'real');
XX = sym('XX', 'real');
% Define Normal to Plane at Infinity
N = [X; Y; Z];
% Equation of Dual Absolute Quadric (DAQ)
Q = [W_invert, (W_invert * N); (N' * W_invert), (N' * W_invert * N)];
% Select Any One Projection Matrix
M = P(:, :, 2);
% Left hand side of the equation
LHS = M * Q * M';
% Solve for [X, Y, Z] considering the System of Linear Equations
% We need 4 equations for 4 variables X,Y,Z,XX
S = solve(LHS(1, 1) == (XX * W_invert(1, 1)), ...
LHS(1, 2) == (XX * W_invert(1, 2)), ...
LHS(1, 3) == (XX * W_invert(1, 3)), ...
LHS(2, 2) == (XX * W_invert(2, 2)));
plane = [double(S.X(1)); double(S.Y(1)); double(S.Z(1))];
end

Matlab: ode15i solver raises error about dimensions, I fail to see where

CODE
% Why?
tstart = 0;
tfinal = 1;
tspan = [tstart tfinal];
options = odeset('Events',#myEventsFcn);
% Initial conditions
y0 = [0,-0.6,0,0,0,0];
yp0 = [0,0,0,0,0,0];
% decic funtion calculates consistent ICs
[y0,yp0] = decic(#StateI,t0,y0,[0 1 0 0 0 0],yp0,[0 0 0 0 0 0]);
% Arrays for plots
tout = tstart;
sout = y0(1:1);
bout = y0(2:2);
zout = y0(3:3);
svout = y0(4:4);
bvout = y0(5:5);
zvout = y0(6:6);
% ode15i solves system of implicit ODEs
[t,y,te,ye,ie] = ode15i(#StateI,tspan,y0,yp0,options);
% system of implicit ODEs defined as StateI function
function res = StateI(t,y,yp)
% Constants
mS = 3*10^(-4); % [kg]
JS = 5*10^(-9); % [kgm]
mB = 4.5*10^(-3); % [kg]
g = 9.81; % [m/s^2]
JB = 7*10^(-7); % [kgm]
lS = 10^(-2); % [m]
lG = 1.5*10^(-2); % [m]
cp = 5.6*10^(-3); % [N/rad]
res = [(mS+mB)*yp(6) + mB*lS*yp(4) + mB*lG*yp(5) + (mS+mB)*g;
mB*lS*yp(6) + (JS+mB*lS^2)*yp(4) + mB*lS*lG*yp(5) - cp*(y(2)-y(1)) + mB*lS*g;
mB*lG*yp(6) + mB*lS*lG*yp(4) + (JB+mB*lG^2)*yp(5) - cp*(y(1)-y(2)) + mB*lG*g;
y(4)-yp(1);
y(5)-yp(2);
y(6)-yp(3)];
end
% my events defined in myEventsFcn
function [value,isterminal,direction] = myEventsFcn(t,y,yp)
% Constants
mS = 3*10^(-4); % [kg]
mB = 4.5*10^(-3); % [kg]
g = 9.81; % [m/s^2]
rS = 3.1*10^(-3); % [m]
lS = 10^(-2); % [m]
r0 = 2.5*10^(-3); % [m]
hS = 2*10^(-2); % [m]
lG = 1.5*10^(-2); % [m]
lB = 2.01*10^(-2); % [m]
hB = 2*10^(-2); % [m]
cp = 5.6*10^(-3); % [N/rad]
Z2 = -(mS+mB)*g-mB*lG*yp(5);
Z1II = (cp*(y(2)+(rS-r0)/hS)-rS*Z2-mB*lS*lG*yp(5)-mB*lS*g)/hS;
value = [y(1)+(rS-r0)/hS, y(1)-(rS-r0)/hS, Z1II, y(2)-(lS+lG-lB- r0)/hB];
isterminal = [1, 1, 1, 1];
direction = [-1, 1, -1, 1];
end
ERROR MESSAGE
Matrix dimensions must agree.
Error in odezero (line 46)
indzc = find((sign(vL) ~= sign(vR)) & (direction .* (vR - vL) >= 0));
Error in ode15i (line 506)
[te,ye,ie,valt,stop] = odezero(#ntrp15i,#events_aux,events_args,valt,...
Error in silly (line 24)
[t,y,te,ye,ie] = ode15i(#StateI,tspan,y0,yp0,options);
So I ran this code before, no problem, then this error started popping up. I cannot see where this error might occur. I tried transposing my vectors y0 and yp0, which is not sucessful, but it does give another error message, which seems strange because I think Matlab's ode solvers can handle transposed initial conditions.
Best regards
You code runs just fine on my version of MATLAB (2018b). Check your version.

Horn-Schunck Optical Flow (Averaging Velocity)

I'm currently trying to implement the HS-method for optical flow but my u and v always seem to have only zeros in them. I can't seem to figure out my error in here:
vid=VideoReader('outback.AVI');
vid.CurrentTime = 1.5;
alpha=1;
iterations=10;
frame_one = readFrame(vid);
vid.CurrentTime = 1.6;
frame_two = readFrame(vid);
% convert to grayscale
fone_gr = rgb2gray(frame_one);
ftwo_gr = rgb2gray(frame_two);
% construct for each image
sobelx=[-1 -2 -1; 0 0 0; 1 2 1];
sobely=sobelx';
time=[-1 1];
fx_fone=imfilter(fone_gr, sobelx);
fy_fone=imfilter(fone_gr, sobely);
ft_fone=imfilter(fone_gr, time);
fx_ftwo=imfilter(ftwo_gr, sobelx);
fy_ftwo=imfilter(ftwo_gr, sobely);
ft_ftwo=imfilter(ftwo_gr, time);
Ix=double(fx_fone+fx_ftwo);
Iy=double(fy_fone+fy_ftwo);
It=double(ft_fone+ft_ftwo);
% flow-variables (velocity = 0 assumption)
velocity_kernel=[0 1 0; 1 0 1; 0 1 0];
u = double(0);
v = double(0);
% iteratively solve for u and v
for i=1:iterations
neighborhood_average_u=conv2(u, velocity_kernel, 'same');
neighborhood_average_v=conv2(v, velocity_kernel, 'same');
data_term = (Ix .* neighborhood_average_u + Iy .* neighborhood_average_v + It);
smoothness_term = alpha^2 + (Ix).^2 + (Iy).^2;
numerator_u = Ix .* data_term;
numerator_v = Iy .* data_term;
u = neighborhood_average_u - ( numerator_u ./ smoothness_term );
v = neighborhood_average_v - ( numerator_v ./ smoothness_term );
end
u(isnan(u))=0;
v(isnan(v))=0;
figure
imshow(frame_one); hold on;
quiver(u, v, 5, 'color', 'b', 'linewidth', 2);
set(gca, 'YDir', 'reverse');
The only thing I'm not really confident about is the computation of the neighborhood average:
velocity_kernel=[0 1 0; 1 0 1; 0 1 0];
u = double(0);
v = double(0);
[..]
neighborhood_average_u=conv2(u, velocity_kernel, 'same');
neighborhood_average_v=conv2(v, velocity_kernel, 'same');
Wouldn't that always result in a convolution matrix with only zeros?
I thought about changing it to the following, since I need to compute the average velocity using the velocity kernel on each pixel of my images:
velocity_kernel=[0 1 0; 1 0 1; 0 1 0];
u = double(0);
v = double(0);
[..]
neighborhood_average_u=conv2(Ix, velocity_kernel, 'same');
neighborhood_average_v=conv2(Iy, velocity_kernel, 'same');
But I still don't know if that would be the correct way. I followed the instructions on the bottom of this MATLAB page:
http://de.mathworks.com/help/vision/ref/opticalflowhs-class.html
I found this paper with some further explanations and also some matlab code.
They compute the average of u and v as follows:
% initial values
u = 0; v = 0;
% weighted average kernel
kernel = [1/12 1/6 1/12; 1/6 0 1/6; 1/12 1/6 1/12];
for i = 1:iterations
uAvg = conv2( u, kernel 'same' );
vAvg = conv2( v, kernel 'same' );
...
end

How to test the fundamental matrix?

In my application, I use 2 cameras for 3D object reconstruction.
To calibrate the cameras, I compute the fundamental matrix using 2 sets of images in order to find the camera pose (rotation and translation).
I use SVD to find the R and T.
But when I try to check the accuracy of my matrices, it doesn't work at all: the position of the reconstructed points doesn't feat with the real positions.
How can I check if I am in the right way?
Here is my Matlab code that i use :
D2=[-0.168164529475, 0.110811875773, -0.000204013531649, -9.05039442317e-05, 0.0737585102411];
D1=[-0.187817541965, 0.351429195367, -0.000521080240718, -0.00052088823018, -1.00569541826];
K2=[2178.5537139, 0.0, 657.445233702;0.0, 2178.40086319, 494.319735021;0.0, 0.0, 1.0];
K1=[2203.30000377, 0.0, 679.24264123;0.0, 2202.99249047, 506.265831986;0.0, 0.0, 1.0];
load pts1.dat; % load image points from CAM42
load pts2.dat; % load image points from CAM49
% calcul de la matrice fondamentale
disp('Finding stereo camera matrices ...');
disp('(By default RANSAC optimasation method is used.)');
disp('- 4 : LTS');
disp('- 3 : MSAC');
disp('- 2 : RANSAC');
disp('- 1 : Norm8Point');
disp('- 0 : LMedS');
c = input('Chose method to find F :', 's');
if nargin > 0
switch c
case 4
method = 'LTS';
case 3
method = 'MSAC';
case 2
method = 'RANSAC';
case 1
method = 'Norm8Point';
otherwise
method = 'LMedS';
end
else
method = 'RANSAC';
end
%F = estimateFundamentalMatrix(points2', points1', 'Method', method, 'NumTrials', 4000, 'DistanceThreshold', 1e-4)
% calcul de la matrice essentielle
E = K2' * F * K1;
% calcul de R et T à partir de la décomposition SVD
[U S V] = svd(E);
Z = [0 -1 0;
1 0 0;
0 0 0]; % matrice anti-symetrique
W = [0 -1 0;
1 0 0;
0 0 1]; % matrice orthogonale
fprintf(sprintf('\ndev(Vt) = %f', det(V')));
fprintf(sprintf('\ndet(U) = %f', det(U )));
Ra = U * W * V'
Rb = U * W'* V'
T = U * Z * U';
T0 = U(: , 3)
T = [T(2,1); -T(3, 1); T(3, 2)];
disp('=======================');
% R1 = [Ra T0]
% R2 = [Ra -T0]
% R3 = [Rb T0]
% R4 = [Rb -T0]
% test des matrices trouvées. ---------------------------------------------
pti = 10; % point index
x1 = points1(pti,:)';
disp('x1 (real):'); x1 = [x1;1]
x2 = points2(pti,:)';
disp('x2 (real):'); x2 = [x2;1]
disp('===========');
x2 = Ra*x1 + T0 % [Ra, T0]
x2 = Ra*x1 - T0 % [Ra, -T0]
x2 = Rb*x1 + T % [Rb, T0]
x2 = Rb*x1 - T % [Rb, -T0]
fprintf('\nx1t*F*x2 = %f\n',x2'*F*x1);
disp('Epipolar line');
l1 = F*x1
l2 = F*x2
Thank you.
your fundamental matrix has to satisfy the correspondence condition
x' * F * x = 0
for point correspondences x' and x. (see http://www.robots.ox.ac.uk/~vgg/hzbook/hzbook2/HZepipolar.pdf, pp 257-260)
you may have a look at the question camera-motion-from-corresponding-images, which probably help you to check if you are on the right way.

Matlab error: Undefined function 'dmod' for input arguments of type 'double'. How come there is no dmod function as it should come with Matlab?

I have been working on some exam and need to do an exercise involving some frequency shift keying. That is why I use dmod function from Matlab - it comes with Matlab. But as I write in my console
yfsk=dmod([1 0], 3, 0.5, 100,'fsk', 2, 1);
it gives me this
`Undefined function 'dmod' for input arguments of type 'double'.
I have also tried doc dmod and it says 'page not found' in matlab help window.
Do you know wheter this is because I didn't install all the matlab packages or this function is not suported with matlab 2012a?
Thank you
This is gonna be helpful:
function [y, t] = dmod(x, Fc, Fd, Fs, method, M, opt2, opt3)
%DMOD
%
%WARNING: This is an obsolete function and may be removed in the future.
% Please use MODEM.PAMMOD, MODEM.QAMMOD, MODEM.GENQAMMOD, FSKMOD,
% MODEM.PSKMOD, or MODEM.MSKMOD instead.
% Y = DMOD(X, Fc, Fd, Fs, METHOD...) modulates the message signal X
% with carrier frequency Fc (Hz) and symbol frequency Fd (Hz). The
% sample frequency of Y is Fs (Hz), where Fs > Fc and where Fs/Fd is
% a positive integer. For information about METHOD and subsequent
% parameters, and about using a specific modulation technique,
% type one of these commands at the MATLAB prompt:
%
% FOR DETAILS, TYPE MODULATION TECHNIQUE
% dmod ask % M-ary amplitude shift keying modulation
% dmod psk % M-ary phase shift keying modulation
% dmod qask % M-ary quadrature amplitude shift keying
% % modulation
% dmod fsk % M-ary frequency shift keying modulation
% dmod msk % Minimum shift keying modulation
%
% For baseband simulation, use DMODCE. To plot signal constellations,
% use MODMAP.
%
% See also DDEMOD, DMODCE, DDEMODCE, MODMAP, AMOD, ADEMOD.
% Copyright 1996-2007 The MathWorks, Inc.
% $Revision: 1.1.6.5 $ $Date: 2007/06/08 15:53:47 $
warnobsolete(mfilename, 'Please use MODEM.PAMMOD, MODEM.QAMMOD, MODEM.GENQAMMOD, FSKMOD, MODEM.PSKMOD, or MODEM.MSKMOD instead.');
swqaskenco = warning('off', 'comm:obsolete:qaskenco');
swapkconst = warning('off', 'comm:obsolete:apkconst');
swmodmap = warning('off', 'comm:obsolete:modmap');
swamod = warning('off', 'comm:obsolete:amod');
opt_pos = 6; % position of 1st optional parameter
if nargout > 0
y = []; t = [];
end
if nargin < 1
feval('help','dmod')
return;
elseif isstr(x)
method = lower(deblank(x));
if length(method) < 3
error('Invalid method option for DMOD.')
end
if nargin == 1
% help lines for individual modulation method.
addition = 'See also DDEMOD, DMODCE, DDEMODCE, MODMAP, AMOD, ADEMOD.';
if method(1:3) == 'qas'
callhelp('dmod.hlp', method(1:4), addition);
else
callhelp('dmod.hlp', method(1:3), addition);
end
else
% plot constellation, make a shift.
opt_pos = opt_pos - 3;
M = Fc;
if nargin >= opt_pos
opt2 = Fd;
else
modmap(method, M);
return;
end
if nargin >= opt_pos+1
opt3 = Fs;
else
modmap(method, M, opt2);
return;
end
modmap(method, M, opt2, opt3); % plot constellation
end
return;
end
if (nargin < 4)
error('Usage: Y = DMOD(X, Fc, Fd, Fs, METHOD, OPT1, OPT2, OPT3) for passband modulation');
elseif nargin < opt_pos-1
method = 'samp';
else
method = lower(method);
end
len_x = length(x);
if length(Fs) > 1
ini_phase = Fs(2);
Fs = Fs(1);
else
ini_phase = 0; % default initial phase
end
if ~isfinite(Fs) | ~isreal(Fs) | Fs<=0
error('Fs must be a positive number.');
elseif length(Fd)~=1 | ~isfinite(Fd) | ~isreal(Fd) | Fd<=0
error('Fd must be a positive number.');
else
FsDFd = Fs/Fd; % oversampling rate
if ceil(FsDFd) ~= FsDFd
error('Fs/Fd must be a positive integer.');
end
end
if length(Fc) ~= 1 | ~isfinite(Fc) | ~isreal(Fc) | Fc <= 0
error('Fc must be a positive number. For baseband modulation, use DMODCE.');
elseif Fs/Fc < 2
warning('Fs/Fc must be much larger than 2 for accurate simulation.');
end
% determine M
if isempty(findstr(method, '/arb')) & isempty(findstr(method, '/cir'))
if nargin < opt_pos
M = max(max(x)) + 1;
M = 2^(ceil(log(M)/log(2)));
M = max(2, M);
elseif length(M) ~= 1 | ~isfinite(M) | ~isreal(M) | M <= 0 | ceil(M) ~= M
error('Alphabet size M must be a positive integer.');
end
end
if isempty(x)
y = [];
return;
end
[r, c] = size(x);
if r == 1
x = x(:);
len_x = c;
else
len_x = r;
end
% expand x from Fd to Fs.
if isempty(findstr(method, '/nomap'))
if ~isreal(x) | all(ceil(x)~=x)
error('Elements of input X must be integers in [0, M-1].');
end
yy = [];
for i = 1 : size(x, 2)
tmp = x(:, ones(1, FsDFd)*i)';
yy = [yy tmp(:)];
end
x = yy;
clear yy tmp;
end
if strncmpi(method, 'ask', 3)
if isempty(findstr(method, '/nomap'))
% --- Check that the data does not exceed the limits defined by M
if (min(min(x)) < 0) | (max(max(x)) > (M-1))
error('An element in input X is outside the permitted range.');
end
y = (x - (M - 1) / 2 ) * 2 / (M - 1);
else
y = x;
end
[y, t] = amod(y, Fc, [Fs, ini_phase], 'amdsb-sc');
elseif strncmpi(method, 'fsk', 3)
if nargin < opt_pos + 1
Tone = Fd;
else
Tone = opt2;
end
if (min(min(x)) < 0) | (max(max(x)) > (M-1))
error('An element in input X is outside the permitted range.');
end
[len_y, wid_y] = size(x);
t = (0:1/Fs:((len_y-1)/Fs))'; % column vector with all the time samples
t = t(:, ones(1, wid_y)); % replicate time vector for multi-channel operation
osc_freqs = pi*[-(M-1):2:(M-1)]*Tone;
osc_output = (0:1/Fs:((len_y-1)/Fs))'*osc_freqs;
mod_phase = zeros(size(x))+ini_phase;
for index = 1:M
mod_phase = mod_phase + (osc_output(:,index)*ones(1,wid_y)).*(x==index-1);
end
y = cos(2*pi*Fc*t+mod_phase);
elseif strncmpi(method, 'psk', 3)
% PSK is a special case of QASK.
[len_y, wid_y] = size(x);
t = (0:1/Fs:((len_y-1)/Fs))';
if findstr(method, '/nomap')
y = dmod(x, Fc, Fs, [Fs, ini_phase], 'qask/cir/nomap', M);
else
y = dmod(x, Fc, Fs, [Fs, ini_phase], 'qask/cir', M);
end
elseif strncmpi(method, 'msk', 3)
M = 2;
Tone = Fd/2;
if isempty(findstr(method, '/nomap'))
% Check that the data is binary
if (min(min(x)) < 0) | (max(max(x)) > (1))
error('An element in input X is outside the permitted range.');
end
x = (x-1/2) * Tone;
end
[len_y, wid_y] = size(x);
t = (0:1/Fs:((len_y-1)/Fs))'; % column vector with all the time samples
t = t(:, ones(1, wid_y)); % replicate time vector for multi-channel operation
x = 2 * pi * x / Fs; % scale the input frequency vector by the sampling frequency to find the incremental phase
x = [0; x(1:end-1)];
y = cos(2*pi*Fc*t+cumsum(x)+ini_phase);
elseif (strncmpi(method, 'qask', 4) | strncmpi(method, 'qam', 3) |...
strncmpi(method, 'qsk', 3) )
if findstr(method,'nomap')
[y, t] = amod(x, Fc, [Fs, ini_phase], 'qam');
else
if findstr(method, '/ar') % arbitrary constellation
if nargin < opt_pos + 1
error('Incorrect format for METHOD=''qask/arbitrary''.');
end
I = M;
Q = opt2;
M = length(I);
% leave to the end for processing
CMPLEX = I + j*Q;
elseif findstr(method, '/ci') % circular constellation
if nargin < opt_pos
error('Incorrect format for METHOD=''qask/circle''.');
end
NIC = M;
M = length(NIC);
if nargin < opt_pos+1
AIC = [1 : M];
else
AIC = opt2;
end
if nargin < opt_pos + 2
PIC = NIC * 0;
else
PIC = opt3;
end
CMPLEX = apkconst(NIC, AIC, PIC);
M = sum(NIC);
else % square constellation
[I, Q] = qaskenco(M);
CMPLEX = I + j * Q;
end
y = [];
x = x + 1;
% --- Check that the data does not exceed the limits defined by M
if (min(min(x)) < 1) | (max(max(x)) > M)
error('An element in input X is outside the permitted range.');
end
for i = 1 : size(x, 2)
tmp = CMPLEX(x(:, i));
y = [y tmp(:)];
end
ind_y = [1: size(y, 2)]';
ind_y = [ind_y, ind_y+size(y, 2)]';
ind_y = ind_y(:);
y = [real(y) imag(y)];
y = y(:, ind_y);
[y, t] = amod(y, Fc, [Fs, ini_phase], 'qam');
end
elseif strncmpi(method, 'samp', 4)
% This is for converting an input signal from sampling frequency Fd
% to sampling frequency Fs.
[len_y, wid_y] = size(x);
t = (0:1/Fs:((len_y-1)/Fs))';
y = x;
else % invalid method
error(sprintf(['You have used an invalid method.\n',...
'The method should be one of the following strings:\n',...
'\t''ask'' Amplitude shift keying modulation;\n',...
'\t''psk'' Phase shift keying modulation;\n',...
'\t''qask'' Quadrature amplitude shift-keying modulation, square constellation;\n',...
'\t''qask/cir'' Quadrature amplitude shift-keying modulation, circle constellation;\n',...
'\t''qask/arb'' Quadrature amplitude shift-keying modulation, user defined constellation;\n',...
'\t''fsk'' Frequency shift keying modulation;\n',...
'\t''msk'' Minimum shift keying modulation.']));
end
if r==1 & ~isempty(y)
y = y.';
end
warning(swqaskenco);
warning(swapkconst);
warning(swmodmap);
warning(swamod);
% [EOF]
I do believe that dmod function (Communication Toolbox) has been abandoned in the latest MATLAB releases.
It looks like dmod is no more :-)
Here is the link that says it was removed:
http://www.mathworks.com/help/comm/release-notes.html?searchHighlight=dmod
It should be replaced wit with comm.FSKModulator System object
I think you may be looking for the demodulation function (demod) from the signal processing toolbox.
http://www.mathworks.com.au/help/signal/ref/demod.html