Introduction: Because beacon smart car chase competition rules modified to sound standard, need to learn to do the relevant chirp signal processing, audio processing to make way here for a summary of this article somewhat cumbersome, a quick start to see the end of the text can be directly attached Code
The main function
1. The audio read -function [y, Fs] = audioread (filename, range, datatype)
audioread audio format can be read with a wave, flac, MP3, MPEG-4, OGG
% File Format BitsPerSample Data Type of Y Data Range of Y
% ----------------------------------------------------------------------
% WAVE (.wav) 8 uint8 0 <= Y <= 255
% 16 int16 -32768 <= Y <= 32767
% 24 int32 -2^32 <= Y <= 2^32-1
% 32 int32 -2^32 <= Y <= 2^32-1
% 32 single -1.0 <= Y <= +1.0
% ----------------------------------------------------------------------
% FLAC (.flac) 8 uint8 0 <= Y <= 255
% 16 int16 -32768 <= Y <= 32767
% 24 int32 -2^32 <= Y <= 2^32-1
% ----------------------------------------------------------------------
% MP3 (.mp3) N/A single -1.0 <= Y <= +1.0
% MPEG-4(.m4a,.mp4)
% OGG (.ogg)
% ----------------------------------------------------------------------
There are two output parameters and the FS Y, Y is a m * n matrix, wherein m is an audio sampling points, n-number of audio channels, FS is the sampling frequency
% [Y, FS]=AUDIOREAD(FILENAME, DATATYPE) specifies the data type format of
% Y used to represent samples read from the file.
% If DATATYPE='double', Y contains double-precision normalized samples.
% If DATATYPE='native', Y contains samples in the native data type
% found in the file. Interpretation of DATATYPE is case-insensitive and
% partial matching is supported.
% If omitted, DATATYPE='double'.
2. Play Audio -function sound (y, fs, bits)
sound (Y, FS);% for Y and FS playback audio parameters corresponding to the
bits of sample bits
3. Fast Fourier Transform -fft (X)
The signal from the time domain to the frequency domain, meaning the FFT function of MATLAB
Item code
file = 'chirp_鹰短尾_ 啁啾05.mp3'; %读取文件
%音频播放
[Y,FS] = audioread(file);
[m,n] = size(Y);
disp(m); %输出采样频率
disp(n); %输出音频通道数
disp(FS); %输出采样频率
disp(m/FS); %输出素材音频时长
sound(Y,FS); %播放对应Y和FS对应参数的音频
s1 = Y(:,1);
sound(s1,FS); %只播放其中一个通道的音频
%%音频绘制
timeArray = (0:m-1)/FS;
timeArray1 =timeArray*1000; %放大到毫秒级
figure;plot(timeArray1,s1,'k');title('Amplitude Curve');xlabel('Time(ms)');ylabel('Amplitude');
%%绘制频率信息
s1_L = length(s1);
p = fft(s1); %计算傅里叶变换
nUniquePts = ceil((s1_L+1)/2);
p1 = p(1:nUniquePts); %选择前半部,因为后半部是前半部的一个镜像
p2 = abs(p1); %取绝对值,即幅度
p3 = p2/s1_L; %使用点数按比例缩放,这样幅度和信号长度或者它自身的频率无关
p4 = p3.^2; %平方得到功率
if rem(s1_L,2) %奇数,nfft需要排除奈奎斯特点
p4(2:end) = p4(2:end)*2;
else
p4(2:end-1) = p4(2:end-1)*2;
end
freqArray=(0:nUniquePts-1)*(sampFreq/n);%创建频率数组
figure;plot(freqArray/1000,10*log10(p4),'k');
title('Power-Frequency Curve');
xlabel('Frequency(kHz)');
ylabel('Power(dB)');
The results of the test run