how to zero pad a vector to have the same amount of data as a vector with more data?
29 views (last 30 days)
Show older comments
I have read multiple other threads with questions similar to this, however none of these were able to work in my case.
quick description: i have two audio signals. the "verb" signal is longer than the "in" signal. I want to change the "in" signal to have the same amount of data (i.e, the length of verb = length of in), using zero padding.
Can someone please walk me through how to achieve this? I have tried many things. Here is the code that reads the inputs as well as my best attempt to zero pad the "in" signal.
thank you for your help
%%% goal: to have the length of 'in' equal the length of 'verb'
%%% define inputs
[in, fs] = audioread('smash_hit.wav'); % input signal defined
in = in(:,1); % converts signal to mono, if needed
[verb, ~] = audioread('warehouse.wav'); % reverb response signal defined
verb = verb(:,1); % converts signal to mono, if needed
in_padded = [in, zeros(1, length(verb))];
0 Comments
Answers (3)
Les Beckham
on 13 Nov 2023
Try this:
%%% goal: to have the length of 'in' equal the length of 'verb'
%%% define inputs
[in, fs] = audioread('smash_hit.wav'); % input signal defined
in = in(:,1); % converts signal to mono, if needed
[verb, ~] = audioread('warehouse.wav'); % reverb response signal defined
verb = verb(:,1); % converts signal to mono, if needed
% in_padded = [in, zeros(1, length(verb))];
in_padded = [in, zeros(1, length(verb) - length(in))]; % <<< corrected this line
See Also
Categories
Find more on Measurements and Spatial Audio 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!