fena
Newbie level 3
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.
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.