How to centre a graph about 0 on the y axis?

34 views (last 30 days)
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)')

Accepted Answer

Walter Roberson
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
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 .
Lara Severne
Lara Severne on 26 Mar 2018
Yes due to having 4 different sensors per each experiment, and the sample rate for each is 20000 per second. Yeah that would be ideal, but this value may also have to alter depending on whether 100 points per second smoothes the curves enough for a successful FFT. I would like the total results for each of the averaged down columns to be centred around 0 for the FFT. So the total length of cropped matrix is 2.3 seconds roughly so across the sample of 230 averaged results, I need this centred around 0 on y axis. It is exactly 20000 per second, and a total of 66000 per channel (I am trying to remove first second of data due to it not being interesting) hence the initial bit of code)
A = LongTestArray(20001:66000, 1:4)
If any of this is unclear then just let me know, thanks again

Sign in to comment.

More Answers (0)

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!