フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Plotted waveform frequency is way too low

3 ビュー (過去 30 日間)
want2know
want2know 2015 年 8 月 17 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I am using Quartus 12.1 sp1, vhdl and Altera Nios II programmed in C code for DE0-Nano Development. Basically, what I have is, Nios II system sends the data to serial port, Matlab access the serial port to real time plot the graph.
In my system, the rate the graph is plotted is much slower (11Hz) than the rate the processor speed (50MHZ).
Please refer to this image:
My question is, what should I change in order to get the waveform plotted with a period of 0.02 seconds instead of 0.16 minutes as I got now? What determine the period of the plotted waveform?
I posted the Matlab code here: EDIT:
max_packets = 20000; %maximum number of packets to keep in memory (all are saved to log file)
update_plot = 1; %how often we should update the plot
plot_length = 12; %maximum length of plot
figure('Position', [10, 50, 900, 900]); % new figure
ax1 = subplot(3,1,1); % top subplot
ax2 = subplot(3,1,2); % bottom subplot
ax3 = subplot(3,1,3);
drawnow;
s = serial(port);
cleanupObj = onCleanup(@()cleanupFunc(s)); %clean-up function
set(s,'BaudRate',115200,'timeout',2); %timeout is in seconds
fopen(s);
vref= NaN(12,max_packets);
j = 0;
tic; %start timer
while 1; %do forever...
if j < max_packets
j = j+1;
else
fprintf('\n Buffer full, reset to 0\n');
j = 1; %reset counter to stop memory overflow
end
%get data line by line
line = fscanf(s);
[c,vo] = disect_line(line);
if c == 1 %start recording from set 1
vref(1,j) = vo;
for i = 2:12 %get set 2 to 12
line = fscanf(s);
[c,vo] = disect_line(line);
if c == i
vref(i,j) = vo;
else
fprintf('\nError\n');
end
end
dlmwrite(logfile,[toc vref(:,j).' ],'delimiter',',','-append'); %save data from all 12 sets to csv file
update plot1 every update_plot packets, and after we have at least 2 data points (otherwise we get errors)
if mod(j, update_plot)==0 && j>1
if j < plot_length
start = 1;
else
start = j-plot_length+1;
end
plot(ax1, start:j, vref(1,start:j).');
for k = 1:1
text(j, vref(k, j), num2str(k), 'Parent', ax1);
end
xlim(ax1, [start j]);
ylabel(ax1, 'Vref');
title(ax1, ['Time elapsed = ' num2str(toc) ' s']);
end
end
function [c, vo] = disect_line(line)
c = str2double(line(1:2)); %set number
vo = str2double(line(4:7));
end
function cleanupFunc(s)
fprintf('\nClosed serial port.\n')
fclose(s);
delete(s);
clear s;
end

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 8 月 17 日
Your code does not define "start" or "j" and never changes them.
Remember too that start:j would increment by 1 and that if you want a different increment you need start:increment:j
  6 件のコメント
want2know
want2know 2015 年 8 月 18 日
Thank you for your reply. Forgive me, actually I don't understand what is the reason behind this? Is this the same as the common practice we used to generate a waveform :
For example, generating data with a 1000 Hz sample frequency, appropriate time vector is
t = (0:0.001:1)'; Do you mind to give me keywords or link of resources? much appreciated
Walter Roberson
Walter Roberson 2015 年 8 月 18 日
Let Fs = 1000 then 1/Fs = 0.001 and that is what you used as your increment. So in 0:001:1, your first sample is at time 0, your second sample is at 1/Fs = 0.001, your third is at 2/Fs = 0.002, your fourth is at 3/Fs = 0.003

この質問は閉じられています。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by