Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent high frequency (overtone) generation

Tags:

matlab

audio

enter image description here

Fs =44100;    
toneFreq1 = 8000; 
nSeconds = 25;  
f1 = sin(linspace(0, nSeconds*toneFreq1*2*pi, round(nSeconds*Fs)));
toneFreq2 = 8100; 
nSeconds = 25;  
f2 = sin(linspace(0, nSeconds*toneFreq2*2*pi, round(nSeconds*Fs)));
....

toneFreq80 = 15900; 
nSeconds = 25;  
f80 = sin(linspace(0, nSeconds*toneFreq80*2*pi, round(nSeconds*Fs)));
toneFreq81 = 16000; 
nSeconds = 25;  
f81 = sin(linspace(0, nSeconds*toneFreq81*2*pi, round(nSeconds*Fs)));


f_12345678910...= [f1+f2+f3+f4+f5+f6+f7+f8+f9+f10...f81]/81;


f_z=[f_12345678910...];
sound(f_z,Fs) 
wavwrite(f_z, Fs, 24, '8_16zKHz.wav');

I create a wave file (contain frequency from 8khz to 16khz by using Matlab). Then I play the wave and use the M50 microphone(6cm above the speaker) and a recorder to record the sound(from the speaker). Finally, I use a matlab program to convert the sound into a figure. In this figure, you can see a 8-16khz platform (what I want), but also can see some high frequency component(arrow). I don't know why the high frequency(>16khz) is generated. Is the high frequency signal being generated in the speaker, or is it noise generated by the microphone? Thank you.

like image 813
yang bin Avatar asked Jan 01 '26 09:01

yang bin


1 Answers

I think that your problem is with the use of linspace. On the surface, it seems like it should work, but there is something uncomfortable about how you're invoking it. I think that your method does not end up with quite the exactly-correct sample rate.

Also, I have little experience with Matlab's ability to export 24-bit WAVs in a format that is universally recognizable. I think that you should try 16-bits first, as that has been extremely reliable for me.

So, as something to try, I'd re-write your code in this way:

%define my parameters
toneFreqs = [8000:100:16000];
fs = 44100;
nSeconds = 25;

%create my data
t_sec = ([1:(nSeconds*fs)]-1)/fs; %here is the time for each sample
t_sec = t_sec(:);                 %make a column instead of a row
myWav = zeros(size(t_sec));       %pre-allocate the output
for Ifreq = 1:length(toneFreqs)   %loop over each frequency
    myWav = myWav + sin(2*pi*toneFreqs(Ifreq)*t_sec);
end

%save to WAV file
myWav = myWav./max(abs(myWav));    %normalize amplitude to 1.0
wavwrite(myWav,fs,16,'myWav.wav'); %save as 16 bit
like image 146
chipaudette Avatar answered Jan 04 '26 18:01

chipaudette



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!