Separating an matrix into multiple matrices to generate audio.

I have an matrix which is 1*n and another which is n*1. The 1 contains a row of 0 and 1 and the other contains values. I want to everytime a 0 is in the first row n*1 add the 1*n value in a new matrix I called temp. When a 1 shows up in the first row my temp should be written to an audio file since it is an audio signal I am working with. I will attach my code with more of an explanation. I atteched an example of the data I am working with.
for i = 1:length(speech1) %Speech1 is the n*1 matrix which contains the audio data
while( quiet_row == 0 ) % quiet_row contains the 0 and 1 elements
counter = counter+1
temp(counter,1) = speech1(i,1) %when a 0 is found in quiet_row the corresponding value is speech 1 should be saved to the temp matrix.
if(quiet_row == 1) %whenever quiet_row finds a 1 after a bunch of 0's the temp array should be written to an audio file.
audiowrite("sound.flac",temp,Fs)
clear temp
end
end
end

2 Comments

Can you modify the question with sample example of two matrices,which may help to understand the question easiliy?
I attached the data that I am working for the two matrices.

Sign in to comment.

Answers (1)

load sspeech1.mat ;
load quiet_row.mat ;
temp = speech1(quiet_row) ; % this will get all values of speech1 for which quiet_row is 1
audiowrite("sound.flac",temp,Fs)

2 Comments

In the quiet_row there is values that range between 0 and 1, such as 00001111111110111101110000. Every time there is a zero or a group of zero in the quiet_row set save the corresponding group in the speech1 variable to a temp and then write the temp to an audiofile.

Sign in to comment.

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!