divide audio signal into frames

42 ビュー (過去 30 日間)
Rusmaya Luthfina
Rusmaya Luthfina 2011 年 12 月 21 日
コメント済み: Ravi 2023 年 1 月 27 日
hi all,
i've 2second audio signal, i want to divide it into 20 frames and each frame is 100ms length.
for i = 1:100:2000
%do process
end
did i write the right code? or is there any other way to divide it? really need ur help...
thank u

採用された回答

Naz
Naz 2011 年 12 月 21 日
If you know for sure that your signal is 2 seconds long, then the sampling frequency can be found from dt*N=2, where dt=1/fs is sampling period and N is number of samples, which you don't need.
IF you already have an array of sampled signal, it has particular length (number of samples). In addition, you know that the 'duration' of that array is 2 seconds, so, you must break your array onto 2000ms/100ms=20 pieces:
x=[your array of N samples];
n=round(length(x)/20); %find how many samples will each frame contain
P=zeros(n,20); %preallocate the matrix for 20 colums of Nsamples/20 in each
for k=0:19
P(:,k+1)=x(1+n*k:n*(k+1));
end
Not sure if this works, but the idea is there. There could be an easier way to break your signals into frames: just know that the array of samples must be broken onto 20 pieces.
  3 件のコメント
Rusmaya Luthfina
Rusmaya Luthfina 2011 年 12 月 22 日
thx for your answer, i get the idea of your answer, actually i'm extracting audio features in time domain such as average energy, zcr, and silence ratio. i've implemented ur idea but with simple code i understand.. anyway,, thank u so much for ur answer..
__maya__
Ravi
Ravi 2023 年 1 月 27 日
Dear Rusmaya,
Could you find the average of different(here 20) frames after you have broken down the 2 second long time domain signal? How to find the average of all the frames ?

サインインしてコメントする。

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2011 年 12 月 21 日
That code is probably not correct, as it does not take in to account the sampling frequency and instead implicitly assumes that the data was sampled at 1 ms per sample which would be a sampling rate of 1000 Hz.
When Fs designates your sampling frequency, 100 ms would be Fs/10 . That will probably be an integer, but better would not be to assume that.
But being lax for a moment,
windowsize = Fs/10;
trailingsamples = mod(length(YourSignal), windowsize);
sampleframes = reshape( YourSignal(1:end-trailingsamples), windowsize, []);
Now the columns of sampleframes will be the individual frames, such as sampleframes(:,3) for the third frame.
  3 件のコメント
Walter Roberson
Walter Roberson 2013 年 3 月 12 日
That code is for the case where Fs/10 is an integer. If it is not an integer, then you need to define what it means to divide into 100 ms frames.
prasanna patil
prasanna patil 2013 年 3 月 13 日
yeah sir, it worked... thank u...

サインインしてコメントする。


saibaba
saibaba 2013 年 4 月 6 日
i am doing a project on "speech enhancement" am also using the same process but am not understanding it clearly what am i using u use round for the length of the signal but i use the floor does it make any difference. i want to post my code can anyone explain what is happening in it......
actually my aim is to reduce the noise using kalman filter and i got the output too... i want how its happening inner view of it... can anyone explain
matlab code:
[x,Fs4,bits4]=wavread('DEKF_white_stat_7db__noisy.wav'); xx=x; N=256; % frame length m=N/2; % of each frame of the moving distance lenth=length(x); % the length of the input signal count=floor(lenth/m)-2; x=x/max(abs(x)); t=(0:length(x)-1)/Fs4; s=1; p=11; a=zeros(1,p); w=hamming(N); y_temp=0; F=zeros(11,11); F(1,2)=1; F(2,3)=1; F(3,4)=1; F(4,5)=1; F(5,6)=1; F(6,7)=1; F(7,8)=1; F(8,9)=1; F(9,10)=1; F(10,11)=1; H=zeros(1,p); S0=zeros(p,1); P0=zeros(p); S=zeros(p); H(11)=1; s=zeros(N,1); G=H'; P=zeros(p); y_temp=cov(x(1:7680)); x_frame=zeros(256,1); x_frame1=zeros(256,1); T=zeros(lenth,1); for r=1:count x_frame=x((r-1)*m+1:(r+1)*m); if r==1 [a,VS]=lpc(x_frame(:),p); else [a,VS]=lpc(T((r-2)*m+1:(r-2)*m+256),p); end if (VS-y_temp>0) VS=VS-y_temp; else VS=0.0005; end
F(p,:)=-1*a(p+1:-1:2);
if r==1
S=[zeros(p,1)]; %state vector
P0=[zeros(p,p)]; %error covatiance
else
P0=P;
end
for j=1:256
if(j==1)
S=F*S0;
Pn=F*P*F'+G*VS*G';
else
S=F*S;
Pn=F*P*F'+G*VS*G';
end
K=Pn*H'*(y_temp+H*P*H').^(-1);
P=(eye(p)-K*H)*Pn;
S=S+K*[x_frame(j)-H*S];
T((r-1)*m+j)=H*S;
end
% End cycle calculation LPC parameters
end rt=137.78/128; figure(1); subplot(2,1,1); plot(t,x); xlabel('Time'); ylabel('Amplitude'); title('Original'); sound(x,Fs4,bits4); x1=T./rt; wavwrite(x1,Fs4,bits4,'kalman_denosed.wav'); [x1,Fs4,bits4] = wavread('kalman_denosed.wav'); x1=x1/max(abs(x1)); t=(0:length(x1)-1)/Fs4; subplot(2,1,2); plot(t,x1); xlabel('Time'); ylabel('Amplitude'); title('Denoised Kalman'); display('done'); sound(x1,Fs4,bits4);
sr=sum(x.^2) %Speech Power nro=sum((x-x1).^2) %Output Noise Power % nri=sum((speech-x).^2); %Input Noise Power % SNRi=10*log10(sr/nri) %Input SNR SNRo=10*log10(sr/nro) %Output SNR

カテゴリ

Help Center および File ExchangeAudio I/O and Waveform Generation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by