Simple Question on Wavrecord Syntax & Correlation Syntax

3 visualizaciones (últimos 30 días)
JOJO
JOJO el 6 de Mayo de 2014
Respondida: Prateekshya el 23 de Oct. de 2024 a las 3:15
Hello, I have read this Matlab link on wavrecord http://www.mathworks.co.uk/help/matlab/ref/wavrecord.html I want to ask what is the y axis, they say it is n samples of audio signal but
1. what is the unit, it is voltage, power density?
2. And the unit for x axis for the graph when I put plot(y); after the first command? It is Hz? "y = wavrecord(n,Fs) records n samples of an audio signal, sampled at a rate of Fs Hz (samples per second). "
3. How does the correlation command in Matlab works, it uses the formula shown in the link below R(i,j)=...? http://www.mathworks.co.uk/help/matlab/ref/corrcoef.html

Respuestas (1)

Prateekshya
Prateekshya el 23 de Oct. de 2024 a las 3:15
Hello Jojo,
The wavrecord function in MATLAB (note that it has been deprecated and replaced by audiorecorder in newer versions) records audio data and returns it as an array. Here is how to interpret the axes:
Y-Axis (Audio Signal Values):
  • Unit: The values on the y-axis represent the amplitude of the audio signal. These are typically normalized floating-point numbers ranging from -1 to 1, representing the relative amplitude of the audio waveform.
  • Interpretation: These values are dimensionless and do not directly correspond to physical units like voltage or power density. They represent the sampled audio waveform's amplitude.
X-Axis (Sample Index):
  • Unit: The x-axis represents the sample index, not frequency. When you use plot(y), you are plotting the amplitude of each audio sample against its index in the array.
  • Interpretation: The x-axis values are simply the indices of the samples, ranging from 1 to n, where n is the number of samples recorded. To convert these indices to time, you can divide by the sampling frequency Fs, resulting in units of seconds.
Example Code for Plotting:
% Parameters
Fs = 44100; % Sampling frequency in Hz
nBits = 16; % Bit depth
nChannels = 1; % Number of channels (1 for mono, 2 for stereo)
duration = 5; % Duration of recording in seconds
% Create an audiorecorder object
recObj = audiorecorder(Fs, nBits, nChannels);
% Record audio for the specified duration
disp('Start speaking.');
recordblocking(recObj, duration);
disp('End of recording.');
% Retrieve audio data
y = getaudiodata(recObj);
% Plot the audio signal
t = (0:length(y)-1) / Fs; % Time vector in seconds
plot(t, y);
xlabel('Time (seconds)');
ylabel('Amplitude');
title('Audio Signal');
This will give the following as the output:
Correlation in MATLAB:
The corrcoef function in MATLAB computes the correlation coefficients between two or more variables. The correlation coefficient is a measure of the linear relationship between variables.
Formula: The correlation coefficient between two variables X and Y is calculated as:
where:
  • is the covariance between X and Y.
  • and are the standard deviations of X and Y.
Usage: R = corrcoef(X) returns a matrix R of correlation coefficients, where R(i,j) is the correlation coefficient between the i-th and j-th variables.
Example Code for Correlation:
% Example data
X = randn(100, 1); % Random data for variable X
Y = 2 * X + randn(100, 1); % Linearly related data for variable Y
% Compute correlation coefficient
R = corrcoef(X, Y);
% Display the result
disp('Correlation Coefficient Matrix:');
disp(R);
The result of this code is:
Correlation Coefficient Matrix:
1.0000 0.9287
0.9287 1.0000
You can modify the code according to your requirements.
I hope this helps!

Categorías

Más información sobre Just for fun en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by