how the 4G LTE Or 5G NR OFDM measures and corrects the sampling frequency offset? if there is an algorithm using matlab please help
There's multiple ways you can approach this, and as what's inside frontends is a business secret, I'm not sure anyone can say for certain what 4G devices do in general, but it's safe to assume they do a combination of a couple measures.
Among these to cancel a Sampling Clock Offset (SCO) will be:
Ignoring the problem
Your frames are of limited length. Especially if you get channel state information from your communication partner (you do in 4G / 5G!), you can cancel out the Doppler estimate, are left with an estimate how wrong your internal oscillator is, from which you derive both your carrier frequency and your sampling clock. Applying the same correction to both will reduce the problem in short frames that the loss due to Inter-Carrier-Interference (ICI) is negligible.
SCO estimate from sinc fitting in frequency domain
The OFDM spectrum is sinc-shaped. Sampling it critically, and with the correct sample clock, will sample the spectrum at exactly the sinc maxima (with zero ISI).
Since there's enough known data (preambles/sync symbols/pilot tones) and recovered data to work with in the receiver from the first OFDM symbols, where the SCO had little to no effect, you can re-calculate the spectrum as it should have been at the transmitter – and then you can estimate via solving e.g. a least squares problem, what the most likely SCO was that you had – simply by asking yourself "if I had an SCO, where on the spectrum would I look, and what would be the reception I'd be getting, assuming no noise", and then go for the SCO estimate that's closest to what you actually received.
Oversampling will definitely help there - with little approximation error, you only need to know a few of the "neighboring" carriers' values to calculate what the middle between to carriers should be; do that over a couple of middles, and see whether your frequencies got compressed or expanded around the DC carrier.
Cyclic-Prefix correlation properties
After having corrected fine frequency offset through standard OFDM means, you can correlate your received cyclic prefix with the end of the respective symbol, after upsampling/interpolation. That's a way to get a classic timing error estimate.
Do that with consecutive OFDM symbols, and fit a linear function to your estimates. A SCO results in a linear timing error over time.
You might want to correct as much of the channel as you can to get a good estimate – but you can do that based on the channel information the rest of your system gives you.