Isolate frequency bands of digital signal

Discussion in 'Programmer's Corner' started by bioMaynard, Nov 28, 2015.

  1. bioMaynard

    Thread Starter New Member

    Nov 28, 2015
    8
    0
    Hello all
    i have a digital signal which is an overlay of three signals. breathe(10-20/minute, lowest frequency of high energy), at the end of which there is a high frequency signal (snore) and a periodical signal (heart beat 60-80/minute). I need to create filters on matlab to isolate the three signals with almost zero phase distortion.
    The signal (wav file) is here sites.google.com/site/wavesignalfile

    I am no expert on dsp so all suggestions comments and ideas are very very welcomed. here is what i have done so far. i tried the fft on the signal and after that i filtered the frequency bands. breathe seems legit, heart beat seems not periodical and i do not know how to isolate snoring since i only know that the frequency is "high". feel free to tell me to try stuff but please be descriptive one step at a time.

    Many thanks for reading this.

    matlab code:
    Code (Text):
    1. clear;
    2. [x, Fs] = audioread('wave.wav'); %Fs Sampling frequency
    3.  
    4. figure,plot(x);
    5. title(' Wave Signal');
    6. xlabel('Time');
    7. ylabel('Amplitude');
    8.  
    9. y=fft(x);
    10. f = (0:size(y,1)-1)*Fs/size(y,1); % Frequency vector
    11.  
    12. figure,plot(f,real(y));
    13. title('Power Spectrum of Wave');
    14. xlabel('Frequency (Hz)');
    15. ylabel('Power');
    16.  
    17. y1=y; y1(:)=0; %breathe
    18. y2=y; y2(:)=0; %heart beat
    19. y3=y; y3(:)=0; %snore
    20.  
    21. for i=1:size(y,1)
    22.     if(f(i)>0.1666 && f(i)<0.3334) % breathe 10-20/min equals to 0.16-0.33/sec is that correct????
    23.         y1(i)=y(i);
    24.     elseif(f(i)>1 && f(i)<1.33) %heart
    25.         y2(i)=y(i);
    26. %    elseif(f(i)>   && f(i)>  ) %snore
    27. %        y3(i)=y(i);
    28.     end
    29. end
    30.  
    31. x1=ifft(y1,'symmetric');
    32. figure,plot(real(x1));
    33. title(' Breathe Wave Signal');
    34. xlabel('Time');
    35. ylabel('Amplitude');
    36.  
    37. x2=ifft(y2,'symmetric');
    38. figure,plot(real(x2));
    39. title(' Heart Wave Signal');
    40. xlabel('Time');
    41. ylabel('Amplitude');
    42.  
    43. %x3=ifft(y3,'symmetric');
    44. %figure,plot(real(x3));
    45. %title(' Snore Wave Signal');
    46. %xlabel('Time ');
    47. %ylabel('Amplitude');
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,136
    1,786
    I think it will be ambitious to isolate signals that are so close to each other in frequency. Filtering can attenuate out of band signals but not eliminate them in a way that could be called isolation. I'm curious about your notion of "phase distortion". Usually there is some phase change in the passband along with the attenuation. It is impossible to eliminate, but it can be controlled.
     
  3. bioMaynard

    Thread Starter New Member

    Nov 28, 2015
    8
    0
    Thanks for your respond!
    I see. considering that the goal is filtering to get the best possible results what would you do?
    and do you see a way to find the frequency of snoring? even approximaltely
     
  4. Papabravo

    Expert

    Feb 24, 2006
    10,136
    1,786
    I guess I would try applying a DFT (Discrete Fourier Transform) to see if there are any identifiable peaks where you expect them to be. In this kind of signal processing it is essential that you use analog means to limit the highest frequency component (anti-aliasing filter) and then sample the signals at a minimum of twice that frequency.
     
  5. bioMaynard

    Thread Starter New Member

    Nov 28, 2015
    8
    0
    then i suppose that you agree to my matlab code. Truth being said i have trouble identifying peaks where i expect them to be :p but thank you very much for your comments.
    If someone tries my code or any code and finds something of interest please share.
     
  6. Papabravo

    Expert

    Feb 24, 2006
    10,136
    1,786
    If you have trouble identifying features then you might want to increase the S/N ratio or increase the sample rate. If the input signal is not going through an analog low pass filter then aliasing may destroy any data you are trying to collect.
     
  7. bioMaynard

    Thread Starter New Member

    Nov 28, 2015
    8
    0
    thanks a lot for your suggestions. could you please verify that my matlab code for the dft is correct? that is a way to filter specific frequencies right?
     
  8. Papabravo

    Expert

    Feb 24, 2006
    10,136
    1,786
    Sorry, but your Matlab script is greek to me.
     
  9. bioMaynard

    Thread Starter New Member

    Nov 28, 2015
    8
    0
    the frequency 10 per minute is 10/60 =0.1666 per sec = 0.1666Hz on the frequency domain of the dft, right?
     
  10. Papabravo

    Expert

    Feb 24, 2006
    10,136
    1,786
    That arithmetic is correct. I gather your idea is to produce a time domain version of each signal by doing an inverse transform on band limited ranges of the frequency domain data. I don't think the results will be all that satisfying. You're throwing away too much information IMHO. You should do the experiment to see for yourself.
     
  11. bioMaynard

    Thread Starter New Member

    Nov 28, 2015
    8
    0
    i agree with you but i have to start somewhere. i cant do anything about sampling rate or analog filtering. the signal is digital at 2 khz i have to take it from there. i already uploaded it, would it help if i uploaded plots of the time or frequency domain too?
     
  12. Papabravo

    Expert

    Feb 24, 2006
    10,136
    1,786
    I'm not sure, but it couldn't hurt.
    I would suggest three parallel bandpass filters but your two lowest signals are just too close together to allow for much of a transition band. Locating the higher frequency stuff should be doable since there is a large transition band from 1.33 Hz to 1 kHz which is the highest frequency you would expect to find at a sample rate of 2 kHz.

    We usually speak of the rolloff of a filter, as the ability to attenuate out of band signals, as 20 dB/decade for example. This means if you have two frequencies that are a decade apart, 1 Hz. and 10 Hz. and you ran them through a lowpass filter with a corner frequency of 1 Hz. The 1 Hz. signal would be down by 3 dB and the 10 Hz. signal would be down by 23 dB.

    In your example going from .33 Hz. to 1 Hz., that same 20 dB attenuation would require a digital filter with a truly impressive number of taps and a characteristic of maybe 200 dB/decade. These are difficult goals to achieve.

    I would use the FFT information to guide you in constructing either digital or analog filters.
     
    Last edited: Nov 30, 2015
  13. BR-549

    Well-Known Member

    Sep 22, 2013
    1,981
    388
    How were the 3 signals overlayed on the 2khz digital?

    I am not able to view your file.
     
  14. bioMaynard

    Thread Starter New Member

    Nov 28, 2015
    8
    0
    Sorry im not sure, i dont concern myself with that part. The file is on a standard google site. There is a little blue arrow on the bottom right to download it, and then you can plot it using the first 7 lines of the code (top of the page).
     
  15. BR-549

    Well-Known Member

    Sep 22, 2013
    1,981
    388
    Ok, I downloaded it. Thanks.

    I would put my time and effort into getting three isolated analog signals.

    Sorry I could not help.
     
  16. bioMaynard

    Thread Starter New Member

    Nov 28, 2015
    8
    0
    Dont worry about it, all i look for is opinions and ideas. i will try some filters as papabravo suggested and i will be back with results
     
Loading...