Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 7529f302 authored by hhakim's avatar hhakim
Browse files

Rewrite matfaust.real/imag as done for pyfaust in e2139a44.

parent 40aa33c1
Branches
Tags
No related merge requests found
...@@ -981,30 +981,44 @@ classdef Faust ...@@ -981,30 +981,44 @@ classdef Faust
function bool = isreal(F) function bool = isreal(F)
%% %%
bool=F.is_real; bool=F.is_real;
end end
%====================================================================== %======================================================================
%> @brief Returns the real part of the Faust F. %> @brief Returns the real part of the Faust F.
%====================================================================== %======================================================================
function rF = real(F) function rF = real(F)
if isreal(F) import matfaust.Faust
rF = F; if isreal(F)
else rF = F;
rF = 1/2 * (F + conj(F)); else
end % rF = 1/2 * (F + conj(F));
end rF = cplx2real_op(F);
[Fnrows, Fncols] = size(F);
S = struct('type','()', 'subs', {{1:Fnrows, 1:2*Fncols}});
% TODO: fix strange bug, rF(1:Fnrows, 1:2*Fncols) doesn't work here
rF = subsref(rF, S);
rF = rF * Faust([ speye(Fncols) ; sparse([], [], [], Fncols, Fncols)]);
end
end
%====================================================================== %======================================================================
%> @brief Returns the imaginary part of the Faust F. %> @brief Returns the imaginary part of the Faust F.
%====================================================================== %======================================================================
function iF = imag(F) function iF = imag(F)
if isreal(F) import matfaust.Faust
iF = sparse(zeros(size(F))); % zero if isreal(F)
else iF = matfaust.Faust(sparse([], [], [], size(F, 1), size(F, 2))); % zero
iF = 1 / 2j * (F - conj(F)); else
end % iF = 1 / 2j * (F - conj(F));
end iF = cplx2real_op(F);
[Fnrows, Fncols] = size(F);
S = struct('type','()', 'subs', {{Fnrows+1:2*Fnrows, 1:2*Fncols}});
iF = subsref(iF, S);
% TODO: fix strange bug, cf. real TODO
iF = iF * Faust([speye(Fncols) ; sparse([], [], [], Fncols, Fncols)]);
end
end
%====================================================================== %======================================================================
%> @brief Returns a new Faust whose class is single. It allows to convert all the factors to single precision. %> @brief Returns a new Faust whose class is single. It allows to convert all the factors to single precision.
...@@ -3536,3 +3550,19 @@ classdef Faust ...@@ -3536,3 +3550,19 @@ classdef Faust
end end
end end
function real_op = cplx2real_op(op)
% this function is for Faust.real and Faust.imag
if matfaust.isFaust(op)
facts = cell(1, numfactors(op));
for i=1:numfactors(op)
facts{1, i} = cplx2real_op(factors(op, i));
end
real_op = matfaust.Faust(facts);
else
rop = real(op);
iop = imag(op);
real_part = [rop, -iop];
imag_part = [iop, rop];
real_op = [ real_part ; imag_part ];
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment