フィルターのクリア

Where is the data?

4 ビュー (過去 30 日間)
Kenzie
Kenzie 2024 年 2 月 1 日
回答済み: Star Strider 2024 年 2 月 1 日
howdy again,
I am plotting the fourier amplitude spectrum for the mauna loa data yet when I run the code, the plot is empty. is it an axes problem? and if so, how do I fix it so that the x axis is still in 10^nth hertz.
% Load the data
filename = 'maunaloa_weekly.csv';
data = readtable(filename, 'ReadVariableNames', false, 'Delimiter', ',');
variableNames = {'Date', 'Values'};
% Assign variable names to the table
data.Properties.VariableNames(1:2) = variableNames;
% Convert the dates to datetime format
dates = datetime(data.Date, 'Format', 'dd/MM/yyyy');
Values = data.Values;
% Create a time vector using datetime
time_vector = dates;
% Plot the data
figure;
subplot(2, 1, 1);
plot(dates, Values, 'LineWidth', 2);
title('Maunaloa Weekly Data');
xlabel('Time');
ylabel('Floating Point Values');
% Fourier analysis plot
subplot(2, 1, 2);
% Time interval between data points
dt = days(7); % Weekly data
% Perform FFT
N = length(Values);
Fs = 1/days(dt); % Sampling frequency
frequencies = Fs*(0:(N/2))/N;
fft_values = fft(Values);
amplitudes = 2/N * abs(fft_values(1:N/2+1));
% Plot the amplitude spectrum with log scale on x-axis
semilogx(frequencies, amplitudes, 'LineWidth', 2);
title('Fourier Amplitude Spectrum');
xlabel('Frequency (Hz)');
ylabel('Amplitude');
  2 件のコメント
the cyclist
the cyclist 2024 年 2 月 1 日
Can you upload the maunaloa_weekly.csv file? You can use the paper clip icon in the INSERT section of the toolbar.
Kenzie
Kenzie 2024 年 2 月 1 日
just did!

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

採用された回答

Star Strider
Star Strider 2024 年 2 月 1 日
Use fillmissing to interpolate the NaN elements in ‘Values’
% Load the data
filename = 'maunaloa_weekly.csv';
data = readtable(filename, 'ReadVariableNames', false, 'Delimiter', ',');
variableNames = {'Date', 'Values'};
% Assign variable names to the table
data.Properties.VariableNames(1:2) = variableNames;
% Convert the dates to datetime format
dates = datetime(data.Date, 'Format', 'dd/MM/yyyy');
Values = data.Values;
% Create a time vector using datetime
time_vector = dates;
% Plot the data
figure;
subplot(2, 1, 1);
plot(dates, Values, 'LineWidth', 2);
title('Maunaloa Weekly Data');
xlabel('Time');
ylabel('Floating Point Values');
% Fourier analysis plot
subplot(2, 1, 2);
% Time interval between data points
dt = days(7); % Weekly data
% Perform FFT
fprintf('There are %d NaN elements in ''Values''.\n',nnz(isnan(Values)))
There are 44 NaN elements in 'Values'.
Values = fillmissing(Values,'linear');
N = length(Values);
Fs = 1/days(dt); % Sampling frequency
frequencies = Fs*(0:(N/2))/N;
fft_values = fft(Values);
amplitudes = 2/N * abs(fft_values(1:N/2+1));
% Plot the amplitude spectrum with log scale on x-axis
semilogx(frequencies, amplitudes, 'LineWidth', 2);
title('Fourier Amplitude Spectrum');
xlabel('Frequency (Hz)');
ylabel('Amplitude');
Make appropriate changes to get the result you want.
.

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by