传感器测试--声音采集与FFT 分析

三天不学习,就不知道如何用声卡了。

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对声卡操作还是设置权限太多。

  如果有工具包,进官网看例程  Acquire Continuous Audio Data- MATLAB & Simulinkhttps://www.mathworks.com/help/daq/getting-started-acquiring-data-using-audio-in-session.html

3 LabVIEW

对硬件的操作是lv的强项。

直接对例子continous audio acquire修改,增加fft。

 声卡用22.05kHz

声卡的几个硬件操作,在while进行数据处理即可。

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

做一个码农都是奢望

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值