Hello. I must say, in Matlab I am a newbie, please do not swear.

I have an audio file recorded in it is white noise with a frequency of from 100-10000 Hz,

Required to construct the spectrum of this audio file

googled what it takes f-tsiya fft in Matlab (https://www.mathworks.com/help/matlab/ref/fft.html), tried to build something

It is not clear that here P1?

And maybe there is some ready code for my problem?

I have an audio file recorded in it is white noise with a frequency of from 100-10000 Hz,

Required to construct the spectrum of this audio file

googled what it takes f-tsiya fft in Matlab (https://www.mathworks.com/help/matlab/ref/fft.html), tried to build something

[y,Fs]=audioread('C:\1.wav');

L = 1000; % Length of signal

Y = fft(y);

P2 = abs(Y/L);

P1 = P2(1:L/2+1);

P1(2:end-1) = 2*P1(2:end-1);

f = Fs*(0:(L/2))/L;

plot(f,P1)

title('Single-Sided Amplitude Spectrum of X(t)')

xlabel('f (Hz)')

ylabel('|P1(f)|')

It is not clear that here P1?

And maybe there is some ready code for my problem?

asked March 19th 20 at 09:21

1 answer

answered on

Solution

File 1000 counts (value of L)?

If not, then L is equal to the dimension of y after reading from a file.

I do not understand why this is done

Don't need it, IMHO.

P1 is the first half of the modules of the fft result, what is usually meant by "spectrum" - frequency response.

If not, then L is equal to the dimension of y after reading from a file.

I do not understand why this is done

`P1(2:end-1) = 2*P1(2:end-1);`

Don't need it, IMHO.

P1 is the first half of the modules of the fft result, what is usually meant by "spectrum" - frequency response.

Find more questions by tags MATLAB

P1(2:end-1) = 2*P1(2:end-1); - removed.

And the picture on the chart similar to the spectrum.

and can help with the transition from P(f) to dB? (bottom graph from the application signal analyzer)

- Jaida45 commented on March 19th 20 at 09:26

Normalized version: P1 = 20 * log10(P1/ P1(1)) - aliza_Kreiger commented on March 19th 20 at 09:38

Try a normalized version. - aliza_Kreiger commented on March 19th 20 at 09:41

it features signal analyzer? how would smooths the spectrum - Jaida45 commented on March 19th 20 at 09:44

You can also iron - accumulate absы 1 second. After accumulating ration for a number of savings. - aliza_Kreiger commented on March 19th 20 at 09:47

code is not checked.

In P1, the accumulated modules.

Add your ending - aliza_Kreiger commented on March 19th 20 at 09:53

In which version have you attended signal in the lower frequencies? - aliza_Kreiger commented on March 19th 20 at 09:59

1. interpretation of the result of FFT depends on the sampling frequency (Fs) and FFT size (L). The easiest way to interpret the result when L = Fs - in this case, each sample of the FFT result is adequate chatot in Hertz. When L != Fs, you need the index of the frequency multiplied by a factor Fs/L to obtain the frequency in Hz. So your initial version of the chart you brought in some fractions of a Hertz (44100/2646000~0.017).

2.Probably in your file at some point present lower frequency. With the accumulation of I set N=10, i.e., the accumulation for 10 seconds. The graph is drawn only for the first 10 seconds of the signal.

You have a file 60 seconds of the recording. Try to do 60 seconds of accumulation (N=60).

Or you can make the same plot (with 10 seconds of savings), but the signal processing is not, for example, from the middle. - aliza_Kreiger commented on March 19th 20 at 10:05

here, the first is when I have L = number of array elements, and second, when L = Fs. The audio file I just recorded with a frequency of 100-10 000gts. The first figure is true, but the second disappears. - Jaida45 commented on March 19th 20 at 10:11

the cycle that you suggested, I did not yet to do. maybe I have to code error. L = 2646000 or or 44100 - Jaida45 commented on March 19th 20 at 10:17

Reread item 1.

See:

1.you do fft on entire array in 2646000 elements at a sampling rate of 44100.

2.in the result of FFT of the receive array is not in Hertz, but in fractions of a Hertz (44100/2646000~0.017), i.e. for example 1 element of the array has a frequency of 1*0.017 Hz, the second element 2*0.017 Hz (actually from the index Alemana necessary to subtract 1 and then multiply by a factor). Element 44100 is the frequency of 750 Hz.

3.Of the total result of the FFT you take only 22050 samples, and it is 22050*0,017=375 Hz.

Ie, your first graph from 0 to 375 Hz, and not to 22 KHz, as you mistakenly think. So your interpretation of this graph is not true. Additionally misleads the scale x value, which is taken from here: f = Fs*(0:(L/2))/L; by the Way, this formula just scored the same factor: Fs/L and multiplied by the element's index.

If you do FFT on entire array, L have to assign a value 2646000, then it will be something more meaningful.

On account of the theory, about the ratio Fs/L can be read from Richard Lyons, "Digital signal processing" - section 3.5. Well, there is about everything else, all sensible owner. - aliza_Kreiger commented on March 19th 20 at 10:20

Combed the option of accumulation:

- aliza_Kreiger commented on March 19th 20 at 10:26

And last question, can I use y = decimate(x,r) and than it threatens? the reason it wants to use is not the grip of the memory MK for the source array y to the MC to check the library fft - Jaida45 commented on March 19th 20 at 10:29

On account of the danger depends on what you will do with this signal.

Note that when reducing the sampling rate, cut the upper frequencies.

I.e. in the signal with a sampling frequency of 44100 Hz, contains frequencies up to 22050 Hz. The slaughter of the signal, for example, RR = 10 KHz - left frequency up to 5 KHz.

Library FFT in MK on si? Usually on the lower level limit FFT size equal to a power of two. It makes sense to make the resulting black hole is equal to a power of two. If the array size is not equal to a power of two, then it is necessary to do standard DFT (not FFT), and it is much longer. In Matlab it's all hidden from the user, but on the lower level and need to resolve by hand.

Although BH = power of two this is not a mandatory requirement. To a size equal to a power of two can bring such as finishing off the missing value zeros, or taking the number of signal samples is less than BH, but equally two. In both cases you need to remember about the ratio (Fs/L) in the derivation of frequencies. Fs - sampling frequency, L is the FFT size. - aliza_Kreiger commented on March 19th 20 at 10:32

made it so

spoiler[y,Fs]=audioread('D:\wav\Sound_21098_1000Hz.wav');

y = decimate(y,10);

y = y(:, 1);

L = 4410;% Length of signalN = 10; % number of accumulation

P1 = zeros([L/2, 1]);

for i = 0:N-1

Y = fft(y(L*i + 1 : L*(i+1)));

P1 = P1 + abs(Y(1:L/2));

end

P1 = P1 / (N * L);

P4 = 20*log10(P1/P1(1));

f = (0:(L/2)-1)* (

L/ L);plot(f,P4)

title(")

xlabel('f (Hz)')

ylabel('P')

manually asked L, because the frequency of Fs has decreased 10 times, and I changed the formula Fs/L. T. in memory he 4410, and 44100.

got this picture

if understand this correctly, here signal just stabbed 10 times.

Library FFT in MK on si Yes. planned if no degree 2-Ki to finish off the zeros. - Jaida45 commented on March 19th 20 at 10:35