I am a newbie to MATLAB and have a question.
In the MATLAB wavread function:
wavread(filename, [N1 N2]);
Can anyone please help me understand why the N1 & N2indices are usually chosen as 24120 & 25439 respectively for slicing the wav file?
Thanks in advance!
If you consult the wavread documentation, it's actually quite clear on what N1 and N2 are. N1 represents the beginning sample and N2 represents the ending sample, and what is returned are your audio samples between N1 and N2 for each channel.
As such, supposing your audio sampling rate was 44100 Hz. Following your post, if you did:
wavread(filename, [24120 25439]) ,
you are returning audio samples for each channel that range between the 0.5469 (24120/44100) second to 0.5768 (25439/44100) second mark in your audio file. This would return an overall matrix of 1320 x N where N is the number of audio channels in your file. The overall length of this audio sample file would be roughly 0.03 seconds.
BTW, these indices are not usually chosen to be this way. These indices are highly dependent on the length of your audio signal, as well as what you want to isolate from the audio signal itself. These indices are used to mainly to disregard irrelevant audio signal data and to only give you those audio samples where you know there is some meaningful output.
My belief is that the audio files that you are processing have very meaningful output between these time frames, which is why those indices are used quite often. As I said, this all depends on which audio files you are processing.
Related
I'm using dsp.Audiorecord to get real-time microphone input. The sound input is a series of sinusoids with different frequencies ranging from 500 to 2000Hz. Each one sounds for a second.
I'd like to know in real-time, what's the frequency of the current sin and also make the difference between two sins with same frequency going one after the other. This is why I use dsp.Audiorecord.
This is what my code looks like now:
Microphone = dsp.AudioRecorder;
tic;
while(toc<30)
audio = step(Microphone);
[x, indexMax] = max(abs(fft(audio(:,1)-mean(audio(:,1)))));
indexMax
end
All the indexMax shows are numbers ranging from around 25 to 40. There's clearly an operation left out in order to retrieve the original frequency in [500;2000].
I've tried also to apply dsp.FFT() directly to audio but it tells me:
Error using dsp.FFT/pvParse
Invalid property/value pair arguments.
If there's any other way to perform real-time FFT on the dsp.Audiorecorder I'd really like to know. Or just if you see a way to to complete what I've done here it would be great also.
To approximately estimate what frequency goes with what index, you need to know the sample rate (Fs) of the data sent to the FFT, and the length (N) of the FFT:
f ~= index * Fs / N
That's the operation you've left out.
I want to take some audio signal, most likely in stereo, and apply some transfer function to it with the convolution function. I have seen examples here on how to apply transfer functions after obtaining a tfest from two signals, but the tfest data is the same size as the original audio.
I have attempted to navigate MATLAB and become familiar with its interface and syntax by watching the lone Lynda video on MATLAB basics. I have prior programming experience with C# and feel comfortable in Visual Studio, but MATLAB is new to me.
The transfer function is previously obtained, and currently in Excel. The data is in octave bands (63 Hz, 125 Hz, 250 Hz, ... , 8kHz), and will be extrapolated to the spectrum of the input signal (20 Hz - 20 kHz). This will take the form of: (f1, -x1), (f2, -x2), ... ,(fn, -xn), with each data point in the sampled audio having a match with the transfer function.
The function is constant over time. Essentially, I am simulating what something would sound like after passing through a partition.
My thought process tells me this will follow: input audio, transform to frequency domain, apply transfer function, transform back into time domain, and write as WAV.
How would I go about doing this? I understand I did not provide any code, and for this I am sorry. Any resources on the topic are most appreciated. I do not expect a turn-key solution, just some guidance so I can find my way to a correct method.
I would do like this:
function [ out_wav_file ] = TransformSignal( in_waw_file )
% Read input signal
[in_sgn, FS, N] = wavread(in_waw_file);
% If audio file is multiple channel, selec one channel
in_chn = in_sgn(:, 1);
% Transform to frequency domain
% You could use a smaller FFT length but it would cost you quality when
% converting back
fft_in_sgn = abs(fft(in_sgn, length(in_sgn)));
fft_out_sgn = SomeFunction(fft_in_sgn);
out_sgn = ifft(fft_out_sgn);
wavwrite(out_sgn, FS, N, out_wav_file);
end
Hope it helps!
How can I display coefficients of audio signal when plotting an audio file in Matlab?
I am fairly new to Matlab so this could be a stupid question. I have searched for similar things but haven't come across anything similar.
First of all you need to read the sound. Considering that you have it stored in wav format, you can use for example [X, fs] = wavread('sound_name.wav');. fs would be your sample rate and X would be matrix of samples [number of samples]x[number of channels]. By default it will read sound in doubles, but it can be changed. See help wavread for details.
Then you can display raw waveform by simply ploting it: plot(X);. Or if you need spectrum of the sound, you can window signal and then apply FFT. In this case voicebox toolbox would be useful: F = enframe(X, hamming(win_len), fix(win_len/2)); sp = rfft(F.'); imagesc(10*log(abs(sp)));
There are also lots of handy functions in Matlab signal processing toolbox.
I am reading a .wav file in Matlab. Then I play the read file with a specified sampling frequency 44100Hz. But when I try to play a file sampled at low sampling frequency, it gets played as if I am playing it in fast forward mod and thats because the sampling frequency at which I am playing is higher than at which the file is sampled.
So my question is How can I find the sampling frequency of a file I read using wavread() in Matlab. I tried to convert the read signal in frequency spectrum and then pass the magnitude of the fft() signal but it didn't work.
Any suggestions?
Observe that wavread can return sampling frequency Fs as follows:
[y, Fs] = wavread(filename)
First off you can find the sample frequency by using this function:
def read_samplepoints(file_name):
sampFreq, snd1 = wavfile.read(file_name)
samp_points = len(snd1)
data_type = snd1.dtype
return samp_points, data_type, sampFreq
Execute in terminal by using 'folder_name'.'class_name'.read_samplepoints(file_name). The last number in the returned sequence will be the sample Frequency.
To enhance the bass of your song you need to use a low band filter to only capture your lower frequencies and keep your higher ones. However, this will chance all the frequencies in your file, which you may not want. Another way is to take your file into audacity (or a similar program) and go to the effects section and adjust the bass and treble levels (similar to the Equalizer on iTunes). Those are two options and there may be a few more but try those to begin with and see where they lead you.
I have a sound file, which I'll call sndfile.wav.
So far I have determined the number of samples, sampling rating, and the length in seconds.
[f,Fs] = wavread('mike.wav');
N = length(f);
slength = N/Fs;
Given that f is the vector containing the samples from the sound file, Fs is the sampling rate, N is the number of samples, and slength is the length of the sound file in seconds, how can I plot the sound signal with respect to time in seconds.
Make a time vector and then plot it versus f.
t = linspace(0, N/Fs, N)
plot(t, f)
moorepants answer is good for plotting the signal. If you want to do more to the signal after viewing take a look at the "Simple Audio Editor" available at file exchange. http://www.mathworks.com/matlabcentral/fileexchange/19873-simple-audio-editor
It can read an audio file directly and display it. You can also play the signal and do cut,copy and paste with the audio signal.