Generate dampening sine waves of various frequencies

2 views (last 30 days)
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.

Accepted Answer

Image Analyst
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
Naila Akbar
Naila Akbar on 22 Mar 2019
So how can I achieve my requirement of loop through 15 values? or I can't?
Naila Akbar
Naila Akbar on 22 Mar 2019
my problem solved by changing this
y = [y; zi'];
to this
y = [y, zi'];

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!