Sign In

Don't have a Xilinx account yet?

  • Choose to receive important news and product information
  • Gain access to special content
  • Personalize your web experience on Xilinx.com

Create Account

Username

Password

Forgot your password?
XClose Panel
Xilinx Home
Reply
Super Contributor
vlavruhin
Posts: 195
Registered: ‎12-08-2010
0

Re: Using RAM Blocks to manipulate data

Evgenia, but what is the purpose of storing the samples in memory? If you only need to find the average value, then there is no need for additional memory buffer. Just use accumulator and get the answer.

 


evgenia89 wrote:

 

But the thing is that I need to put into a memory any amount of points (let's say 1000), and then to calculate average of all these point. It should be one number but it seems that the block 'Accumulator' works for every point independently



Accumulator works on every clock cycle. You can add enable port (in parameters of Accumulator block).

 

When Enable is true, then Accumulator adds current input sample to internal register:

internal_register = internal_register + input,

output = internal_register.

 

When Enable is false, then Accumulator just outputs value of internal register:

output = internal_register.

 

When Reset is true, then Accumulator resets internal register:

internal_register = 0.

 

So with the help of Enable and Reset signals you can calculate the sum of input samples (and hence, the average value).

 

This approach will work even if you will need to find average value of long sequence (because there is no need for additional memory storage).

Best Regards,
Vitaly.
Contributor
evgenia89
Posts: 36
Registered: ‎02-06-2012
0

Re: Using RAM Blocks to manipulate data

If I don't store the samles in the memory the accumulator calculates sum at every sample as shown in the figure to my previous post. Actually the output is also a bit strange - sum is from -1 to 1 in different moments.

The 'Enable' port doesn't really help - the picture is the same when I use it.

Super Contributor
vlavruhin
Posts: 195
Registered: ‎12-08-2010

Re: Using RAM Blocks to manipulate data

Hi, Evgenia.

evgenia89 wrote:

If I don't store the samles in the memory the accumulator calculates sum at every sample as shown in the figure to my previous post.



Sure. Every block in System Generator (and in FPGA, generally) always has some output value. It's a hardware. So there is always some kind of signal at any port.

 

Lets consider that you have following input sequence:

x_1, x_2, ..., x_N.

 

You would like to calculate sum (or average value) of input samples.

 

So lets consider Accumulator block. At any clock cycle accumulator do following (if enable = true):

internal_register = internal_register + input,

output = internal_register.

 

At moment t=0:

internal_register = 0,

acc_output = 0.

 

At moment t = 1:

input = x_1,

internal_register = internal_register + input = x_1,

acc_output = internal_register = x_1.

 

At moment t = 2:

input = x_2,

internal_register = internal_register + input = x_1 + x_2, 

acc_output = internal_register = x_1 + x2.

 

...

 

At moment t = N:

input = x_N,

internal_register = internal_register + input = x_1 + x_2 + ... + x_N, 

acc_output = internal_register = x_1 + x_2 + ... + x_N.

 


evgenia89 wrote:

The 'Enable' port doesn't really help - the picture is the same when I use it.


If Enable is false, then Accumulator just skips current input sample (i.e., acuumulator doesn't add it to internal register).

 


evgenia89 wrote:

Actually the output is also a bit strange - sum is from -1 to 1 in different moments.


That's another story. I assume that your samples are integer or fixed-point fractional numbers. Right?

System Generator has different options to represent fixed-point numbers.

 

There are 'UFix_N_M' and 'Fix_N_M' formats.

N - bitwidth of number,

M - bitwidth of fractional part (i.e., position of binary point).

'Fix' means signed fractional. And 'UFix' is unsigned fractional number.

 

So if output of accumulator has type, for example, 'Fix_16_15', then you will get only numbers in range [-1, 1).

 

What is the type of your samples?

Best Regards,
Vitaly.
Contributor
evgenia89
Posts: 36
Registered: ‎02-06-2012
0

Re: Using RAM Blocks to manipulate data

Hello, Vitaly,

 

thank you very much for your response. I changed the type of accumulator output and now it works correctly.

 

But my previous problem is still not solved. I believe that I need memory anyway because my task is to calculate avearge of e.g. 1024 samples, then - the next 1024 samples, and so on and in the end the average of all these stored data should be written to a file.

I am wondering if it is possible to do with System Generator or I should use memory interface generator.

 

Evgenia.

Super Contributor
vlavruhin
Posts: 195
Registered: ‎12-08-2010
0

Re: Using RAM Blocks to manipulate data

Hello, Evgenia.

 

Average is just scaled sum, right?

So if your task is to calculate an average value of 1024 samples, then find the sum and discard log2(1024)=10 least significant bits.

 

If you need to calculate average values of different frames of data, then just reset Accumulator between these frames. Simple control logic (for example, finite state machine) can do that.

 

So if your goal is to find average value of input samples, then you don't need additional memory storage (and memory interface generator as well).

Best Regards,
Vitaly.