Generating a continuous signal and sampling it at a given rate is demonstrated here. In simulations, we may require to generate a continuous time signal and convert it to discrete domain by appropriate sampling.

For baseband signal, the sampling is straight forward. By Nyquist Shannon sampling theorem, for faithful reproduction of a continuous signal in discrete domain, one has to sample the signal at a rate \(f_s\) higher than at-least twice the maximum frequency \(f_m\) contained in the signal (actually, it is twice the one-sided bandwidth occupied by a real signal. For a baseband signal bandwidth (\(0\) to \(f_m\)) and maximum frequency \(f_m\) in a given band are equivalent).

Matlab or any other simulation softwares process everything in digital i.e, discrete in time. Therefore, we cannot generate a real continuous-time signal on it, rather we can generate a “continuous-like” signal by using a very very high sampling rate. When plotted, such signals look like a continuous signal.

Let’s generate a simple continuous-like sinusoidal signal with frequency \(f_m\) = 10kHz. In order to make it appear as a continuous signal when plotting, a sampling rate of \(f_s\)=500kHz is used.

1 2 3 4 5 6 7 8 9 10 |
fs=500e3; %Very high sampling rate 500 kHz f=10e3; %Frequency of sinusoid nCyl=5; %generate five cycles of sinusoid t=0:1/fs:nCyl*1/f; %time index x=cos(2*pi*f*t); plot(t,x) title('Continuous sinusoidal signal'); xlabel('Time(s)'); ylabel('Amplitude'); |

Pretending the above generated signal as a sinusoidal signal, we would like to convert the signal to discrete-time equivalent by sampling. By Nyquist Shannon Theorem, the signal has to be sampled at * at-least* \(f_s=2*f_m=20 kHz\). Let’s sample the signal at \(f_{s1}=30kHz\) and then at \(f_{s1}=50kHz\) for illustration.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
fs1=30e3; %30kHz sampling rate t1=0:1/fs1:nCyl*1/f; %time index x1=cos(2*pi*f*t1); fs2=50e3; %50kHz sampling rate t2=0:1/fs2:nCyl*1/f; %time index x2=cos(2*pi*f*t2); subplot(2,1,1); plot(t,x); hold on; stem(t1,x1); subplot(2,1,2); plot(t,x); hold on; stem(t2,x2); |