Why do I get additional frequencies using standard audiowrite BitsPerSample values?
2 次查看(过去 30 天)
显示 更早的评论
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
% 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
% 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
when I change BitsPerSample parameter to 32/64:
% write wav
audiowrite(wavefile,y,Fs,'BitsPerSample',64);
I get a right values/signal form.
Why it is happends? It is aliasing/quantization noise?
0 个评论
采纳的回答
Mathieu NOE
2022-9-8
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!