How I can Plot Data Samples as Data values in Y-axis and Sample counter converted to micro second values in X-axis? Then get average and standard variation values?

5 visualizzazioni (ultimi 30 giorni)
I imported the excel file which have Two coloumns and 100,001 rows.
1- I use the plot icon in MATLAB to plot all of the rows in the first column. for example below:
2- Then, I get the below graph:
2- How I can do this plot again, but insetad of the Sample counter values in x-axis, I want to make it (time).
For example, convert the first sample = 1 TO BE first sample = 1e-06 (micro seconds) and to all of the other samples till I reach 100,001 e-06. I can explain it again below:
  1. The distance between samples is 1us (microsecond).
  2. We take the samples, create time axis. And, We’ve got 100,001 point.
  3. So we got time samples, or sample counter (SC), and we translate this into time, Which will be 100,001 * 1 us (micro seconds) which will be 100,000 us (microseconds)
3- After I finish from above steps, I will have my samples in the y-axis and I will have the time in micoseconds in x-axis.
4- Then I want to plot The pulse,which is in 50 us, that’s the ON time (included in the plot). And, the OFF time is 950 us (not in plot). However:
  1. The start of analysis of 1st window, is 15us + 5 um. That’s our start.
  2. The end of first-time window is 15us + 5us + 40us. Thats our end. Then we can plot it.
5- So after we finish from the first pulse above which is considers as number 0. Then we have to do it to the rest for pulses which will be for example from 1 to 99. And we use a counter, for example,"m" to be used for 1 to 99 in below equation:
  1. 15us + 5us + 40us + m*1000us.
  2. Therefore I need to repeat for example, using "for" loop.
  3. and then we just hold on for the 40us AND hold off for the rest in each loop. Then plot all of those windows and then we should have a line.
6- Also when we do the “for” loop, for each time window , I want to calculate average as well AND standard deviation. I also want to plot thses and see if there a trend

Risposte (1)

