Simple Question on Wavrecord Syntax & Correlation Syntax

1 回表示 (過去 30 日間)
JOJO
JOJO 2014 年 5 月 6 日
回答済み: Prateekshya 2024 年 10 月 23 日 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

回答 (1 件)

Prateekshya
Prateekshya 2024 年 10 月 23 日 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!

カテゴリ

Help Center および File ExchangeJust for fun についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by