How can I solve this confidence level error?

6 ビュー (過去 30 日間)
kim
kim 2024 年 11 月 15 日
コメント済み: Star Strider 2024 年 11 月 16 日
I was trying to plot data of power spectra of pressure, u, v. However, the confidence level keep plotting strange.
I think my confidence level is missing something, or reason that I didn't apply code 'butter'.
Attached file is on .txt, original file is on .dat
clear all
close all
clc
data_uv = load('D5_SN111.dat'); % u, v data
data_pressure = load('D5_SN111(1).dat'); % pressure data
u = data_uv(:, 7); % u 성분 (7번째 열)
v = data_uv(:, 8); % v 성분 (8번째 열)
% D5_SN111(1).dat: year month day hour minute sec pressure
pressure = data_pressure(:, 7); % pressure data
pressure = fillmissing(pressure, 'linear');
u = fillmissing(u, 'linear');
v = fillmissing(v, 'linear');
WINDOW = 1024 * 2;
NOVERLAP = 512 * 2;
NFFT = 1024 * 2;
Fs = 1; % (1 sample/hour)
confcen = 10; %
conf_level = 100; %
%% pressure data PSD
figure;
[pxx_pressure, f_pressure, Pxxc_pressure] = pwelch(pressure, WINDOW, NOVERLAP, NFFT, Fs, 'ConfidenceLevel', 0.95);
loglog(f_pressure, pxx_pressure, 'k'); % 파워 스펙트럼 밀도 그래프
hold on;
confup = Pxxc_pressure(conf_level, 2) ./ pxx_pressure(conf_level) * confcen;
confdn = Pxxc_pressure(conf_level, 1) ./ pxx_pressure(conf_level) * confcen;
loglog([f_pressure(conf_level), f_pressure(conf_level)], [confdn, confup], 'r', 'LineWidth', 1.5);
title('Power spectra of bottom pressure at D5');
xlabel('Frequency (Hz)');
ylabel('Power/frequency (dbar^2/Hz)');
grid on;
legend('PSD', '95% Confidence Interval');
hold off;
%% u data's PSD
figure;
[pxx_u, f_u, Pxxc_u] = pwelch(u, WINDOW, NOVERLAP, NFFT, Fs, 'ConfidenceLevel', 0.95);
loglog(f_u, pxx_u, 'b');
hold on;
confup = Pxxc_u(conf_level, 2) ./ pxx_u(conf_level) * confcen;
confdn = Pxxc_u(conf_level, 1) ./ pxx_u(conf_level) * confcen;
loglog([f_u(conf_level), f_u(conf_level)], [confdn, confup], 'r', 'LineWidth', 1.5);
title('Power spectra of U at D5');
xlabel('Frequency (Hz)');
ylabel('Power/frequency ((cm/s)^2/Hz)');
grid on;
legend('PSD', '95% Confidence Interval');
hold off;
%%v data's PSD
figure;
[pxx_v, f_v, Pxxc_v] = pwelch(v, WINDOW, NOVERLAP, NFFT, Fs, 'ConfidenceLevel', 0.95);
loglog(f_v, pxx_v, 'g');
hold on;
confup = Pxxc_v(conf_level, 2) ./ pxx_v(conf_level) * confcen;
confdn = Pxxc_v(conf_level, 1) ./ pxx_v(conf_level) * confcen;
loglog([f_v(conf_level), f_v(conf_level)], [confdn, confup], 'r', 'LineWidth', 1.5);
title('Power spectra of V at D5');
xlabel('Frequency (Hz)');
ylabel('Power/frequency ((cm/s)^2/Hz)');
grid on;
legend('PSD', '95% Confidence Interval');
hold off;
and, this is what I got.
However, I was trying to get such data.
I have no idea what I'm missing with.

採用された回答

