Audio signal reading and manipulation

7 ビュー (過去 30 日間)
Lane Smith
Lane Smith 2021 年 11 月 18 日
コメント済み: Mathieu NOE 2021 年 11 月 19 日
I have an audio file that i read.
I then want to take the first 5 samples and store them as a seperate array.
eample
[x,f] = audioread('speech.wav');
y1 = [x1 x2 x3 x4]
y2 =[x2 x3 x4 x5]
y3= [x3 x2 x4 x5]
yn = [ ect ]
this showing that array y1 has sample 1,2,3,4
array y2 has sample 2,3,4,5
ect.
i then want to make a loop that will effect all arrays
take array y1 and make it change the sample
array z1 = [x3 x2 x4 x1]
array z2 = [x4 x3 x5 x2]
ect
then comple all of the z1 arrays into a new audio file and play is
NS = [z1 z2 z3 z4 z5 z6 z7 ect...]
then play it
sound(NS,f)
ANY IDEAS ON HOW TO MAKE IT

採用された回答

Mathieu NOE
Mathieu NOE 2021 年 11 月 19 日
hello
this is my code but there are a few open questions
  • why you say that we take 5 samples while y and z are vectors of 4 samples
  • I suppose it's a typo but I guess y3= [x3 x2 x4 x5] is wrong and should be y3= [x3 x4 x5 x6]
  • the resulting vector is about 4 times longer than the input vector but that's normal as each x vaues get's replicated multiple times in the output (z)
clc
clearvars
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% load signal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% data
[signal,Fs] = audioread('test_voice_mono.wav');
[samples,channels] = size(signal);
dt = 1/Fs;
time = (0:samples-1)*dt;
% extract four samples buffers with one sample shift
shift = 1; % nb of samples shift between successive buffers
buffer = 4; % nb of samples in one buffer
N = fix((samples-buffer)/shift +1);
z_all = [];
for ci=1:N
start_index = 1+(ci-1)*shift;
stop_index = min(start_index+ buffer-1,samples);
y =signal(start_index:stop_index,:); % 4 contiguous samples (y1 = [x1 x2 x3 x4])
% flip values so that it becomes : z1 = [x3 x2 x4 x1]
ind = [3;2;4;1];
z = y(ind);
% concatenate all z vectors
z_all = [z_all; z];
end
% audiowrite('out.wav',z_all,Fs);
sound(z_all,Fs)
  2 件のコメント
Lane Smith
Lane Smith 2021 年 11 月 19 日
Thank you so much. this helps alot!
Mathieu NOE
Mathieu NOE 2021 年 11 月 19 日
My pleasure !
do you mind accepting my answer ?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDigital Input and Output についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by