Memory leak from waveform plotting at high frequency
显示 更早的评论
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)
采纳的回答
更多回答(2 个)
Walter Roberson
2017-11-5
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
2017-11-5
编辑:Nathan Kennedy
2017-11-5
0 个投票
3 个评论
Star Strider
2017-11-5
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
2017-11-5
Star Strider
2017-11-5
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Pulsed Waveforms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!