returned T in spectrogram()
显示 更早的评论
Hi All!
Suppose that I want to divide a signal in segments and I want to calculate the center of those segments and the respective time. Suppose that I' ve
signal = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17];
fs_audio = 0.5; % sampling frequency = 0.5 HZ
winLen_Sec_desired = 5 % length of a segment in seconds = 5 seconds
winOverlap_desired = 0.4 % percentage of overlapping segments = 40%
depending on the sampling frequency the desired parameter won't be the real ones, but it's ok...
winLenSamp = round(winLenSec_desired*fs_audio); % length of a segment in
% samples
if mod(winLenSamp,2) == 0 % check that the segment has an odd size
winLenSamp = winLenSamp+1;
end
winLenSec_Real = winLenSamp/fs_audio; % our window size will be slightly
% different from the one desired
winOverlapSamp = ceil(winLenSamp*winOverlap_desired);
winOverlap_Perc = winOverlapSamp/winLenSamp; % our overlap will be slightly
% different from the one desired
winStep = winLenSamp - winOverlapSamp; % we'll have a center each winStep
% samples
firstCenter = ceil(winLenSamp*0.5); % calculate the first center
j = 1;
i = firstCenter;
while (i + winLenSamp - firstCenter) <= length(signal) %till we exceed
% the dimension
winCenters(j) = i; %save in winCenters the center of the segment j
j= j +1; % increment the segment
i= i + winStep; % calculate the new center position
end
time = (0:length(signal)-1)/fs_audio;
winTime = time(winCenters);
I hope that till here everything is correct... Anyway I'm interested in winTime and winCenters
Now I have to use the spectrogram function in matlab to compute the STFT of the signal. In particular I use
VECTORFREQ = [150:10:400];
[S F T P] = spectrogram(signal, rectwin(winLenSamp), winOverlapSamp, VECTORFREQ, fs_audio, 'yaxis');
in order to have back the vector T containing the time instants for each segment in which the FFT is calculated.
I guess that T and winTime calculated before should be the same but they are not! Any guess?
Thanks a lot Gabriele
ps I know that to divide a signal in segments I can use the function buffer, but it doesn't return the center of the segments nor the time where each segment is centered.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Time-Frequency Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!