AM modulation wav file tremolo effect problem
26 views (last 30 days)
Show older comments
% % tremolo1.m % M Script that uses a low frequency AM to provide a tremolo effect
filename='acoustic.wav';
% read the sample waveform [x,Fs,bits] = wavread(filename);
index = 1:length(x);
% using a sin wave at the moment, in practice is usually a % triangle wave or a square wave or a cross between the two
Fc = 5; alpha = 0.5;
trem=(1+ alpha*sin(2*pi*index*(Fc/Fs)))'; % sin(2pi*fa/fs)
y = trem.*x;
% write output wavwrite(y,Fs,bits,'out_tremolo1.wav');
i found this code here http://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/ . Does implementation works for you? I always got this error :
??? Error using ==> times Matrix dimensions must agree.
Error in ==> tremolo1 at 26 y = trem.*x;
how to make matrixs dimensions agree, otherwise how to make it to work? thanks in advance
1 Comment
filip novacek
on 27 Dec 2015
Hi, I also tried the script from the cs.cf.ac.uk - with 2 different wav files. The first worked perfectly, the second got me the same error as you described.
Answers (1)
Walter Roberson
on 1 Dec 2018
I do not have a problem with the file that is provided in the lecture notes. However, at the time it was written, the code assumed that the input file was mono, and for non-mono inputs, the code will fail in versions up to R2016a. As of R2016b, MATLAB added "implicit expansion" in a way that would permit the code to work.
The particular demonstration input file has 148799 samples. length() is 148799 and so index becomes 1 x 148799 and trem which uses input becomes 1 x 148799 but at the last moment is transposed to 148799 x 1. That is then .* the original input which is 148799 x 1 . And for the original input and any mono source that would work fine.
Suppose the input were stereo, 148799 x 2. Then length() is 148799, index is 1 x 148799, trem comes out as 148799 x 1, and that 148799 x 1 is .* the 148799 x 2. Up to R2016a the mismatch in number of columns would lead to a failure. Starting in R2016a it would be treated as if bsxfun(@times, trem, x) had been written, giving a 148799 x 2 output.
0 Comments
See Also
Categories
Find more on Pulsed Waveforms 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!