How to continuously extend a vector in a loop

10 ビュー (過去 30 日間)
Allan Prince
Allan Prince 2021 年 1 月 27 日
コメント済み: Allan Prince 2021 年 1 月 27 日
I have a function which is supposed to generate a series of audible tones of L duration and Fs sample frequency. I want to be able to play back the string of tones after all of the samples for each tone are created.
I have created a loop that generates L*Fs samples of each tone, one tone at a time in a loop. Each time through the loop, I generate L*Fs samples stored in a vector for each tone. As each chunk of L*Fs samples is created, I need to extend the length of the vector so that when all tones have been created, I will have one long vector that I can playback using sound();
I am having difficulty continuously extending the vector each time through the loop. I've searched for simular examples but have not found any that seem to enlighten me on how to make this work. I would be grateful if someone could suggest a way to make this work.
%Generate tones
Fs = 48000; %sample frequency
L = 0.5; %duration
n = 0:1/Fs:L; %sample
index = 1:1:length(n)-1;
% tone frequencies (Hz)
notes = [440 495 550 587 660 733 825];
tones=[];
for ii = 1:1:length(notes)
[n1,y] = generate_sigs(L,notes(ii),Fs)
% how to continuously extend vector y each loop ????
tones = [tones y(index,1):y(index):y(index,2)];
end
sound(tones, Fs);
% ***text of the generate sigs function***
% function [n,x] = generate_sigs(L,f,Fs)
% n = [0:round(L*Fs-1)]/Fs;
% x = sin(2*pi*f*n); %create n samples at specified
% %frequency and duration L

採用された回答

David Hill
David Hill 2021 年 1 月 27 日
for ii = 1:1:length(notes)
[n1,y] = generate_sigs(L,notes(ii),Fs)
tones = [tones,y];
end
  1 件のコメント
Allan Prince
Allan Prince 2021 年 1 月 27 日
Thank you so much.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by