Clear Filters
Clear Filters

How can I add two .wav files having different sampling frequency and lengths??

1 view (last 30 days)
Here is the code
%Sid --on the floor
clc
clear all
close all
[y,Fs,nb]=wavread('C:\Users\Sid\Desktop\flute.wav');
[z,Fs1,nb1]=wavread('C:\Users\Sid\Desktop\sid2.wav');
audioplayer(y, Fs,nb)
audioplayer(z, Fs1,nb1)
S = [y; z];
sound(S,Fs1,nb);
%Gives an error
??? Error using ==> vertcat
CAT arguments dimensions are not consistent.
Error in ==> difa2 at 13
S = [y; z];

Answers (1)

Walter Roberson
Walter Roberson on 6 May 2015
Your code does not attempt to add the files. Your code attempts to use the different files as different channels. If the original are stereo you would be attempting to construct 4 channels of output.
If you want to add different files, you must resample one of them to be on the same time-base as the other, and you would then pad the shorter of the results to be the same as the longer. Normally you would resample the one with the lower frequency. See resample() and the factor you would use would be the ratio of the frequencies.

Community Treasure Hunt

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

Start Hunting!