|
34 | 34 | error('ERROR: response_desired must be an int or double') |
35 | 35 | end |
36 | 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 | + |
37 | 43 | % convert from Hz to rad/s |
38 | | -freq = wave_spectrum.frequency * (2*pi); |
39 | | -freq_hz = wave_spectrum.frequency; |
40 | | -wave_spectrum = wave_spectrum.spectrum / (2*pi); |
41 | | -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); |
42 | 47 |
|
43 | 48 | % response spectrum |
44 | | -R.spectrum = abs(RAO).^2 .* (2*wave_spectrum); |
| 49 | +R.spectrum = abs(RAO).^2 .* (2*wave_spectrum_rad); |
45 | 50 | R.type = 'response'; |
46 | | -R.frequency = freq; |
| 51 | +R.frequency = freq_rad; |
47 | 52 |
|
48 | 53 | % spectral moment calculations |
49 | 54 | m0 = frequency_moment(R, 0); |
|
52 | 57 | wBar = m1/m0; |
53 | 58 |
|
54 | 59 | % calculate coefficient_a from Quon2016 Eqn.8 |
55 | | -coeff_a_rn = abs(RAO) .* sqrt(2*dw.*wave_spectrum) .* ((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); |
56 | 61 | % phase delay should be positive number |
57 | | -phase = unwrap(angle(RAO)); |
| 62 | +phase = -unwrap(angle(RAO)); |
58 | 63 | % for negative values of Amp, add pi phase shift, flip sign |
59 | 64 | phase(coeff_a_rn < 0) = phase(coeff_a_rn < 0) - pi; |
60 | 65 | coeff_a_rn(coeff_a_rn < 0) = coeff_a_rn(coeff_a_rn < 0) * -1; |
61 | 66 |
|
62 | 67 | % calculate conditioned spectrum [m^2-s/rad] |
63 | | -S = wave_spectrum .* coeff_a_rn.^2 .* response_desired^2; |
64 | | -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 |
65 | 70 | % if the response amplitude we ask for is negative, we will add |
66 | 71 | % a pi phase shift to the phase information. This is because |
67 | 72 | % the sign of response_desired is lost in the squaring above. |
|
73 | 78 | end |
74 | 79 |
|
75 | 80 | % outputs |
76 | | -mler.conditioned_spectrum = S; |
| 81 | +mler.conditioned_spectrum = conditioned_spectrum; |
77 | 82 | mler.phase = phase; |
78 | | -mler.frequency = freq_hz; |
| 83 | +mler.frequency = wave_spectrum.frequency; |
79 | 84 |
|
80 | 85 | end |
0 commit comments