how to plot the data and superimpose the mean of the data?

I am required to plot 20 second data of my veleocity. then i need to superimpose the mean of the velocity. Can somebody look into my codes. I dont know how to convert the velocity in Hz into second. The velocity is measure with a device that collect data 100 times in a second.
here is my code
U20=U(1:2000,:); % Selection of 20 seconds of data
Usec=U20/100; % 1 second =100 Hz (I think i am making mistake here)
plot(Usec); % ploting of instantinous velocity
Umean=mean(Usec); % Mean of the sample
hold on
plot(Umean,'-','LineWidth',1); % Superimposing the mean velocity
xlabel('sample data length');
ylabel('Stream wise velocity');
The graph should look like the attached picture where U is the mean and U' is the instantaneous velocity.
many thanks

댓글 수: 3

Velocity is neither measured in Hz nor in seconds. It is measured in m/s or similar unit (i.e. length/time). Hz is the unit of frequency, second the unit of time. If what you've measured is in Hz or s, you won't be able to convert it to a velocity without a distance measurement.
True, my U(velocity) is in m/sec however measured with a device that has sampling frequency of 100 per second that's why i need to convert my data into second and am therefore diving by 100. besides, lets say my location of interest is 3.0 m. I am still struggling to get the plot.
Guillaume
Guillaume 2014년 10월 18일
편집: Guillaume 2014년 10월 18일
The sampling frequency has no bearing on the measured value, it only affects your x-axis.
What is the unit of the measured value?

댓글을 달려면 로그인하십시오.

 채택된 답변

Mohammad Abouali
Mohammad Abouali 2014년 10월 18일
편집: Mohammad Abouali 2014년 10월 18일
% Generating some sample data
t=linspace(0,2*pi,100);
U=sin(t);
% Ploting velocity
plot(t, U);
axis tight
hold on
% Now plotting the mean value.
Umean = mean(U);
line(xlim, [Umean,Umean],'Color','r');

댓글 수: 6

Attached is my data. the data is collected through a device that has a frequency of 100 Hz (Every 100 sample represent 1 second) hence all of the my data is of 20 second. What i want to do is to convert the data into second format (the matrix should be of 20*140 (20 rows and 140 columns) and plot. Then i need to find the mean and superimpose the mean in the graph.
I am struggling with the conversion part (converting sampler data into seconds, in other words, converting each 100 sample into second.
Would really appreciate if you could give it a try.
While you can certainly downsample your data to 1 sample per second using all sorts of filters, why do you want to do this?
Both Mohammad's and my answer show you how to plot your data on a scale of 0-20 with the mean and without any downsampling.
Hi Guillaume,
I tried to run your code however, i am getting error (Vector must of the same length). I know this problem is very basic and should be solve in a matters of few mints however, i am struggling. can you please tell me how to do the conversion i.e from a matrix of (2000*140 to 20*140) by summing up each 100 rows step by step.
I included two methods. (1) jumping window, which averages each 100 numbers together, (2) sliding window average (or moving window average).
Based on your description what you are looking is the first method though. But I included the second method too since it gives nicer mean graph.
U20_mean is array of 20x140 which averages each 100 row. Something along this should work:
load U2'0 second data';
%%Method 1: Jumping window
% Cell Array of size 20x1
U20_mean_cell=cellfun(@mean,mat2cell(U20,100*ones(20,1),140),'UniformOutput',false);
% Regular Array of size 20x140 which contains the average of each 100
% samples (or row)
U20_mean=cell2mat(U20_mean_cell);
% Sample plot
figure
tHighRes=linspace(0,20,2000);
plot(tHighRes,U20(:,1))
axis tight
hold on
tLowRes=linspace(0.5,19.5,20);
plot(tLowRes,U20_mean(:,1),'r','LineWidth',2);
%%Method 2: sliding window
s=ones(100,1)/100;
U20_mean_cell2=cellfun(@(x) conv(x,s,'valid') , ...
mat2cell(U20,2000,ones(140,1)), ...
'UniformOutput',false);
U20_mean_movingWindow=cell2mat(U20_mean_cell2);
%Sample plot
figure
tHighRes=linspace(0,20,2000);
plot(tHighRes,U20(:,1))
axis tight
hold on
plot(tHighRes(50:1950),U20_mean_movingWindow(:,1),'r','LineWidth',2);
Above figure is method 1
And this is method 2
@ Guillaume In fluid mechanic quite often we decompose the velocity into its mean part and fluctuation part U=Ubar+U'. pretty much then the equation is solved for Ubar and then the turbulence equation is modeling the effect of U'. This is generally known as Reynolds Averaged Navier-Stokes' (RANS) equation.
I don't know why he wants to average these numbers, but this approach is used in many field. I applied the same techniques once on seismograph (yes, the techniques that are used in solving fluid motion applied on seisomograph) and I was able to detect some features much easier.
Interesting answer by @Mohammad Abouali. There's a much simpler approach to this.
sample_data=rand(1,100); % Your signal data array
mean_data = smoothdata(sample_data,'movmean'); % Calculating the average or mean, moving over each window
% Plotting graphs
figure
plot(sample_data) % Original data
hold on
plot(mean_data,'linewidth',2) % Average of the data
legend('Original signal','Mean of the signal')

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Guillaume
Guillaume 2014년 10월 18일
편집: Guillaume 2014년 10월 18일
Assuming you have a velocity U measured for 20 seconds (see comment to your question),
t = linspace(0, 20, numel(U)); %generate a time vector for 20 seconds with as many elements as U
plot(t, U);
hold on
Umean = mean(U);
plot(t, Umean);
xlabel('times (s)');
ylabel('velocity (m/s)');

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

질문:

2014년 10월 18일

댓글:

2020년 2월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by