Memory leak from waveform plotting at high frequency
Show older comments
Hi
I'm having problems with 16gb of RAM on my computer being taken up calculating the below.
I know its because of t and f, How do I code the sampling to be right at high frequencies such as 200-250 MHz so it plots at appropriate time intervals that is not taxing?
t = 0 : 0.01 : 1;
for f = 200000000 : 500000 : 250000000 % From 200 MHz to 245 MHz with 500 kHz increment
y(f,:) = sin (2 * pi .* f .* t);
end
figure(1)
plot(t,y)
figure(2)
%Also plot the sum of each waveform at each time interval t
plot(t, sum(y), ':r', 'LineWidth',2.5)
Accepted Answer
More Answers (2)
Walter Roberson
on 5 Nov 2017
t = 0 : 0.01 : 1;
num_t = length(t);
fvals = 200000000 : 500000 : 250000000;
num_f = length(fvals);
y = zeros(num_f, num_t);
for f_idx = 1 : num_f % From 200 MHz to 245 MHz with 500 kHz increment
f = fvals(f_idx);
y(f_idx,:) = sin (2 * pi .* f .* t);
end
figure(1)
plot(t, y)
figure(2)
%Also plot the sum of each waveform at each time interval t
plot(t, sum(y), ':r', 'LineWidth',2.5)
You just happen to have the same number of f values as you have time steps. MATLAB creates one line per column, and your different columns correspond to increasing frequency. You need to think about whether you instead want to plot(t, y.') to have it show increasing time for each line.
Nathan Kennedy
on 5 Nov 2017
Edited: Nathan Kennedy
on 5 Nov 2017
0 votes
3 Comments
Star Strider
on 5 Nov 2017
The aliasing problem can largely be eliminated using an appropriate magnitude for ‘t’.
This produces good results when substituted for the original vector:
t = linspace(0, 2E-8, 250);
This results from the wavelength calculation:
lambda = 1/250E+6;
producing a wavelength at the highest frequency of 4E-9 (seconds).
Nathan Kennedy
on 5 Nov 2017
Star Strider
on 5 Nov 2017
The frequency vector in my Fourier transform code is based on the time vector. If the time vector is not appropriate (my new time vector is appropriate) the frequency vector will be similarly affected.
I have to rely upon the information provided in your Question, and unless you state that there’s a problem with it, I assume it’s correct.
Categories
Find more on Pulsed Waveforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!