Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
What exactly is happening in this line of code speech_out = speech(1:1/1.01964:length(speech),:);?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to make an incoming signal of a desired length in order to perform speech recognition calculations on it in a similar manner to every incoming signal. I originally tried interpolating and decimating to get to desired length, but that would result in a vector with every element being 0, probably because it had to run through the decimation process so many times.
So I found these lines of code from https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html:
And it seemed like this would accomplish what I wanted in the first place, stretching or shrinking the signal array whilst keeping the form of the signal.
I understand the following inputs:
speech_out = speech(1:2:length(speech),:); will delete every other row starting with the second element.
speech_out = speech(1:1/2:length(speech),:); will duplicate every other row starting with the second element.
speech_out = speech(1:1/1.25:length(speech),:); will duplicate every fourth row starting after the newly duplicated element.
This is essentially multiplying the length of the array by the inverse of the 2nd input (e.g. 2, 1/2, 1/1.25, etc...) and results in the correctly sized signal and seems to keep the form of the signal.
Code used:
desired_length = 89728;
speech_out = speech(1:(1/(desired_length/length(speech))):length(speech),:); %iso_sig
BEFORE CODE: (After taking out the silences from the signal)
AFTER CODE: (Now of correct size, while seemingly retaining the important information)
What I don't understand is when it starts to come down to weirder fractions like 1/1.01964, where it swings between duplicating every 51st, 52nd, or 53rd row (might be a larger range, but this is just what I noticed after scrolling through some of the array). I would like to know how it determines which row to duplicate, because I'm eventually going to want to move this code to C to program a DSP.
*Bonus: I also think that this may be screwing up my end result 256pt-FFT, because every window of FFT shows the same form for whatever signal I put through it.
This is showing the dominant frequencies to consistently be at Fs/2 and Fs, where my Fs = 44kHz. I was thinking that the above function I was asking about is somehow affecting my FFT, but I don't see why it would be if my signal is still keeping its form.
0 commentaires
Réponses (1)
dpb
le 24 Nov 2019
MATLAB rounds to nearest integer for the fractional subscript for indexing. Not recommended technique, use the Signnal Processing TB resample function instead.
2 commentaires
dpb
le 24 Nov 2019
Not exactly. resample "applies an antialiasing FIR lowpass filter to x and compensates for the delay introduced by the filter." If you're doing spectral work with the signal, this can be important.
If you don't care about such niceties, there's always interp1 or resample with the explicit timestep input option available.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!