Star Strider
Star Strider 2024 年 11 月 15 日
You are plotting it incorrectly.
Use this:
loglog(f_pressure, Pxxc_pressure, 'r', 'LineWidth', 1.5);
instead of:
loglog([f_pressure(conf_level), f_pressure(conf_level)], [confdn, confup], 'r', 'LineWidth', 1.5);
and other incidents with similar code.
Note that ‘conf_level’ is a scalar with a single value (100), so it will only plot the confidence level at that one point. If that is the only value you want to plot, add that subscript to my code, and change the 'r' to a red marker of some type (perhaps '.r') so it will plot points instead of a line connecting them.
I changed all of them to produce this —
% data_uv = load('D5_SN111.dat'); % u, v data
data_uv = load('D5_SN111.txt'); % u, v data
% data_pressure = load('D5_SN111(1).dat'); % pressure data
data_pressure = load('D5_SN111(1).txt'); % pressure data
u = data_uv(:, 7); % u 성분 (7번째 열)
v = data_uv(:, 8); % v 성분 (8번째 열)
% D5_SN111(1).dat: year month day hour minute sec pressure
pressure = data_pressure(:, 7); % pressure data
pressure = fillmissing(pressure, 'linear');
u = fillmissing(u, 'linear');
v = fillmissing(v, 'linear');
WINDOW = 1024 * 2;
NOVERLAP = 512 * 2;
NFFT = 1024 * 2;
Fs = 1; % (1 sample/hour)
confcen = 10; %
conf_level = 100; %
%% pressure data PSD
figure;
[pxx_pressure, f_pressure, Pxxc_pressure] = pwelch(pressure, WINDOW, NOVERLAP, NFFT, Fs, 'ConfidenceLevel', 0.95);
figure
loglog(f_pressure, pxx_pressure, 'k'); % 파워 스펙트럼 밀도 그래프
hold on;
confup = Pxxc_pressure(conf_level, 2) ./ pxx_pressure(conf_level) * confcen
confup = 20.8534
confdn = Pxxc_pressure(conf_level, 1) ./ pxx_pressure(conf_level) * confcen
confdn = 5.8532
loglog(f_pressure, Pxxc_pressure, 'r', 'LineWidth', 1.5);
title('Power spectra of bottom pressure at D5');
xlabel('Frequency (Hz)');
ylabel('Power/frequency (dbar^2/Hz)');
grid on;
legend('PSD', '95% Confidence Interval');
hold off;
%% u data's PSD
figure;
[pxx_u, f_u, Pxxc_u] = pwelch(u, WINDOW, NOVERLAP, NFFT, Fs, 'ConfidenceLevel', 0.95);
loglog(f_u, pxx_u, 'b');
hold on;
confup = Pxxc_u(conf_level, 2) ./ pxx_u(conf_level) * confcen;
confdn = Pxxc_u(conf_level, 1) ./ pxx_u(conf_level) * confcen;
loglog(f_u, Pxxc_u, 'r', 'LineWidth', 1.5)
% loglog([f_u(conf_level), f_u(conf_level)], [confdn, confup], 'r', 'LineWidth', 1.5);
title('Power spectra of U at D5');
xlabel('Frequency (Hz)');
ylabel('Power/frequency ((cm/s)^2/Hz)');
grid on;
legend('PSD', '95% Confidence Interval');
hold off;
%%v data's PSD
figure;
[pxx_v, f_v, Pxxc_v] = pwelch(v, WINDOW, NOVERLAP, NFFT, Fs, 'ConfidenceLevel', 0.95);
loglog(f_v, pxx_v, 'g');
hold on;
confup = Pxxc_v(conf_level, 2) ./ pxx_v(conf_level) * confcen;
confdn = Pxxc_v(conf_level, 1) ./ pxx_v(conf_level) * confcen;
% loglog([f_v(conf_level), f_v(conf_level)], [confdn, confup], 'r', 'LineWidth', 1.5);
loglog(f_v, Pxxc_v, 'r', 'LineWidth', 1.5);
title('Power spectra of V at D5');
xlabel('Frequency (Hz)');
ylabel('Power/frequency ((cm/s)^2/Hz)');
grid on;
legend('PSD', '95% Confidence Interval');
hold off;
.
  4 件のコメント
kim
kim 2024 年 11 月 16 日
編集済み: kim 2024 年 11 月 16 日
It solved!
Always thank you for your help, thanks to your kindness.
Star Strider
Star Strider 2024 年 11 月 16 日
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeVibration Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by