SignalLab2/speech_analysis.asv

51 lines
1.5 KiB
Plaintext

function speech_analysis()
% Construct the full file path
filepath = './sound/modulator22.wav';
% Read the audio file
[y, Fs] = audioread(filepath);
disp(['Successfully read the audio file: ', filepath]);
disp(['Sampling frequency (Fs): ', num2str(Fs), ' Hz']);
disp(['Number of samples: ', num2str(length(y))]);
% Construct the output filename correctly
%[~, name, ~] = fileparts(filepath); % Get the filename without extension
%outputFilename = fullfile('.', ['processed_', name, '.wav']); % Create the new filename
% Write the audio to a new file with double the sampling rate
%audiowrite(outputFilename, y, Fs*2);
%disp(['Successfully wrote the processed audio to: ', outputFilename, ' with double the sampling rate.']);
% Play the original audio (using the audio data 'y' and its original sampling rate 'Fs')
sound(y, Fs); % Play the original sound
sound(y, Fs*2);
disp('Playing the audio with double the sampling rate.');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Plot
t = (0:length(y)-1) / Fs; % Time in seconds
figure;
plot(t, y);
xlabel('Time (seconds)');
ylabel('Amplitude');
title(['Temporal Variation of ', filepath]);
grid on;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Frequency Spectrum
%FFT
frequencySpectrum(y,Fs, 0);
%DFT
frequencySpectrum(y,Fs, 1);
%Modify the padding to make the change.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
spectrogram(y, Fs, step_size, window_size)
end