Time-frequency analysis using spectogram

12 ビュー (過去 30 日間)
Shanmuka
Shanmuka 2023 年 2 月 17 日
回答済み: Sulaymon Eshkabilov 2023 年 2 月 17 日
% 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
Sulaymon Eshkabilov 2023 年 2 月 17 日
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 Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by