# Matlab HIgh frequency sine wave generation

I need to generated a high frequency sinusoidal signal for modulation in MATLAB. But it turns out to be something weird. This is the simple code snippet I used...

t = 0:0.001:100;
A = 1;
s = A*sin(2*pi*1e9.*t);  %1 GHz signal
plot(t, s);
title('Modulating Signal');
xlabel('Time');
ylabel('Amplitude');


Instead of the sine wave I am getting something weird like this..

The function you need to evaluate is:

A*sin(2*pi*FREQUENCY*(1:NUM_SAMPLES)/SAMPLE_RATE)


Use a reasonable sample rate (at least twice the frequency) and a reasonable interval (remember that at a sample rate of 2Ghz, 1 second of signal will fill up the memory of your computer) ; and it'll work! From your code it seems that you are trying to generating 100s of signal at a sample rate of 1kHz, which doesn't make sense.

At the moment, in your code, the argument of the sin function is an integer multiple of $2\pi$ so in theory your code should be plotting a flat line of 0s. You are seeing something a bit different due to the finite resolution of floating point numbers.

The problem is the definition of your vector $\tt{t}$. You seriously subsample your signal because its period is $T=10^{-9}$ and you the interval of your sample points is $10^{-3}$. Try the following:

t = linspace(0,1e-7,10000);
A = 1;
s = A*sin(2*pi*1e9.*t);  %1 GHz signal
plot(t, s);


The problem is in the use of floating point.

When the sine-function input gets too large, it's accuracy decreases and hence the accuracy of the sine-function decreases. You should limit the input of the sine-function between 0 and 2pi (basically a saw-tooth). This will solve your problem.