Multi-step coding to model wave data based on pressure--partially figured out

Hello! I am very new to Matlab and have been attempting to create a code to model wave data based on pressure data but I have not been very successful at getting through it. I was luckily given a 20 Step workflow for Matlab by the company who created the sensor but I have been failing at correctly coding it to work in Matlab R2018a. Some of the workflow makes no sense to me and I am hoping that some of you who are experts may be able to discern what the code needs to be for a given step. I think much of what I have done is also not correct. Here is the workflow:
  1. Find the linear regression of the burst data.
  2. Find the “mean depth”
  3. Remove mean depth and detrend the burst data
  4. Apply a Hanning window on the burst data (window size 96 samples) to provide hdata
  5. Apply a 1D real-only DFT on hdata to provide fdata
  6. Find max frequency in fdata, which is either the largest frequency or the largest frequency that can be detected without aliasing (Nyquist)
  7. Remove frequencies higher than max frequency and conjugate aliases in fdata
  8. Apply attenuation-correction to each frequency in fdata
  9. Determine principle frequency
  10. IDFT fdata to provide ifdata
  11. Inverse the Hanning window on ifdata to provide ihdata
  12. The rest is based on ihdata:
  13. Variance (see below).
  14. Energy = variance * gravity * density * 1000.0
  15. Statistics are calculated by determining negative-to-positive zero crossings, ignoring the first partial wave (and dropping last partial wave).
  16. Average period = sum(periods) / n
  17. Average height = sum(heights) / n
  18. Rank sort waves by height
  19. Determine max height, and max period
  20. Significant height and period are calculated on the largest 1/3 of the waves.
  21. 1/10 height and period are calculated on the largest 1/10 of the waves.
Default gravity value = 9.780318.
Default density value = 1.0281
Variance = 1/2 A^2 (m^4)
Wave energy = Variance (m^4) * gravity (m/s^2) * density (g/cm^3) * 1000 (Kg * cm^3 / g * m^3)
My actual dataset is over 330,000,000 row txt file and I have attached a 1,000 sample.txt Between help through the community and Matlab tutorials, I've been able to piece together the following but I'm not sure its correct in the larger context. Steps 4-11 are definitely confusing to me and I do not understand. Any help would be greatly appreciated!
Clm = ('sample.txt');
t = readtable(Clm); % t table
y = t{:,4}; % Step 1 linear regression of pressure and depth
x=t{:,2};
b1 = x\y
yCalc1 = b1*x;
scatter(x,y)
hold on
plot(x,yCalc1) % Got a successful-looking graph
xlabel('Pressure')
ylabel('Depth')
title('Pressure vs Depth')
grid on
X = [ones(length(x),1) x]; % Determine linear regression formula y = ax + b
b = X\y
M = mean(y) % Step 2 Mean of Depth
detrend_t2 = detrend(t{:,2}); % Step 3 Detrend Pressure. Can this be done to the entire table or only per column?
trend2 = t{:,2} - detrend_t2;
detrend_t4 = detrend(t{:,4}); % Step 3 Detrend Depth. How to "remove mean depth"?
trend4 = t{:,4} - detrend_t4;
L = 96 % Apply Hann Window of 96 Samples. Did this actually work on the table or just on the variable? Should this be applied to the entire table?
Hs = trend2.*hann(L);
wvtool(Hs);
wininfo = info(Hs)

Answers (0)

Asked:

on 29 Dec 2018

Edited:

on 29 Dec 2018

Community Treasure Hunt

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

Start Hunting!