I need to isolate certain values of a matrix based on whether one of the values fall in a certain range
    4 views (last 30 days)
  
       Show older comments
    
I am writing a word recognition program that takes an array from 'audioread' and applies a few methods to it to get a frequency spectrum. This spectrum is saved into a cell aray with each cell containing the frequency peaks for a quater of the word at a time.
So for each word it returns a 4x1 cell array. Each of these cells need to be further subdivided to frequency bands
An example of one such a cell follows
% ans = 2×2
% 24.9843526628176                        32
% 5.44020124026728                        62
The first column indicates amplitude and the second indicates the index. I need to split the matrix into divisions that are 30 wide each. So all 2nd column values from 0 to 30 must be together and all from 30 to 60 etc. All the way up to 300.
The following code exert is the function that I wrote for this application for context to the question. 
It is probably flawed and unoptimal so if there are glaring issues in it feel free to include commentary in any answers.
Thank you 
function FINAL_OUTPUT = FFT_Output(OG_Audio, Filter_count, Min_peak_distance)
% Setup
Sectional_Length = round(length(OG_Audio)/4);
BM_Filtered_Signal = (blackman(length(OG_Audio))).*OG_Audio;
First_Filter_Parameter = ((1/(Sectional_Length/100))*ones(1,(Sectional_Length/100)));
Word_section = cell(4,1);
FFT_Word = cell(4,1);
FINAL_OUTPUT = cell(4,1);
for i = 1:4
    % Word sections
    Word_section{i} = BM_Filtered_Signal(((Sectional_Length*(i-1))+1):(Sectional_Length*i));            
    % Moving average filter
    j=0;
    while(j<=Filter_count)
        Word_section{i} = filter(First_Filter_Parameter, 1, Word_section{i});
        j=j+1;
    end
    % FAST FOURIER TRANSFORM
    FFT_Word{i} = abs(fft(Word_section{i},length(Word_section{i})));
    FFT_Word{i} = FFT_Word{i}(1:(round(length(FFT_Word{i})/(2))));
    % Peak detection
    [M,I] = findpeaks(FFT_Word{i}, "MinPeakDistance",Min_peak_distance, "MinPeakHeight",(0.1*max(FFT_Word{i})));        % Identifying peak frequencies for comparisons 
    FINAL_OUTPUT{i} = [M,I];   
end
end
0 Comments
Accepted Answer
  Dyuman Joshi
      
      
 on 19 Oct 2023
        
      Edited: Dyuman Joshi
      
      
 on 19 Oct 2023
  
      Here's a general approach - Discretize the data according to the groups and then split then into cells.
bins = 0:30:300;
idx = discretize(data, bins)
out = splitapply(@(x) {x}, data, idx)
More Answers (0)
See Also
Categories
				Find more on Multirate Signal Processing in Help Center and File Exchange
			
	Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
