From: raj on
Hai,

I want to view the the numbers with more precision
for example:

inp=[0.01 0.02 0.03];
outfile1 = fopen('imp_in.txt','w');
fprintf(outfile1, '%15.15f\n', Inp);

with the above i am getting the imp_in.txt file contents as
0.010000000000000
0.020000000000000
0.030000000000000

But my requirement is it should be like this:
0.009765625 instead of 0.010000000000000
0.019775390625 instead of 0.020000000000000
..02978515625 instead of 0.030000000000000

What is modification i should do in the above code?and how it can be
achieved ?I tried fixed point also but not meeting my requirement?
which data type will do this?

regards,
raj

From: julius on
On Jun 24, 3:44 am, raj <rajesh.o...(a)gmail.com> wrote:
> Hai,
>
> I want to view the the numbers with more precision
> for example:
>
> inp=[0.01 0.02 0.03];
> outfile1 = fopen('imp_in.txt','w');
> fprintf(outfile1, '%15.15f\n', Inp);
>
> with the above i am getting the imp_in.txt file contents as
> 0.010000000000000
> 0.020000000000000
> 0.030000000000000
>
> But my requirement is it should be like this:
> 0.009765625 instead of 0.010000000000000
> 0.019775390625 instead of 0.020000000000000
> .02978515625 instead of 0.030000000000000
>
> What is modification i should do in the above code?and how it can be
> achieved ?I tried fixed point also but not meeting my requirement?
> which data type will do this?
>
> regards,
> raj

Does "my requirement" mean "my homework"?
I don't fully understand what it is you are trying to do, but
my guess is that you have to learn to make a quantizer
in MATLAB, with a prescribed precision.

Julius
From: Darol Klawetter on
On Jun 24, 3:44 am, raj <rajesh.o...(a)gmail.com> wrote:
> Hai,
>
> I want to view the the numbers with more precision
> for example:
>
> inp=[0.01 0.02 0.03];
> outfile1 = fopen('imp_in.txt','w');
> fprintf(outfile1, '%15.15f\n', Inp);
>
> with the above i am getting the imp_in.txt file contents as
> 0.010000000000000
> 0.020000000000000
> 0.030000000000000
>
> But my requirement is it should be like this:
> 0.009765625 instead of 0.010000000000000
> 0.019775390625 instead of 0.020000000000000
> .02978515625 instead of 0.030000000000000
>
> What is modification i should do in the above code?and how it can be
> achieved ?I tried fixed point also but not meeting my requirement?
> which data type will do this?
>
> regards,
> raj

The fprintf command above will write to the file, not read from it.
The file contents that you list is what I would expect to see after
you execute the fprintf command.
From: cpshah99 on
>Hai,
>
>I want to view the the numbers with more precision
>for example:
>
>inp=[0.01 0.02 0.03];
>outfile1 = fopen('imp_in.txt','w');
>fprintf(outfile1, '%15.15f\n', Inp);
>
>with the above i am getting the imp_in.txt file contents as
>0.010000000000000
>0.020000000000000
>0.030000000000000
>
>But my requirement is it should be like this:
>0.009765625 instead of 0.010000000000000
>0.019775390625 instead of 0.020000000000000
>.02978515625 instead of 0.030000000000000
>
>What is modification i should do in the above code?and how it can be
>achieved ?I tried fixed point also but not meeting my requirement?
>which data type will do this?
>
>regards,
>raj
>
>
%%%%%

how can u expect matlab to give you what u want?

if u enter 0.1 is i/p it will definately give 0.1000.

try this.

inp=[1/12 1/13 1/14];
outfile1 = fopen('imp_in.txt','w');
fprintf(outfile1, '%15.15f\n', inp);

so if u enter 1/13 on matlab command window it will give u 0.0769 but if u
open that text file it will give 0.076923076923077

chintan
From: Andrew FPGA on
> What is modification i should do in the above code?and how it can be
> achieved ?I tried fixed point also but not meeting my requirement?
> which data type will do this?

Hi Raj, sounds like you are getting confused between quantising your
filter coefficients and printing the coefficients to a text file. It
would help if you think about them as two separate steps.

1) Use the fixed point toolbox to quantise your coefficients. You
specify signed/unsigned, and the wordlength. You can specify the
decimal point location by setting the fraction length or you can let
matlab determine the optimum position.
e.g. coeff = fi( 0.1, 1, 16, 15 );

What this does is take a floating point number (0.1) and creates a
matlab fixed point representation in coeff.

2) Now you want to print the fixed point number to a file, so that
your synthesis tool can pick it up.
fprintf( fileid, '%f', coeff ) does not work because coeff is a matlab
fixed point object. fprintf does not work with fixed point objects.
What you can do is extract the fixed point number as an integer and
print that.

e.g.
str = num2str( coeff.int ).
fprintf( fileid, str ).
(make sure the file is opened in text mode).

Regards
Andrew