Hi I have Csv file for voltage and time data and I would like to compute spectrogram to to compute harmonics at different frequencies but my spectrogram looks so much noisy or
Afficher commentaires plus anciens
%%
folder = 'C:\Users\Min\Desktop\New folder (3)';
filename = '27o2.csv';
data = readtable(fullfile(folder, filename));
t = table2array(data(3:end, 1));
x = table2array(data(3:end, 2));
fs = 1 / (t(2) - t(1));
% Plot the spectrogram
figure;
spectrogram(x, 500,100,500, fs, 'yaxis');
% Customize the plot
xlabel('Time (s)');
ylabel('Frequency (MHz)');
colormap("hot")
title('Spectrogram');
colorbar;

Réponse acceptée
Plus de réponses (1)
What do you mean by "noisy"? Your calculation gives you the correct information, i.e., sum of harmonic sinusoidals. First of all, let's take a look at how your signal looks in time domain.
%%
folder = pwd;
filename = '27o2.csv';
data = readtable(fullfile(folder, filename));
t = table2array(data(3:end, 1));
x = table2array(data(3:end, 2));
fs = 1 / (t(2) - t(1));
figure;
plot(t, x);
axis tight
It looks like the signal is quite stationary, i.e., no big change of mean and variance. And I don't see a sudden change in the signal. Hence, let's take a look at the FFT result.
%% FFT
T = 1/fs; % Sampling period
L = length(x); % Length of signal
t = (0:L-1)*T; % Time vector
Y = fft(x);
figure;
plot(fs/L*(-L/2:L/2-1),abs(fftshift(Y)),"LineWidth",3)
title("fft Spectrum in the Positive and Negative Frequencies")
xlabel("f (Hz)")
ylabel("|fft(X)|")
Just like you said, it has harmonic components.
Now, let's give a slight change to your STFT calculation, i.e., give bigger overlap so that it can have a "smoother" result.
%% Plot the spectrogram
figure;
spectrogram(x, 500, 480, [], fs, 'yaxis');
% Customize the plot
xlabel('Time (s)');
ylabel('Frequency (MHz)');
colormap("hot")
title('Spectrogram');
colorbar;
1 commentaire
Honey
le 9 Juil 2024
Catégories
En savoir plus sur Get Started with Signal Processing Toolbox dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



