0
$\begingroup$

I am performing Short-time Fourier transform on an audio signal (I dont know how to attach the audio file here). The sound was recorded in anechoic chamber and the source is supposed to come from left. Lets say the result of STFT has 'N' number of time frames and 'nfft' FFT coefficients. My goal is to look at the plurality of time-frequency points in a certain frequency band over a plurality of time frames, graphically represented in real and imaginary parts in the complex plane. This is the code:

[x, fs] = audioread('booth.wav');   % load a .wav file x1 = x(:,1); 
                                    %left ear

                          % bandpass filter to work on good frequencies only:   
fc=[300 500]; %because my signal's frequency is in this range  
[b,a] =butter(4,fc/(fs/2),'bandpass'); % Butterworth filter of order 4 

x1 = filter(b,a,x1); 

                                      %perform STFT: 
x=x1(:);  %make sure it's column
xlen=length(x); %length of signal
wlen=2^nextpow2(0.04*fs);  %window length
hop=(3/4)*wlen;       %hop size 
numFrames=1 + fix((xlen - wlen)/hop); %number of frames
nfft=2^nextpow2(wlen);

if mod(nfft,2)==0        %even
  N=nfft/2+1;
elseif mod(nfft,2)==1    %odd
  N=(nfft+1)/2;    
end

window=hamming(wlen,'periodic'); %hamming window
Sl = zeros(numFrames,N); %preallocate stft for left ear
indx=0;  

for i=1:numFrames    
  xw=x(indx+1:indx+wlen).*window;   %multiplying signal to window
  X=(fft(xw,nfft))./wlen;  %fourier transform 
  Sl(i,:)=X(1:N);    %keep half of it        
  indx=indx+hop;   %hop and go to next time frame   
end

f=(0:N-1)*fs/nfft;  %frequency vector
                    %correcting DC and Nyquist
if rem(nfft, 2)         
  Sl(2:end, :) = Sl(2:end, :).*2;
else                
  Sl(2:end-1, :) = Sl(2:end-1, :).*2;
end

                                %Now plotting the points:
figure(1);   
hold on;
grid on;
for j=150:447   %I just want to look at these frequency indices  
  plot(real(Sl(:,j)),imag(Sl(:,j)),'Ob');
  title(['F=', num2str(f(j)), ' hz'])    
  xlabel('real'); ylabel('imaginary');  
  axis([-1 1 -1 1]);
  plot(-1:1,[0,0,0],'k', 'LineWidth', 1);
  plot([0,0,0],-1:1,'k','LineWidth',1)
  pause;
end
  1. If I look at the points at a frequency that I know my fft should have value at it, the points all fall on zero in the complex plane (if not on zero,very close to it). Why?
  2. I tried doing RMS normalization, but the points now are not in the [-1 1] range in complex plane and they are all over the place! I am not sure if I can do something like peak normalization and Rms normalization together?
$\endgroup$
  • $\begingroup$ Hi! How do you access an unechoic chamber ? $\endgroup$ – Fat32 Aug 27 '18 at 19:10
  • $\begingroup$ @Fat32 we have one at school!! $\endgroup$ – Atra Es Aug 27 '18 at 19:11
  • $\begingroup$ So you are a research assistant ? $\endgroup$ – Fat32 Aug 27 '18 at 19:12
  • $\begingroup$ @Fat32 No but I am allowed to use it! Lol. May I ask why? $\endgroup$ – Atra Es Aug 27 '18 at 19:13
  • 1
    $\begingroup$ @AtraEs The best way to format code is to add four spaces before each line. I formatted a few lines, and left the rest for you to fix :) $\endgroup$ – MBaz Aug 27 '18 at 21:05
1
$\begingroup$

This should be a comment but comments have limittaitns

I don't kno if this fixes your problem because I'm not sure what you are doing but using the handel file that comes with matlab

Modifying your code

figure(1);
ii=intersect(find(f>300 ),find(f<500 ));
for j=ii %I just want to look at these frequency indices
plot(real(Sl(:,j)),imag(Sl(:,j)),'Ob'); %grid on;

title(['F=', num2str(f(j)), ' hz']);

produced something.

Hope this helped

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.