How to centre a graph about 0 on the y axis?
34 views (last 30 days)
Show older comments
Lara Severne
on 25 Mar 2018
Commented: Lara Severne
on 26 Mar 2018
Trying to perform an FFT and need points centered around 0 (i.e. all their values would average out to be 0) about the y axis. Originally I was taking mean of all the points in a column and minusing these from their respective columns. I am now however trying to specifically use the 20001-66000 values in the matrix and the average is not changing for some reason, and the graph of the shortened matrix is no longer centred due to this. Any help greatly appreciated. The full code is as below.
A = LongTestArray(20001:66000, 1:4);
M = mean(A)
A(:,3) = A(:,3) - M(:,3);
A(:,4) = A(:,4) - M(:,4);
%%Attempting to average down the 46000 data points for signal processing
B = A;
Ar = reshape(B, [], 4, 920); % Reshape
%%to draw the graph, changing it from number of samples to a time domain
X=Ar(:,4);
f = 21.7 ;
samples = 0:size(X, 1)-1 ;
t = samples/f ;
%plot column 1
plot(t, X )
grid on ;
hold on ;
title('Low Frequency Accelerometer Test 1')
xlabel('Time (s)') % x-axis label
ylabel('Voltage (V)')
0 Comments
Accepted Answer
Walter Roberson
on 25 Mar 2018
set(gca, 'YAxisLocation', 'origin')
for placing the graphics axis at y = 0
YL = get(gca, 'YLimit');
maxlim = max(abs(YL));
set(gca, 'YLimit', [-maxlim maxlim]);
to force the plot to have the same extent to the top and bottom.
9 Comments
Walter Roberson
on 26 Mar 2018
Edited: Walter Roberson
on 26 Mar 2018
To confirm: you have about 20000 x 4 points per second? And you want to average batches of 200 x 4 consecutive points, so that you get down to 100 x 4 averaged points per second?
And once the points are averaged that way, you want to center what results for each column, over all of the seconds, so that even though each batch of 100 x 4 points per second might not have a center of 0 per column, that the overall average for each column is 0 ?
To do this we will need a hard variable about the number of points per second (is it exactly 20000 ?), and we will need rules about what should happen if the size of the data is not an exact multiple of points_per_second/100 .
More Answers (0)
See Also
Categories
Find more on Discrete Data Plots 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!