I have read an audio signal .wav with a Sampling frequency fs = 44100
[y Fs]= audioread('as6.mp3');
[N,P]=size(y);
ts=1/Fs;
tmax=(N-1)*ts;
t=0:ts:tmax;
I am interested to study the frequencies under 8000 of this signal with the function downsampling ()
so, How can I do it

5 commentaires

Paul
Paul le 21 Juin 2022
Is the goal to really downsample the signal, i.e., change the sampling frequency from 44100 Hz to 8000 Hz?
Or is the goal to anlayze the signal as provided but only focus on the frequency range 0 - 8000 Hz?
Abdelhakim Souidi
Abdelhakim Souidi le 22 Juin 2022
the goal is to anlayze the signal as provided but only focus on the frequency range 0 - 8000 Hz?
Paul
Paul le 22 Juin 2022
Then no need to downsample or decimate? Just do whatever analysis needs to be done and focus on the plot (or whatever is generated) in the range from 0-8000 Hz.
Abdelhakim Souidi
Abdelhakim Souidi le 22 Juin 2022
Paul if you can do me a favor, I want to see how to apply the Downsampling function in this case
Responding to is resample and downsample function are the same in this comment
Basic concepts:
downsample - In the basic case, equivalent to indexing with an integer step
x = rand(1,20);
N = 3;
isequal(x(1:N:end),downsample(x,N))
ans = logical
1
decimate - Applies a low pass filter to x to avoid aliasing before downsampling
upsample - Inserts zeros between elements of the input array
interp - Applies a filter after upsampling x
resample - When applied to uniformly spaced data, modifies the sampling rate by a rational multilple p/q. Filtering is involved. Don't know if resample and decimate (or interp) can be made to yield the same result with appropriate selection of input arguments.

Connectez-vous pour commenter.

 Réponse acceptée

Star Strider
Star Strider le 21 Juin 2022

1 vote

Any resampling is not necessary. Just use the lowpass function to filter out everything above 8 kHz. (Use 'ImpulseResponse','iir' for the best results.)

4 commentaires

Abdelhakim Souidi
Abdelhakim Souidi le 21 Juin 2022
your approach seem quite different,can you propose a code please
Star Strider
Star Strider le 21 Juin 2022
Modifié(e) : Star Strider le 22 Juin 2022
Click in the link I provided. It has a detailed explanation, including examples.
EDIT — (22 Jun 2022 at 11:03)
There are several options with respect to using the resample function to change the sampling frequency. The one I usually use is this —
[y Fs]= audioread('as6.mp3');
[N,P]=size(y);
ts=1/Fs;
tmax=(N-1)*ts;
t=0:ts:tmax;
y = double(y); % Convert To Double Precision
Fsr = Fs/2; % Half The Original Sampling Frequency
[yr,tr] = resample(y,t,Fsr) % Resample To 'Fsr' & Return New Time Vector 'tr'
y_filt = lowpass(y, 8000, Fs, 'ImpulseResponse','iir'); % Filter Original Signal
yr_filt = lowpass(yr, 8000, Fsr, 'ImpulseResponse','iir'); % Filter Downsampled Signal
From there,. you can do anything you want with the filtered signals.
Note that according to the documentation, the output y for a .mp3 file will be single. This will not be a problem for lowpass, however it will have to be converted to double for resample. The downsample function does not specify what precision the input signal vector has to be. (The downsample funciton also does not have the functionality of returning the resampled time vector, which is the reason I chose resample for this.)
.
Abdelhakim Souidi
Abdelhakim Souidi le 22 Juin 2022
thank you brother for clarification. I Want to know one more other thing is resample and downsample function are the same
Star Strider
Star Strider le 22 Juin 2022
My pleasure.
Apparently not, at least as far as I can tell.
Using the type function reveals that the two appear to be entirely independent. I thought that downsample might call resample, however it does not appear to do so:
type downsample.m
q = which('resample.m', '-all')
type(q{1})
I will leave that for you to do rather than displaying it here (although it does work here) since the code is copyrighted and should not be displayed on an open access site. (Be certain that the appropriate element of ‘q’ is the Signal Processing Toolbox version of resample so that you can see the correct function, since there are several different — I count 8 in the online documentation — resample functions.)
.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by