why the number of point of sfft and istft is different、

8 views (last 30 days)
I do stft to a sound,then I use the result of stft to do istft,but i find the sample point is different.
The original sound is 338160*1 double,after istft,the rebuild sound is 338112*1 double.How can I rebuild sound in the same as the point of original point?
I have try others' sound,all the number loss(original point -rebuild point) is 48.such as 338160-338112=48.

Accepted Answer

David Goodmanson
David Goodmanson on 5 Sep 2021
Edited: David Goodmanson on 30 Sep 2021
Hi neal,
The documentation for stft says that if you want the number of sample points to be unaffected, then if
length of the signal = n,
width of the window = w
number of overlap points = 'over'
then (n-over)/(w-over) must an integer. But things are a lot easier to deal with by using the equivalent condition,
(n-w)/(w-over) = integer
For that to be true, whatever the prime factors of (n-w) are, then (w-over) must be composed of a product of some ot those prime factors.
n = 338160;
w = 256;
factor(n-w)
ans = 2 2 2 2 7 7 431
If (w-over), the unoverlapped portion of the window, is denoted by z, then fortunately for a window of length 256, there are a lof of available factors for z. In your case, though, z = 64 does not divide (n-w) so things don't work, as you found out. Here are possibilities for z, with z = 64 also included:
format short g
z = [49 8*7 64 2*49 16*7];
over = w-z
Ratio = (n-w)./(w-over) % should be an integer
fracn = over/w % overlap fraction
over = 207 200 192 158 144
Ratio = 6896 6034 5279.8 3448 3017
fracn = 0.80859 0.78125 0.75 0.61719 0.5625
so there are some choices available. If you really like 75% overlap exactly and don't care about 256 for window length, then
n = 338160;
w = 240;
over = 180; % z = 60
factor(n-w)
Ratio = (n-w)./(w-over)
ans = 2 2 2 2 2 2 2 2 2 2 2 3 5 11
Ratio = 5632
works

More Answers (0)

Categories

Find more on Time-Frequency Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!