How to concentate multiple audio signals in to one instance
Show older comments
Hello there,
I am instanciating several instances of a class called Signal and want to merge them into one instance. I know there's "cat" which helps, but I am struggling to find the correct syntax to make it happen for an array of instances of any given size:
signal1 = Signal(1,281.6,-pi/2,1,fa); % Amplitude, Frequence, Phase, Duration, Sample Rate
signal2 = Signal(1,200.6,Phase,1,fa); % second signal
signalvec = [signal1, signal2];
now I could go:
concattedsignal = cat(2,signalvec(1),signalvec(2);
but it doesn't help me if the array gets bigger. I tried:
for i = 1 : length(signalvec)
concattedsignal = cat(2,signalvec(i));
end
but this will always just give me the last instance of the array. What can I do to concentate every instance of an signal into one new signal?
Thanks alot!
Answers (1)
Voss
on 19 Dec 2021
The loop only gives you the last signal because you overwrite concattedsignal each time. You need to use concattedsignal in the loop and add on to it. Try something like this:
concattedsignal = [];
for i = 1 : length(signalvec)
concattedsignal = cat(2,concattedsignal,signalvec(i));
end
3 Comments
Jendrik Siebels
on 20 Dec 2021
Edited: Jendrik Siebels
on 20 Dec 2021
Voss
on 20 Dec 2021
OK. How about making signalvec a cell array:
signalvec = {signal1, signal2};
concattedsignal = [signalvec{:}];
Actually, regardless of that, I'm not sure what the purpose is here because you have this already:
signalvec = [signal1, signal2];
which does exactly the same thing as this:
signalvec = cat(2,signal1,signal2);
So if you are going to concatenate elements of an array in a loop using cat, but in order to do so, first you need to concatenate those same elements into an array using [], then what is the point?
Perhaps a mat-file of data with a few actual signals (I mean the variables signal1, signal2, etc.) would help to clarify.
Jendrik Siebels
on 21 Dec 2021
Categories
Find more on Lengths and Angles 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!