필터 지우기
필터 지우기

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 CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by