Generate dampening sine waves of various frequencies
2 views (last 30 days)
Show older comments
Naila Akbar
on 21 Mar 2019
Commented: Naila Akbar
on 22 Mar 2019
I'm trying to generate dampening sine waves of various frequencies and stitch them all together. Time interval is of 1 second for each frequency, amplitude 2, phase 0, decay constant 2.5 and the following frequencies in this order:
261, 293, 309, 348, 393, 419, 492, 522, 467, 413, 393, 353, 309, 293, 261
I'm trying to do this with following code;
for i = 1:15;
yi = (A*exp(-lemda*t)).*(sin(2*pi*f(i)*t+w));
% plot
subplot(16,1,i);
plot(t,yi);
title(['f = ' num2str(f(i))]);
% sound file
% sound(yi);
audiowrite(path,yi,fs);
[zi, fs] = audioread(path);
y = [y; zi];
sound(y);
end;
But it is giving me error;
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Error in Q5_a (line 28)
y = [y; zi];
Can someone help me out? I'm new to matlab, everything seems big here. Thanks in advance.
0 Comments
Accepted Answer
Image Analyst
on 21 Mar 2019
This works for the first two sounds, but you can't have 3, quad, or more sound channels so it won't work for the 3 through 15 loop:
t = linspace(0, 1, 3000);
A = 2;
lambda = 2.5;
f = [261, 293, 309, 348, 393, 419, 492, 522, 467, 413, 393, 353, 309, 293, 261];
w = 0;
for i = 1:15
yi = (A*exp(-lambda*t)) .* (sin(2*pi*f(i)*t +w));
% plot
subplot(4, 4, i);
plot(t,yi, 'b-');
title(['f = ' num2str(f(i))]);
grid on;
sound(yi);
fileName = 'deleteme.wav';
audiowrite(fileName,yi, f(i));
[zi, fs] = audioread(fileName);
if i == 1
y = yi
else
y = [y; zi'];
end
sound(y);
end
2 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!