Cris LaPierre
Cris LaPierre il 27 Set 2022
I highly recommend going through MATLAB Onramp, but the quick answers are
2. Select your x values, then use Ctrl+click to select your y values (should have 2 columns selected. Not go to the plots tab and select the plot you want. See this video. this approach will not work if you plan to loop your code, however. You must write the actual code.
4. The easiest way to plot is to create a vector of your pulse values, and a corresponding vector of time values. Then plot them using the appropriate plotting function. To add 2 lines to the same plot, use hold on followed by hold off when done.
6. Taking the average and standard devaition are just a matter of using the mean and std functions with the appropriate data. MATLAB Onramp will introduce you to using MATLAB functions as well.
  15 Commenti
Ali
Ali il 30 Set 2022
This is the plot result from my code:
Now, I will zoom in the plot and you can see below
From above, you can notice I have pulses which repeat ever 1000 micro second. Those pulses are my target.
For example: Looking at the zoom in for the first data pulse below:
You can look from above zoom in. The first pusle start from 7 micro seconds (us) which is to be more precise maybe from almost 5 us and it end at 57 us which is almost 60 us.
Looking again for the next pulse in graph below:
In above graph, we can notice a pattern for the second pulse, Its start from 15us and it end at 60us.
This means in every 1000us, we have 950us noise and only 40us is the data captured which is pulse.
Therefore from this 100,000 us. I have only 100 pulse which is repeated every 1000us.
So, each pulse have a time window which start at 15 u + 5us AND it ends at 15us+5+40us which is 60us.
I want to make a "for" loop which will let me extract the pulse which occure from 0 till 100,000 us.
Then we will get 100 pulses. In each pulse the magnitude value is changin in the 40us.
I need to take this avreage value in each pulse and then plot those values to visulaize it if its increasing or decreasing.
For example you can look at the excel sheet screen shoot below:
I was doing this manually for the frist, second and third pulse for all my data, which is time consuming and not accurate. From above excel sheet, you can see I chose the values of magnitude in the first puls and wrote its avreage values then did the same for the second and third pulse. After that I took the avreage of the three pulses to have a final value for the first data then i did this again for the next data..etc
I need to learn this so that i can automate it in MATLAB. I was using MATLAB and EXCEL. Now, i just want to use MATLAB which I concluded it will make my result more visual and more faster in calculation.
Cris LaPierre
Cris LaPierre il 30 Set 2022
Modificato: Cris LaPierre il 30 Set 2022
Here, I think it is easier to work in indices rather than time. Again, you have the equation for the indices you want already, so now just incorporate it into your code. I'm not sure what exactly you want your final plot to be, so I took a guess by plotting the mean of mag and phase over each 40 pulse.
% Start is the same as before
file = "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1140105/MATLAB%20DATA%20-%20Exp%207.xlsx";
M = readtable(file)
M = 100000×4 table
I_inc I_ref Q_inc Q_ref ___________ ___________ ___________ ___________ 0.0007087 0.00077618 0.00047246 0.00025873 -0.00047246 -0.00038809 -0.00094493 -0.00012936 0 0.00038809 0.00047246 0.00012936 0.00035435 0.00025873 0.00023623 -0.00012936 -0.0012993 -0.0011643 -0.0011812 0.00012936 0.003071 0.0031047 0.0035435 0 -0.031655 -0.029107 -0.036616 0 -0.061302 -0.051874 -0.060475 0.0046571 -0.058822 -0.045148 -0.047364 0.0086673 -0.064964 -0.047735 -0.048309 0.011255 -0.065554 -0.045536 -0.042758 0.013712 -0.068035 -0.045536 -0.040514 0.015653 -0.070161 -0.044501 -0.037443 0.017852 -0.071224 -0.043466 -0.033663 0.019922 -0.073114 -0.042819 -0.031183 0.021862 -0.074059 -0.041267 -0.026812 0.024061
A = M.I_inc;
B = M.Q_inc;
E2 = complex(A,B);
C = M.I_ref;
D = M.Q_ref;
F2 = complex(C,D);
% getting IMABS
Inc_mag = abs(E2);
Ref_mag = abs(F2);
Inc_phase_deg = angle(E2) * 180/pi;
Ref_phase_deg = angle(F2) * 180/pi;
%==
s11 = F2./E2;
s11_mag = abs(s11);
s11_phase_deg = angle(s11) * 180/pi;
%==
t = (1:length(s11_mag))*1e-6;
plot(t,s11_mag)
ylabel('Magnitude')
xlabel('Time (s)')
% define pulse characteristics
start = 20;
width = 40;
gap = 1000;
% capture results in a new table, pStats
pStats = table('Size',[100 3],'VariableTypes',{'double','double','double'},'VariableNames',["Time","Avg_mag","Avg_phase"]);
ind = start:gap:length(s11_mag);
for p = 1:length(ind)
magdata = s11_mag(ind(p):(ind(p)+width));
phasedata = s11_phase_deg(ind(p):(ind(p)+width));
pStats.Time(p) = t(ind(p));
pStats.Avg_mag(p) = mean(magdata);
pStats.Avg_phase(p) = mean(phasedata);
end
% view results
pStats
pStats = 100×3 table
Time Avg_mag Avg_phase _______ _______ _________ 2e-05 0.6069 -49.839 0.00102 0.6084 -49.597 0.00202 0.60818 -50.096 0.00302 0.60956 -49.635 0.00402 0.60508 -49.805 0.00502 0.60838 -49.696 0.00602 0.60864 -49.7 0.00702 0.61456 -49.906 0.00802 0.60383 -49.556 0.00902 0.60549 -49.495 0.01002 0.60312 -49.277 0.01102 0.60495 -50.126 0.01202 0.60417 -49.947 0.01302 0.60335 -49.592 0.01402 0.6058 -49.545 0.01502 0.60667 -49.533
figure
yyaxis left
plot(pStats,"Time","Avg_mag")
ylabel('Magnitude')
xlabel('Time (s)')
yyaxis right
plot(pStats,"Time","Avg_phase")
ylabel('Phase (deg)')

Accedi per commentare.

Categorie

Scopri di più su Data Import from MATLAB in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by