Basically I have a school project where I must create a new wave file from a given wave file. This new wave must be created in Matlab and the only difference is that a sine wave is to be mixed with the given wav file (not concatenated onto the end..). The sine wave is to be of 500hz.
My code so far is:
clear;
filename = 'C:\Documents and Settings\cmh0007\My Documents\rofl.wav';
[y, Fs, nbits, readinfo] = wavread(filename);
duration = numel(y) / Fs;
sinefs = 0:0.002:duration;
sinwave = 0.5*sin(2*pi*sinefs);
disp(size(y));
disp(size(sinwave));
newsignal = y + sinwave;
subplot(2,2,1), plot(y), title('Entire waveform');
subplot(2,2,3), plot(sinwave), title('sine waveform');
subplot(2,2,2), plot(newsignal), title('added waveform');
however, this code fails on creating the newsignal variable. The issue is that the two matrices are of different sizes due to the sampling rates differing between the two waves.
The output of the size calls are as follows:
797696 2
1 18089
Seeing as these files differ in sizes by a factor of ~44 I figured I could simply use the same sample from the sin wave 44 times over for each sample of the given wave file. However, because the difference is not exactly 44 I don’t know if this is even an option.
Does anyone have any suggestions on how to go about mixing these two files?
Try changing 0.002 to 1/Fs. That way you’ll have the same sampling rate. You should also choose only one of the stereo channels for y and do an appropriate transpose.
You might also consider changing the name sinefs to sinet or something as it represents the time parameter and not the sampling frequency.