フィルターのクリア

CAN ANYONE PLEASE PROVIDE AN EXPLANATION FOR THIS CODE ON AUDIO COMPRESSION? (the formula is for 60% compression i dont understand how it came)

2 ビュー (過去 30 日間)
[x,fs]=audioread('sample.wav');
N=length(x);
vlcplayer=audioplayer(x,fs);
vlcplayer.play
%%%%%%%%%%%%%%%%%%%%%
t=fft(x,N);
X=fftshift(t)
f=-fs/2:fs/N:(fs/2-fs/N);
figure(1)
plot(f,abs(X))
title('original audio signal')
%%%%%%%%%%%%%%%%%%%%%%%
Xr=zeros(1,N);
Xr((N*((60/100)/2))+1 : N*(1-(60/100)/2)) = X((N*((60/100)/2))+1 : N*(1-(60/100)/2)); %%FORMULA
  2 件のコメント
Rik
Rik 2020 年 11 月 6 日
Please format your posts properly (click here for help with the editor). Also, please don't post the same question twice.
John D'Errico
John D'Errico 2020 年 11 月 7 日
Actually, 3 postings on this question, one of which I closed.

サインインしてコメントする。

回答 (2 件)

KSSV
KSSV 2020 年 11 月 6 日
[x,fs]=audioread('sample.wav'); % read the audio file
N=length(x); % Get the length if the data
vlcplayer=audioplayer(x,fs); % play the file
vlcplayer.play
%%%%%%%%%%%%%%%%%%%%%
t=fft(x,N); % this gives Fourier TRanform this converts the audio into frequency domain
X=fftshift(t) ; % fourier transform shifted
f=-fs/2:fs/N:(fs/2-fs/N); % gives frequencies based on length of the data
figure(1) % figure opened
plot(f,abs(X)) % plot the frequency and aboslute of X, plot of freuquency and amplitude
title('original audio signal') % title
%%%%%%%%%%%%%%%%%%%%%%%
Xr=zeros(1,N); % Initialization (You need to check on this)
Xr((N*((60/100)/2))+1 : N*(1-(60/100)/2)) = X((N*((60/100)/2))+1 : N*(1-(60/100)/2)); %%FORMULA
% The above formula generates some indices and picks that data from X and fills in Xr.
  5 件のコメント
KSSV
KSSV 2020 年 11 月 7 日
fft calculates/ convers the time domain into frequency domain.
fftshift shifts the zero frequency to center.
Walter Roberson
Walter Roberson 2020 年 11 月 7 日
fft of real-valued data returns a vector in which the first half corresponds to increasing frequencies -- 0Hz, then 1Hz, then 2Hz, and so on up to (N-1)/2 Hz for N points. This corresponds to positive frequencies.
Then in the same vector it descends in frequency, (N-1)/2 Hz, (N-1)/2-1 Hz,... 3 Hz, 2 Hz, 1 Hz (0 Hz is not repeated). The information in the second half is reversed in order compared to the first half, and is the complex conjugate of the first half. This corresponds to negative frequencies.
Zero frequency, Positives, conj(reverse of Positives)
There is another order that contains the same information in a slightly different way:
conj(reverse of positives), zero frequency, Positives
This is just taking the second half of the fft and moving it to the front. When that is done, the data order corresponds to most negative frequency first, then increasing (less and less negative) until eventually you reach the zero frequency and then increase through the positive frequencies
For example regular order for fft might be
0 Hz, 1 Hz, 2 Hz, 3 Hz, -3 Hz, -2 Hz, -1 Hz
and the other order would be
-3 Hz, -2 Hz, -1 Hz, 0 Hz, 1 Hz, 2 Hz, 3 Hz
The function that does this minor reordering is fftshift()
As I indicated before, the effect is to make the extraction into a low-pass filter. Your code extracts the middle of the shifted data.. for example taking the middle it would extract the data for -1 Hz, 0 Hz, 1 Hz.
If you took the middle without doing the fftshift then what would have been extracted would be for 2 Hz, 3 Hz, -3 Hz which would be a high-pass filter

サインインしてコメントする。


Walter Roberson
Walter Roberson 2020 年 11 月 6 日
I already explained the code at https://www.mathworks.com/matlabcentral/answers/632834-need-explanation-for-a-matlab-audio-compression-urgently-please-i-would-be-very-gratful#comment_1102859

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by