It sounds like your Audi S4 failed the smog check because one or more of its emission monitors were incomplete. More than likely they were erased while replacing the battery. In order to to make the monitor(s) ready, you'll need to drive your Audi through a drive cycle.
The Audi S4 OBD II Drive Cycle below will be sufficient in setting your vehicle's emission monitors. This OBDII drive cycle begins with a cold start (coolant temperature below 122 degrees F). We recommend achieving this by letting your S4 cool down overnight, and beginning the drive cycle process on a morning. Take extra caution while performing drive cycles on public roadways. This particular drive cycle is complicated and requires many speed ups and slow downs. Please note, under normal circumstances, your Audi should complete the drive cycle on its own without needing to follow the driving pattern below. Driving for at least 300 miles in both highway and city traffic conditions over the course of a week should get the required monitors to set.
Also, a certified Audi repair shop can use the VAG-COM diagnostics system to manually run through your Audi S4's emission monitor parameters. Should you choose to try completing the Audi Drive Cycle, follow the steps below. Prior to beginning the drive cycle (if you have a scan tool) we recommend checking the status of the Readiness Monitors. Also ensure there are no current or pending digital trouble codes. If any exists, correct them and clear the codes first. Then begin the drive cycle. Make sure the check engine light is not on.
How To Perform an Audi S4 OBD II Emission Monitor Drive Cycle
When starting a drive cycle, Audi requires the vehicle be driven approximately 7.5 miles within a period of 23 minutes from a cold start. Always operate the throttle smoothly and never turn off the ignition during the drive cycle, and be very careful to obey all traffic laws and drive in a very safe manner. Following drive cycle pattern will require much speed manipulation. Avoid extreme driving conditioning such as very high/low temperatures, rough roads or high altitudes. These conditions may prevent some monitors from becoming "Ready".
Step 1 Engine Cold Start engine, idle 20 seconds. Accelerate gradually and drive at 20-25 mph for 1 minute, varying speed.
Step 2 Accelerate gradually to 32 mph within 35 seconds. Decelerate to 0 mph in 10 seconds. Idle for 40 seconds.
Step 3 Accelerate at part throttle to 25 mph in 10 seconds. Cruise at 17-25 mph for 15 seconds. Accelerate gradually to 57 mph in 45 seconds. Cruise at 50-56 mph for 1 minute. Decelerate gradually to 0 mph in 40 seconds. Idle for 15 seconds.
Step 4 Accelerate at part throttle to 36 mph and maintain for 10 seconds. Decelerate to 0 mph in 15 seconds. Idle for 5 seconds.
Step 5 Accelerate to 30 mph and back to 0 mph within 30 seconds. Idle for 20 seconds.
Step 6 Accelerate to 36 mph in 20 seconds. Drive at 35 mph for 20 seconds. Decelerate to 0 mph in 15 seconds. Idle 5 seconds.
Step 7 Accelerate gradually to 26 mph and decelerate to 0 within 40 seconds. Idle 15 seconds.
Step 8 Accelerate to 27 mph in 40 seconds. Decelerate to 0 mph in 10 seconds. Idle 25 seconds.
Step 9 Accelerate to 26 mph in 15 seconds, maintain speed for 10 seconds, decelerate to 0 mph in 10 seconds. Idle 15 seconds.
Step 10 Accelerate to 23 mph in 20 seconds, decelerate to 0.5 mph in 10 seconds (no complete stop). Accelerate to 28 mph and back to 0 mph (momentary stop 1 second) within 35 seconds.
Step 11 Accelerate gradually to 34 mph in 45 seconds. Vary speed between 34 and 19 mph for 2 minutes. Decelerate from 25 to 0 mph in 25 seconds. Idle for 5 seconds.
Step 12 Accelerate to 29 mph in 15 seconds, decelerate gradually to 0 mph in 45 seconds. Idle for 30 seconds.
Step 13 Accelerate gradually to 28 mph and back to 0 mph (momentary stop 1 second) within 50 seconds. Accelerate gradually to 27 mph and back to 0 mph within 55 seconds. Idle for 15 seconds.
Step 14 Accelerate to 24 mph and back to 0 mph within 18 seconds. Idle for 10 seconds. Accelerate gradually to 22 mph and back to 0 mph within 50 seconds. Idle for 8 seconds.
Step 15 Accelerate gradually to 30 mph within 50 seconds. Decelerate to 0 mph in 10 seconds. Idle for 25 seconds.Step 16 Accelerate to 23 mph and back to 0 mph within 30 seconds. Idle for 10 seconds.
Step 17 Repeat steps 1 - 16 once again. Recheck the status of the "Readiness Monitors".
END DRIVE CYCLE
NOTE: Remember, clearing DTC's or interrupting power to the ECM after the readiness monitors have been reset to "Ready" will require that the Drive Cycle be repeated.
Completing your Audi's drive cycle successfully one time should reset most drive cycle monitors to a "Complete" or "Ready" status. There are however "two trip" monitors, which require that the drive cycle be successfully completed two times in order to become "Ready".