I appreciate any hint.
Regards,
Mike
I hope you mean the additive inverse, -mod, or the multiplicative
inverse, 1./mod, because if you want to unmod something I'm afraid
you're out of luck.
Suppose you want to know if a number is even or odd,
B = mod(A,2);
Now B is either 0 or 1. Do you think there could be any way to get back
the original number, A, knowing only whether it is even or odd?
--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.
Actually, there are some things one can do,
although the original question was not specific
enough to answer it.
For starters, is the OP asking for an additive
inverse or a multiplicative inverse? Both CAN be
done, within limits. An additive inverse always
exists in modular arithmetic. Thus 4 is the
additive inverse of 3, mod 7.
A multiplicative inverse is more difficult, since it
does not always exist. Here we are looking for
x such that mod(x*A,p) == 1. You can find a
tool for the modular (multiplicative) inverse in
my vpi toolbox, called minv.m. It uses the
extended Euclidean algorithm.
>> a = 35;
>> p = vpi(2^31 - 1);
>> ainv = minv(a,p)
ainv =
1656630242
>> mod(a*ainv,p)
ans =
1
HTH,
John
Thank you very much Guys, I really do appreciate your contributions.
My question came from a simulink block uses this equation:
wt = mod(A, 2*pi)
Now, if I know wt and pi, can I get the value of A?
John, if I use your vpi toolbox, can it calculate the value of A?
Many thanks
Not exactly, no. Think about it, suppose wt is 0.1. You can't know if
A is 2*pi + 0.1 or 4*pi + 0.1 or 6*pi + 0.1, etc.
However, if you're trying to unwrap phase and you have a vector of phase
values then take a look at the function unwrap.
I don't think you are THINKING about what the mod function does. Look closely at this example:
A = [1:20]*pi;
wt = mod(A, 2*pi)'
Study wt. Now suppose I randomly chose one element from A, and only showed you the corresponding element of wt. Could you tell me which element I chose from A with certainty?
Doug Matt, Thank you very much.
In fact, what I'm trying to find is the phase from the wt vector. (w=2*pi*f, and t is time). unfortunately when used d(unwrap (wt))/dt, I couldn't get the right phase of the signal. That is why I'm trying with the inverse of mod !
Matt, you're right, I didn't think much about the mod operator! with your example, it is now clear that impossible to give you the element from A you chose. But do you have any suggestions about the phase!
Once again, many thanks,
Mike