0
$\begingroup$

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..Not really the sine wave or the full blue wave

$\endgroup$

3 Answers 3

1
$\begingroup$

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.

$\endgroup$
1
$\begingroup$

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);
$\endgroup$
0
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.