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

14 ビュー (過去 30 日間)
Hydro
Hydro 2014 年 10 月 18 日
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 件のコメント
Hydro
Hydro 2014 年 10 月 18 日
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 件のコメント
Mohammad Abouali
Mohammad Abouali 2014 年 10 月 18 日
@ 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.
Yuvarajendra A Reddy
Yuvarajendra A Reddy 2020 年 2 月 25 日
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)');

カテゴリ

Help Center および File ExchangeVector Fields についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by