From audio signal to mean of frequency responses

5 views (last 30 days)
Hi there,
Im not very advanced in Matlab.
I have an audio signal of exhaling air and want to obtain the mean of frequency responses of that signal so that I can further evaluate the lung function by converting the mean of frequency responses to flow rate. The following steps I want to do
  • Segment the file into 100 millisecond segments
  • Convert each segment into frequency domain using Fast Fourier Transformation.
  • Apply Butterworth filter on each segment to extract frequencies between 100 HZ and 1200 HZ.
  • Calculate the mean of frequency responses between 100 HZ and 1200 HZ for each segment.
The following code I found that performs the first two steps. After that I found it difficult to apply a butterworth filter and calculate the mean of frecuency responses.
I hope someone can help me out here.
[data, fs] = audioread('test-kort3.wav');
% read exhalation audio wav file (1 channel, mono)
% frequency is 44100 HZ
% windows of 0.1 s and overlap of 0.05 seconds
WINDOW_SIZE = fs*0.1; %4410 = fs*0.1
array_size = length(data); % array size of data
numOfPeaks = (array_size/(WINDOW_SIZE/2)) - 1;
step = floor(WINDOW_SIZE/2); %step size used in loop
transformed = data;
start =1;
k = 1;
t = 1;
g = 1;
o = 1;
% performing fft on each window and finding the peak of windows
i =start;
WindowArray(j) = transformed(i);
j = j+1;
i = i +1;
Y = fft(WindowArray);
p = abs(Y).^2; %power

Accepted Answer

Christopher McCausland
Christopher McCausland on 20 Jul 2022
Hi Julia,
A butterworth filter can be applied with the butter() command as detailed in the documentation.
A more intuative approch to get started is to use the design filter fucntion within MATLAB, This would look something like;
function filteredOutput = bandpassFilter(data,fs,LC,HC,Order)
% Create bandstop filter and filter data
% data - a vector of numerical data to filter; fs - sampling freq of data;
% LC - Low cut point; HC - High cut point; Order - specified filter order
% (or as close to order as possiable)
filter = designfilt('bandpassiir','FilterOrder',Order, ...
'HalfPowerFrequency1',LC,'HalfPowerFrequency2',HC, ...
% Optional check what the filter looks like with freqz()
% use filtfilt to apply the filter to the data and ensure zero-phase shift
% at the cost of doubling the filter order
filteredOutput = filtfilt(filter,data);
The only downside to the filter function is that it will try its best to match the required parameters, however if the response is not mathematically possiable it will either try and fit something as close to what you asked as possiable or throw an error.
@Star Strider also has several great examples on the topic if you want to try generating a butterworth from scratch too, its a great exercise in digital signal processing.
In terms of calculating the mean response I assume you are talking about comparing each window, this is a more probmatic topic (but not impossiable) as you are trying to reduce the signal vector into one value. I would avoid mean and instead focus on median as it is less prone to skewing. Please give me some more information as to what you want the output to look like from this and I will help.
Kind regards,
Julia Greeven
Julia Greeven on 20 Jul 2022
@Christopher McCausland Thankyou for your answer!
I found an article that showed exactly what I want to do for my internship: go from a recorded audio siginal of exhaling air to a lung function parameter. This article showed a relation between frequency response and the flow rate (m/s) of exhaling air using the equation (you can see this in the attached picture). Where Y is the flow rate (meter/second) and X is the mean of frequency responses in the range [100-1200] HZ.
That is why I want to use the mean frequency of responses..
After the steps I described before, I want to calculate the flow rate using the mean frequency responses resulting in a graph like the second attached picture. So I want the output to look like a flow-rate vs. time graph.
@Star Strider Thankyou for your tips, i will have a look on these options!
Star Strider
Star Strider on 20 Jul 2022
@Julia Greeven — Also consider pspectrum with the 'spectrogram' option. (I like it better than the spectrogram function because the units are more appropriate.)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!