Why do I get additional frequencies using standard audiowrite BitsPerSample values?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I want to write spectral data to wav file and read it again.
If I do some example with two sine waves, after writing+reading a wav file I get more frequencies in spectrum (aliasing/quantization noise?).
% generate sin-waves
wave = dsp.SineWave(Frequency=2.45e6,SampleRate=5e6);
wave.SamplesPerFrame = 1024;
wave2 = dsp.SineWave(Frequency=2.46e6,SampleRate=5e6);
wave2.SamplesPerFrame = 1024;
% save and visualize
scope1 = spectrumAnalyzer(SampleRate=wave.SampleRate,...
ViewType="spectrum-and-spectrogram",...
PlotAsTwoSidedSpectrum=false);
%data = [];
y = [];
for ii = 1:250
x = wave() + 0.5*wave2()+ 0.05*randn(1024,1);
scope1(x);
pause(0.01)
if scope1.isNewDataReady
y = [y,x];
%data = [data;getSpectrumData(scope)];
end
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1120030/image.png)
% set
Fs = 48000;
% write wav
audiowrite(wavefile,y,Fs,'BitsPerSample',16);
% visualize output orig
scope2 = spectrumAnalyzer(SampleRate=wave.SampleRate,...
ViewType="spectrum-and-spectrogram",...
PlotAsTwoSidedSpectrum=false);
for a = 1:width(y)
scope2(y(:,a))
pause(0.01)
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1120035/image.png)
% read wav
[b,Fs] = audioread('test.wav');
info = audioinfo('test.wav');
% visualize output wav
scope3 = spectrumAnalyzer(SampleRate=wave.SampleRate,...
ViewType="spectrum-and-spectrogram",...
PlotAsTwoSidedSpectrum=false);
for a = 1:width(b)
scope3(b(:,a))
pause(0.01)
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1120040/image.png)
when I change BitsPerSample parameter to 32/64:
% write wav
audiowrite(wavefile,y,Fs,'BitsPerSample',64);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1120045/image.png)
I get a right values/signal form.
Why it is happends? It is aliasing/quantization noise?
0 commentaires
Réponse acceptée
Mathieu NOE
le 8 Sep 2022
hello
if you export data to wav format , you have to make sure that the amplitude do not exceed +/- 1 otherwise the signal will be clipped and there you have a distorted signal (and that's why you get all the spurious frequencies)
seems to me this condition is not met as I can see the FFT peaks are well above 0 dB => clipping !
x = wave() + 0.5*wave2()+ 0.05*randn(1024,1);
% and normalize !!
x = x./max(abs(x));
3 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Import and Analysis dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!