# How can I generate audio wave files of harmonic series/partials for a specific frequency in Matlab

this is the only code I know, but it is for one specific frequency and not for its harmonic series, I am trying to get all the partials as individual files, eg. If I want to generate 40hz sine wavwrite file and its harmonic series which would be 40-80-120-140hz etc, about 551 individual audio sine wav files all at harmonic series frequency values in one go generated with an Matlab Code...

fs = 44100; % sampling frequency
nbits= 16;
file = 'output.wav'
d = 40; % duration
f = 60; % wave frequency
phi = pi/2; % phase shift - will produce cosinusoid for pi/2
t = linspace(1/fs, d, d*fs); % time vector
y = sin(2*pi*f*t + phi);
plot(t,y);
wavwrite( y, fs, nbits, file)


use a for loop to save each frequency into a different named wav file, use string manipulation command num2str() of Matlab. The following will help:

clc; clear all; close all;

Fs = 44100;         % Sampling frequency
F0 = 200;            % base frequency
t = [0:1/Fs:0.1];   % time index
k = 0;              % harmonic index

for fsine=F0:F0:Fs/2
x = sin(2*pi*fsine*t);
filename = ['wav' num2str(k)];
wavwrite(x, Fs,16, filename);
k = k+1;
end

• for some reason I am having difficulty to achieve this, can you paraphrase the code, I must be doing something wrong, thanks again Fat32... Jul 4 '15 at 20:30
• what is wrong? I tested and it works ? Jul 4 '15 at 20:52
• please don't take my inexperience for ignorance, I am probably skipping something, can you post the whole code that you have tried, I am using Octave to initialize the code, but unable not generate the files... Jul 4 '15 at 23:57
• ok see the complete matlab code. I tested it works. Jul 5 '15 at 0:27
• awsome, it worked perfectly, thank you for taking your time and helping out, really appreciate it Fat32. Jul 5 '15 at 16:35