三天不学习,就不知道如何用声卡了。
1 MATLAB-- Audio record for specified time
做了一个简单的demo,仅采集1次的声音,并做FFT 分析
记得存为.m文件,不要.mlx文件,因为你不知道何时开始。
% record 只做做了 一次采集,如何做连续采集,大家尝试
% 连续采集,记得设置退出条件,比如捕捉ecs按键
timeLength=2; % 采样时长,单位秒
Fs=44100;%Hz
samples=timeLength*Fs; % 默认采样率44100,计算采样点数
nBits=16;%bit
nChannels=2
ID=1;% 0 or 1 or -1
recObj = audiorecorder(Fs,nBits,nChannels,ID);
disp('Start speaking.') %% start recording.............
recordblocking(recObj, timeLength);
disp('End of Recording.'); % end
% Store data in double-precision array.
myRecording = getaudiodata(recObj);
% Plot the waveform.
%plot(myRecording);
% Play back the recording.
play(recObj); % play your recording
figure %('Name','实时频谱','MenuBar'...
% ,'none','ToolBar','none','NumberTitle','off');
audioIn=myRecording;%data
% xdata=(1:1:samples/2)/timeLength;
% raw audio data
xdata=(1:1:samples)*1/Fs;% 采样时间间隔数据
subplot(1,2,1),plot(xdata,audioIn)
xlabel('Time/s');ylabel('Amplitude/mv');
title('Time domain')
% FFT
ydata_fft=fft(audioIn); % 傅里叶变换
ydata_abs=2*abs(ydata_fft(1:samples/2))';% 取绝对值
f = Fs*(0:(samples/2)-1)/samples;% 频率轴
subplot(1,2,2) %子图2
plot(f,ydata_abs)
xlabel('Frequency/Hz');ylabel('Amplitude/mv');
title('Frequnecy domain')
set(gca,'xscale','log') % log in x
用matlab获得的声音很怪。labview采集的效果就非常好!
需要设置channel为2,这样录制的声音就正常了。
记得NVH课程还是这分贝的分析方法,天哪,我竟然忘了,对去BWM高级工程师的教导了。
y轴用对数处理,效果一般。
我女儿的频谱
2
2 Continous Audio record
Audio Systems Toolbox .需要下载这个模块,可惜 我没有这个权限。
看来matlab对声卡操作还是设置权限太多。
3 LabVIEW
对硬件的操作是lv的强项。
直接对例子continous audio acquire修改,增加fft。
声卡用22.05kHz
声卡的几个硬件操作,在while进行数据处理即可。