Fuel problems or Knock sensor?

When I am at a stop just sitting there the RPM drops and goes up like it is going to die and then when I push on the gas pedal it stalls a little then will go but until I get over about 45mph it will stall a little. It is fine when I am on the freeway and worse at a stop. The check engine light is on and I took it in and the code said Knock sensor. But would a knock sensor do that? To me it seems like not enough fuel is getting to where it needs to be. But I dont know much about cars.F

I think you have a fuel related issue or a plugged fuel filter. The CEL system is far from perfect so the closest thing the computer can relate to is the knock sensor. The knock sensor may be trying to adjust for bad fuel or a lack of fuel. You need to get this checked out by a good mechanic. I would avoid the dealership unless this is warranty work (you don’t mention the year model of the Altima).

It is a 1998 so if I were to replace the fuel filter and maybe get the fuel system cleaned out or something could that fix the problem or do I need to buy a new injector and strainer?

You are probably due for a fuel filter change so it couldn’t hurt. That’s all that I would do before seeing a good mechanic to find the real problem if the fuel filter does not cure the stalling.

Thank you =)

Yes, a fault in the knock sensor circuits could cause this. The knock sensor sends a signal to retard the ignition timing by a varying amount based on any pre-ignition problems and when the timing is retarded an engine may have a tendency to stumble and stall.

One can often tap the engine the vicinity of the knock sensor(s) with a hammer and cause it to stumble a bit.