|
7 | 7 | % |
8 | 8 | % Parameters |
9 | 9 | % ---------- |
10 | | -% RAO : array |
| 10 | +% RAO : array (N x 1) |
11 | 11 | % Response amplitude operator [-] |
12 | 12 | % wave_spectrum: struct |
13 | | -% Struct with wave spectral density [m^2/Hz] and frequency [Hz] |
14 | | -% response_desired: int or float |
15 | | -% Latitude longitude pairs at which to extract data. |
| 13 | +% wave_spectrum.spectrum - Spectral density [m^2/Hz] (N x 1) |
| 14 | +% wave_spectrum.frequency - Frequency [Hz] (N x 1) |
| 15 | +% response_desired: scalar |
| 16 | +% Desired response amplitude |
16 | 17 | % |
17 | 18 | % Returns |
18 | 19 | % ------- |
19 | 20 | % mler : struct |
20 | | -% containing conditioned wave spectral amplitude |
21 | | -% coefficient [m^2-s], and phase [rad] indexed by frequency [Hz]. |
| 21 | +% mler.conditioned_spectrum - Conditioned wave spectral amplitude [m^2-s] (N x 1) |
| 22 | +% mler.phase - Phase [rad] (N x 1) |
| 23 | +% mler.frequency - Frequency [Hz] (N x 1) |
22 | 24 | % |
23 | 25 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
24 | 26 |
|
|
32 | 34 | error('ERROR: response_desired must be an int or double') |
33 | 35 | end |
34 | 36 |
|
| 37 | +% validate all inputs have same length |
| 38 | +N = length(RAO); |
| 39 | +if length(wave_spectrum.frequency) ~= N || length(wave_spectrum.spectrum) ~= N |
| 40 | + error('MHKiT:loads:mler_coefficients: RAO, frequency, and spectrum must have same length'); |
| 41 | +end |
| 42 | + |
35 | 43 | % convert from Hz to rad/s |
36 | | -freq = wave_spectrum.frequency * (2*pi); |
37 | | -freq_hz = wave_spectrum.frequency; |
38 | | -wave_spectrum = wave_spectrum.spectrum / (2*pi); |
39 | | -dw = (2*pi - 0) / (length(freq)-1); |
| 44 | +freq_rad = wave_spectrum.frequency * (2*pi); |
| 45 | +wave_spectrum_rad = wave_spectrum.spectrum / (2*pi); |
| 46 | +dw = (2*pi - 0) / (N-1); |
40 | 47 |
|
41 | 48 | % response spectrum |
42 | | -R.spectrum = abs(RAO).^2 .* (2*wave_spectrum); |
| 49 | +R.spectrum = abs(RAO).^2 .* (2*wave_spectrum_rad); |
43 | 50 | R.type = 'response'; |
44 | | -R.frequency = freq; |
| 51 | +R.frequency = freq_rad; |
45 | 52 |
|
46 | 53 | % spectral moment calculations |
47 | 54 | m0 = frequency_moment(R, 0); |
|
50 | 57 | wBar = m1/m0; |
51 | 58 |
|
52 | 59 | % calculate coefficient_a from Quon2016 Eqn.8 |
53 | | -coeff_a_rn = abs(RAO) .* sqrt(2*wave_spectrum*dw) .* ((m2 - freq*m1) + wBar*(freq*m0 - m1)) ./ (m0*m2 - m1^2); |
| 60 | +coeff_a_rn = abs(RAO) .* sqrt(2*dw.*wave_spectrum_rad) .* ((m2 - freq_rad.*m1) + wBar.*(freq_rad.*m0 - m1)) ./ (m0*m2 - m1^2); |
54 | 61 | % phase delay should be positive number |
55 | 62 | phase = -unwrap(angle(RAO)); |
56 | 63 | % for negative values of Amp, add pi phase shift, flip sign |
57 | 64 | phase(coeff_a_rn < 0) = phase(coeff_a_rn < 0) - pi; |
58 | 65 | coeff_a_rn(coeff_a_rn < 0) = coeff_a_rn(coeff_a_rn < 0) * -1; |
59 | 66 |
|
60 | 67 | % calculate conditioned spectrum [m^2-s/rad] |
61 | | -S = wave_spectrum .* coeff_a_rn.^2 .* response_desired^2; |
62 | | -S(isnan(S)) = 0; % replace nans with zero |
| 68 | +conditioned_spectrum = wave_spectrum_rad .* coeff_a_rn.^2 .* response_desired^2; |
| 69 | +conditioned_spectrum(isnan(conditioned_spectrum)) = 0; % replace nans with zero |
63 | 70 | % if the response amplitude we ask for is negative, we will add |
64 | 71 | % a pi phase shift to the phase information. This is because |
65 | 72 | % the sign of response_desired is lost in the squaring above. |
|
71 | 78 | end |
72 | 79 |
|
73 | 80 | % outputs |
74 | | -mler.conditioned_spectrum = S; |
| 81 | +mler.conditioned_spectrum = conditioned_spectrum; |
75 | 82 | mler.phase = phase; |
76 | | -mler.frequency = freq_hz; |
| 83 | +mler.frequency = wave_spectrum.frequency; |
77 | 84 |
|
78 | 85 | end |
0 commit comments