Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

energy calculation in vhdl??

Status
Not open for further replies.

fena

Newbie level 3
Joined
Nov 24, 2009
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
turkey
Activity points
1,349
I need to calculate the energy of an incoming FSK-modulated digital signal. To do that, firstly, I multiplied the signal with itself by a simple multiplier (i.e. squared it), then, for the integration part, I summed up the first 40 elements of the signal and for every next squared input, I added it to sum and substracted the earliest input (i.e. 40th). However, it seems like not working. I tried to change the value 40 but didnt work What is wrong with my logic? my vhdl code for this part was as follows:
process(clkin)
variable cnt,flag : integer := 0 ;
variable toplam : integer := 0 ;
begin
if clkin'event and clkin = '1' then
if cnt=39 then
if flag=0 then
outp<=to_signed(toplam,22);
flag:=1;
else
toplam:=toplam-my_integers(0);
my_integers<= 0 & my_integers(39 downto 1);
my_integers(39)<=to_integer(signed(datain));
toplam:=toplam+my_integers(39);
outp<=to_signed(toplam,22);
end if;
else
my_integers(cnt)<=to_integer(signed(datain));
toplam:=toplam+to_integer(signed(datain));
cnt:=cnt+1;
end if;

here, my_integers is the vector that I store the squared inputs, datain is the incoming squared data and toplam is the current sum.
 

hi, as per my knowledge in vhdl the code you have written is having some mistake. i ahve pasted a part of your code below. All statements in one process (which are assigned to the same event) gets updated simultaneously thats why you cannot assign single variable or signal different values at a time e.g. for variable toplam you have assigned different values at the same time so it will not get modified or execution of that may affect your other statements also.
if flag=0 then
outp<=to_signed(toplam,22);
flag:=1;
else
toplam:=toplam-my_integers(0);
my_integers<= 0 & my_integers(39 downto 1);
my_integers(39)<=to_integer(signed(datain));
toplam:=toplam+my_integers(39);
outp<=to_signed(toplam,22);
end if;
else
my_integers(cnt)<=to_integer(signed(datain));
toplam:=toplam+to_integer(signed(datain));
 

so sorry. there sohuld be another "end if" statement in the end. I forgot to copy that part.

My code was actually like this:


if clkin'event and clkin = '1' then
if cnt=39 then
if flag=0 then
outp<=to_signed(toplam,22);
flag:=1;
else
toplam:=toplam-my_integers(0);
my_integers<= 0 & my_integers(39 downto 1);
my_integers(39)<=to_integer(signed(datain));
toplam:=toplam+my_integers(39);
outp<=to_signed(toplam,22);
end if;
else
my_integers(cnt)<=to_integer(signed(datain));
toplam:=toplam+to_integer(signed(datain));
cnt:=cnt+1;
end if

end if;
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top