a m file to frame voice signals in MatLab
时间: 2024-05-03 13:21:59 浏览: 64
matlab 语音信号处理 enframe.m
5星 · 资源好评率100%
Here is an example m file to frame voice signals in MatLab:
```matlab
% Load voice signal
[x, Fs] = audioread('voice.wav');
% Define frame size and overlap
frame_size = 0.02; % 20ms
overlap = 0.5; % 50%
% Calculate frame shift and number of frames
frame_shift = frame_size * Fs * (1 - overlap);
num_frames = floor((length(x) - frame_size * Fs) / frame_shift) + 1;
% Initialize frame matrix
frames = zeros(frame_size * Fs, num_frames);
% Create frames
for i = 1:num_frames
start_index = round((i - 1) * frame_shift) + 1;
end_index = start_index + frame_size * Fs - 1;
frames(:, i) = x(start_index:end_index);
end
% Plot original signal and frames
t = (0:length(x)-1) / Fs;
figure;
subplot(2, 1, 1);
plot(t, x);
xlabel('Time (s)');
ylabel('Amplitude');
title('Original Signal');
subplot(2, 1, 2);
imagesc(frames);
xlabel('Frame');
ylabel('Sample');
title('Frames');
```
This code loads a voice signal from a file called "voice.wav", defines a frame size of 20ms with a 50% overlap, calculates the frame shift and number of frames, initializes a frame matrix, and creates the frames based on the frame size and overlap. Finally, the original signal and frames are plotted using MatLab's "plot" and "imagesc" functions.
阅读全文