Filter löschen
Filter löschen

Where is the data?

4 Ansichten (letzte 30 Tage)
Kenzie
Kenzie am 1 Feb. 2024
Beantwortet: Star Strider am 1 Feb. 2024
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 Kommentare
the cyclist
the cyclist am 1 Feb. 2024
Can you upload the maunaloa_weekly.csv file? You can use the paper clip icon in the INSERT section of the toolbar.
Kenzie
Kenzie am 1 Feb. 2024
just did!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 1 Feb. 2024
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.
.

Weitere Antworten (0)

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by