since the state is not changed i think i can just put: (lstate = state;) in the : ( if (state != lstate)) loop.
You are right, but I have always thought that it was more explicit to save the current state before reading it again. At the moment you are incrementing freq at every change of state, which is not strictly neccessary. You could add a test to see whether the state is HIGH (or LOW) when it changes. This will halve the number of times that freq is updated.
Depending on the frequencies involved you may need to use an interrupt to increment the counter.
Hold on a minute !
I have just noticed that you are using pin 1 as your sensor input and that is used by the Serial interface. Try using another digital pin (not pin 0) for the input. While you are at it, change the data type of state and lstate to byte, freq to unsigned int and the input pin to const byte.