Why do I get additional frequencies using standard audiowrite BitsPerSample values?
조회 수: 3 (최근 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!