Digital Signal Processing Reference
In-Depth Information
2.8
Plotting Sinusoids a Little at a Time
The next program came about because of a need to see when two sinusoids repeat,
also known as the period. Take two sinusoids with frequencies of 25 Hz and 33 Hz,
for example. Both repeat themselves over and over, but what if they were added
together? The resulting sinusoid would repeat itself, but when? To nd out, we
need the greatest common divisor. Fortunately, MATLAB provides such a function:
>> gcd(25, 33)
ans =
1
This means that the signal cos(225t) + cos(233t) repeats every second, or
1=gcd(25; 33). Figure 2.3 demonstrates this. The signal is plotted for time 0 to 1
second in the top half, and from 1 to 2 seconds in the bottom half. While the signal
has sections that look similar, careful examination reveals that the signal does not
actually repeat until 1 second has elapsed.
What if we want to see a close-up view of the two sinusoids? The following code
does just that. It plots two sinusoids, and shows one section at a time. The pause
function gives the user a chance to see the graph before a new graph is plotted.
With it, we can see that the two sinusoids start at the same value, but do not match
up at this value until the very end. Figure 2.4 shows the output of this program for
the end of the sinusoids.
%
% show_sins.m
% Show 2 sinusoids, 100 samples at a time.
%
% Feel free to change any of the default values below
show_num = 100;
% How many samples to show at a time
count = 100;
% How many samples to advance at a time
t = 0:0.001:1;
% Our simulated time variable
freq1 = 25;
% frequency1
freq2 = 33;
% frequency2
Search WWH ::




Custom Search