clc;
clear;
close all;
warning off;
addpath(genpath(pwd));
%****************************************************************************
%更多关于matlab和fpga的搜索“fpga和matlab”的CSDN博客:
%matlab/FPGA项目开发合作
%https://blog.csdn.net/ccsss22?type=blog
%****************************************************************************
envelope_insensitivity = 100;
silent_amplitude_threshold = 0.01;
%
filename = 'Test_DTMF.wav';
info = audioinfo(filename);
[y, Fs] = audioread(filename);
row_freq = [697; 770; 852; 941];
column_freq = [1209, 1336, 1477, 1633];
freqs = row_freq + column_freq;
chars = {{'1', '2', '3', 'A'}; {'4', '5', '6', 'B'}; ...
{'7', '8', '9', 'C'}; {'*', '0', '#', 'D'}};
num_strokes = 0;
prev_size = 0;
while (~(prev_size == length(y)))
prev_size = length(y);
envelope = imdilate(abs(y), true(envelope_insensitivity, 1));
if (num_strokes == 0)
figure;
plot(y); xlabel('Samples'); ylabel('Amplitude');
title('Signal');
hold on;
plot(envelope, 'r-', 'LineWidth', 2);
plot(-envelope, 'r-', 'LineWidth', 2);
legend('Data', 'Envelope');
end
quiet_parts = envelope < silent_amplitude_threshold;
stroke_num_samples = find(quiet_parts == 1, 1, 'first') - 1;
quiet_parts_cut = quiet_parts; quiet_parts_cut(1:stroke_num_samples) = [];
quiet_num_samples = find(quiet_parts_cut == 0, 1, 'first') - 1;
stroke = y(1:stroke_num_samples, :);
% the two frequencies that produce maximum power spectral density (PSD)
% are almost equal to the dual frequencies
[Pxx, F] = periodogram(stroke, rectwin(length(stroke)), length(stroke), Fs);
[~, index] = max(Pxx);
freq1 = F(index);
Pxx(index) = []; [~, index] = max(Pxx);
freq2 = F(index);
y(1:stroke_num_samples + quiet_num_samples, :) = [];
num_strokes = num_strokes + 1;
freq_estimated = round(freq1 + freq2); %estimated dual tone frequency
distance_squared = (freqs - freq_estimated) .^ 2; %distance of estimated frequency from actual dual tone frequencies
[row, column] = find(distance_squared == min(min(distance_squared))); %nearest frequency to the estimation is selected
fprintf('%c ', chars{row}{column});
end
fprintf('\nNumber of key strokes: %d\n', num_strokes);
fpga和matlab
- 粉丝: 17w+
- 资源: 2636
最新资源
- Power Quality Disturbance:基于MATLAB Simulink的各种电能质量扰动仿真模型,包括配电线路故障、感应电机启动、变压器励磁、单相 三相非线性负载等模型,可用于模拟各种
- 教务管理系统(jsp+servlet+mysql)130225.rar
- 教务管理系统(jsp+servlet+mysql).rar
- 酒店订单管理系统(Jsp+servlet+mysql)130224.rar
- 酒店订单管理系统(Jsp+servlet+mysql).rar
- 乐趣大型购物系统 v1.1(jsp+servlet+mysql).rar
- 聊天系统(java+applet)130227.rar
- 龙门物流管理系统(Ext+SSH).rar
- 乐趣大型购物系统 v1.1(jsp+servlet+mysql)130223.rar
- 基于动态窗口算法的AGV仿真避障 可设置起点目标点,设置地图,设置移动障碍物起始点目标点,未知静态障碍物 动态窗口方法(DynamicWindowApproach) 是一种可以实现实时避障的局部规划算
- 内容管理系统(hibernate3+struts2+spring2).rar
- 内容管理系统(hibernate3+struts2+spring2)130224.rar
- 企业费用管理系统(SSH+Oracle).rar
- 企业费用管理系统(SSH+Oracle)130222.rar
- 企业级新闻系统(SSH+MYSQL).rar
- 通用的在线考试系统(jsp+struts+hibernate+oracle).rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