Time-frequency analysis using spectogram

9 次查看(过去 30 天)
% 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.

采纳的回答

Sulaymon Eshkabilov
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')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by