I would like to simulate the Johnson noise in a computer. I know its power is P=K*T*B where B is bandwidth and T is the temperature. I know it is random so I can use randn however I do not know how to generate the noise itself because it should be different from AWGN. I was thinking to use low pass filter to make the bandlimited signal. However I do not know if this is correct approach. Can anyone please suggest me techniques or method to generate the Johnson noise ?
Johnson noise is just one of the many sources of AWGN, and it is no different than AWGN. It has a flat spectral density just like AWGN (technically at extremely high frequencies, quantum effects start to take over and the PSD starts decreasing, but that's not a real concern for an engineer). The bandlimited part comes from your system itself. The act of sampling inherently bandlimits your noise to the Nyquist frequency. So you simply need to generate it by scaling randn by the appropriate amplitude to get your desired power which you have the calculation for in your post. No filtering necessary.
This is what I think and exactly opposite what this website says :
So according to what you say Johnson noise is not bandlimited, so I am wondering where the term B come from because it should refer to the bandwidth of the system.
The comment you linked is correct and is in agreement with what I said. The model we have for AWGN (whether Johnson or otherwise) is that it has a flat spectral density across all frequencies. Thus it is of infinite bandwidth and thus infinite power ('variance' if we are using prob/stats terminology) since it has power across all frequencies. Obviously, this does not strictly exist in reality (it decays eventually as my original comment said), but it is a good enough model since we don't deal with extremely high frequencies.
We cannot sample infinite bandwidth signals. We can only sample a bandwidth up to the Nyquist Frequency = Fs/2 (if you are unfamiliar with this, look it up). This means that we are not taking in any frequencies higher than Fs/2 into our system. Thus all the noise power over Fs/2 is ignored, and we concern ourselves with the power up to Fs/2. So the Johnson noise in our system must depend on B = Fs/2, which is the B that you have in that formula.
We cannot sample infinite bandwidth signals. We can only sample a bandwidth up to the Nyquist Frequency = Fs/2
This is correct only if the input signal is band-limited prior to the sampling process. If a signal that has not been band-limited is sampled, all the noise power at higher frequencies will alias down into base-band and add to the base-band noise power.
Just something to keep in mind...
True, I had made an implicit assumption that there was an anti-aliasing filter as part of the sampling process. But it's definitely good to mention that explicitly.
Thanks. However in the attached link the variance of noise is calculate to be Fs*N0. However using what I have is like (Fs/2)*K*T. I know N0 for Johnson noise is 4*K*T*R. Therefore still these two equations do not match as one of them requires the resistor value and their scaling values are different. Therefore which one should be used to calibrate the noise?
In my experience we use the (Fs/2)*K*T (so N0 = K*T). So as a rule of thumb, the thermal noise power per Hz is -174 dBm. From a cursory reading of the wikipedia article on Johnson-Nyquist noise, it seems that B*K*T falls out of 4*R*K*B*T after impedance matching, but perhaps someone more qualified can clear up the exact relationship.
Generally AWGN is the appropriate model for thermal noise, and with the usual numeric ways of generating AWGN (which you should be able to find with some simple searches), B is just whatever the supported bandwidth of the sampling is. For example, for real-valued noise, B is Fs/2, for complex-valued noise B is Fs, where Fs is the sampling frequency.
If you need something other than that, then how to do it will likely be dictated or influenced by whatever your application is that requires something other than AWGN.