Time-frequency analysis using spectogram

12 vues (au cours des 30 derniers jours)
Shanmuka
Shanmuka le 17 Fév 2023
% Load the measurement signal from a .mat file
x=load('signal27.mat');
% Set the parameters for the spectrogram
window_size = 1024; % Size of the analysis window
overlap = window_size/2; % Amount of overlap between windows
nfft = window_size; % Number of FFT points
fs = 1000; % Sampling rate
% Compute the spectrogram
[S, F, T] = spectrogram(x, window_size, overlap, nfft, fs);
% Plot the spectrogram
imagesc(T, F, abs(S));
axis xy;
xlabel('Time (s)');
ylabel('Frequency (Hz)');
WHen trying to run this code, it gives me error on 'pwelch'
Error using pwelch
Expected x to be one of these types:
single, double
Instead its type was struct.
Error in signal.internal.spectral.welchparse>parse_inputs (line 111)
validateattributes(x2,{'single','double'}, {'finite','nonnan'},'pwelch','x')
Error in signal.internal.spectral.welchparse (line 31)
parse_inputs(x1,esttype,varargin{:});
Error in pspectrogram (line 30)
[xw,nx,~,yw,ny,win,~,~,noverlap,~,~,options] = signal.internal.spectral.welchparse(x,esttype,inpArgs{:});
Error in spectrogram (line 191)
[varargout{1:nargout}] = pspectrogram({x},'spect',inpArgs{:});
Error in a (line 11)
[S, F, T] = spectrogram(x, window_size, overlap, nfft, fs);
Can anyone suggest what am i doing wrong here?
And also I need to use "spectogram" command to plot images.

Réponse acceptée

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 17 Fév 2023
There are a couple of inconsistencies (fs value was incorrect and not read from the signal27.mat) in the code. Here is the corrected code:
% Load the measurement signal from a .mat file
x=load('signal27.mat').y;
fs = load('signal27.mat').Fs; % Sampling rate
% Set the parameters for the spectrogram
window_size = 1024; % Size of the analysis window
overlap = window_size/2; % Amount of overlap between windows
nfft = window_size; % Number of FFT points
% Compute the spectrogram
[S, F, T] = spectrogram(x, window_size, overlap, nfft,fs);
% Plot the spectrogram
imagesc(T, F, abs(S));
axis xy;
xlabel('Time (s)');
ylabel('Frequency (Hz)');
figure
spectrogram(x, 'yaxis')

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by