clear
clc
% 假设已知的南北和东西风速分量时程
time = 0:1:999; % 时间步长为1秒
north_south_wind_speed = 8 + 2 * sin(2 * pi * 0.1 * time); % 南北风向分量
east_west_wind_speed = 6 + 1 * sin(2 * pi * 0.1 * time); % 东西风向分量
% 计算合风速和风向
total_wind_speed = sqrt(north_south_wind_speed.^2 + east_west_wind_speed.^2);
wind_direction = atan2(east_west_wind_speed, north_south_wind_speed) * (180/pi);
% 将数据按1分钟平均
averaging_interval = 60; % 秒
num_intervals = floor(length(time) / averaging_interval);
mean_wind_speed = zeros(1, num_intervals);
pulsating_wind_speed_vertical = zeros(1, length(time));
pulsating_wind_speed_parallel = zeros(1, length(time));
for i = 1:num_intervals
start_idx = (i-1) * averaging_interval + 1;
end_idx = min(i * averaging_interval, length(time));
mean_wind_speed(i) = mean(total_wind_speed(start_idx:end_idx));
% 旋转风速分量
rotated_wind_speed = [cosd(-wind_direction(start_idx)) -sind(-wind_direction(start_idx)); sind(-wind_direction(start_idx)) cosd(-wind_direction(start_idx))] * ...
[north_south_wind_speed(start_idx:end_idx); east_west_wind_speed(start_idx:end_idx)];
% 计算垂直于合风速方向的脉动风速
pulsating_wind_speed_vertical(start_idx:end_idx) = rotated_wind_speed(2,:) - mean(rotated_wind_speed(2,:));
% 计算与合风速方向一致的脉动风速
pulsating_wind_speed_parallel(start_idx:end_idx) = rotated_wind_speed(1,:) - mean(rotated_wind_speed(1,:));
end
% 绘制结果
figure;
subplot(3,1,1);
plot(time, total_wind_speed, 'LineWidth', 1.5, 'DisplayName', '合风速');
xlabel('时间 (秒)');
ylabel('风速 (m/s)');
title('合风速时程');
legend;
grid on;
subplot(3,1,2);
plot(time, pulsating_wind_speed_vertical, 'LineWidth', 1.5, 'DisplayName', '垂直脉动风速');
xlabel('时间 (秒)');
ylabel('风速 (m/s)');
title('垂直于合风速方向的脉动风速时程');
legend;
grid on;
subplot(3,1,3);
plot(time, pulsating_wind_speed_parallel, 'LineWidth', 1.5, 'DisplayName', '平行脉动风速');
xlabel('时间 (秒)');
ylabel('风速 (m/s)');
title('与合风速方向一致的脉动风速时程');
legend;
grid on;