I need to isolate certain values of a matrix based on whether

Technical Source
2 min readMar 18, 2024

--

March 18, 2024

I need to isolate certain values of a matrix based on whether one of the values fall in a certain range

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.

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

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

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)

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

No responses yet