Frequency range of AnaylserNode.getFloatFrequencyData()/getByteFrequencyData() - web-audio-api

For the AnalyserNode in the Web Audio API, what is the frequency range of the data returned by getFloatFrequencyData() and getByteFrequencyData()? Can I assume the AnalyserNode is simply FFT, making the range zero-to-half-the-sample-rate?

Yes, that's correct. The frequency bins are linearly spread across the frequencies from 0 to 1/2 the sample rate.

Related

Does the duration of a signal affect its frequency component's amplitude? Also, does the sampling frequency affect the power of a signal?

I have two questions that are bugging me:
Does the duration of an audio signal affect the amplitude of frequency components of that same signal? For example, I am recording the sound of a fan using a microphone. At first, I record only for 10 sec and convert the audio signal into frequency spectrum. Then, I record the same sound for 20 sec and then convert the audio signal into frequency spectrum. In both the cases, the sound of the fan is same, but does the duration of the signal affect the amplitude of frequency components in the spectrum plot?
For example, I have 2 audio signals. For the first one, I have that same fan sound recording for 10 sec and the sampling frequency is 5KHz, and for the second recording, I have that same audio signal but now the sampling frequency is changed to 15KHz. I used MATLAB to check the power for both the signals and the power for both the signals was same, however I want to know why. Formula that I used was Power=rms(signal)^2. According to me the second signal should have more power because now there are more number of samples compared to the first recording and since those extra samples would also have a random amplitude, the average shouldn't be the same as for the first one. Am I thinking it right?
Can anyone provide their thoughts? Thank You!
This answer is from: https://dsp.stackexchange.com/questions/75025/does-the-duration-of-a-signal-affect-its-frequency-components-amplitude-also
Power is energy per unit time. If you increase the duration, you increase the energy, but due to the normalization with time the power would be the same.
The DFT as given by
X[k]=∑n=0N−1x[n]e−j2πnk/N
will scale the frequency component by N as given by the summation over N samples. This can be normalized by multiplying the result by 1/N.
The frequency components of the signal levels will be the same in a normalized DFT (normalized by dividing by the total number of samples) for signal components that occupy one bin (pure tones), but the noise floor as observed may be lower by the change in sampling rate: if the noise floor is limited by quantization noise, the total quantization noise (well approximated as white noise, meaning constant across all frequencies) will be spread over a wider frequency range, so increasing the sampling rate will cause the contribution of quantization noise on a per Hz basis (noise density) to be lower. Further the duration will effect the frequency resolution in each bin in the frequency domain; for an unwindowed DFT, the equivalent noise bandwidth per bin is fs/N where fs is the sampling rate and N is the number of bins. At a given sampling rate, increasing the number of bins will increase the total duration and thus reduce the noise bandwidth per bin; causing the overall DFT noise floor as observed to decrease. (Same noise power just less measured in each bin). Windowing if done in the time domain will reduce the signal level by the coherent gain of the window, but increase the equivalent noise bandwidth such that pure tones will be reduced more than noise that is spread over multiple bins.

why FFT results in high frequency range are not correct?

I am doing FFT with matlab.the time period i am doing the fft on it is 1 second and it consist of 50000 equlay spaces samples. I want to test the FFT results. so I have given an input as below (wave) which is a complex of sinosuidal waves (and I have samples it by sampling frequency of 50 KHZ)and I expect to have the frequency magnitude results as I have given in the input. the results are ok for low frequency ranges but for the higher frequency (5752 Hz and 7993 Hz) results are 5.87 and 6.7 respectively (instead of 6 and ). what Is the origin of this big mistake ? how can I improve my results ?!
Here is the code:
t = 0:1/50000:1;
wave = 100*sin(2*pi*50*t)+1*sin (2*pi*123*t)+2*sin (2*pi*203*t)+3*sin(2*pi*223*t)+4*sin(2*pi*331*t)+5*sin(2*pi*2812*t)+6*sin(2*pi*5752*t)+7*sin(2*pi*7993*t);
SPEC = fft(wave);
L = size(SPEC,2);
x= (0:L/2-1);
Half_SPEC = abs(SPEC(1:L/2))/(L/2); %% removing the mirror side and ranging the domain
plot(x,Half_SPEC);
As Oli Charlesworth has pointed out, you are taking the FFT of 50001 points, which means that the frequency spacing is 1/50001.
Typically the FFT will give you the exact magnitude of your sinusoid only if its frequency is an exact multiple of the frequency spacing. Otherwise, the energy will be spread over multiple FFT bins in a process called spectral leakage.
You may confirm this by changing the number of samples such that the frequency of your sinusoids are a multiple of the frequency spacing:
t = 0:1/50000:1-1/50000;
Windowing the input signal can also help control the amount of leakage.

What's the frequency range for a FFT?

So, as far as I have read up, for a signal with data points 0...n, I get a result from 0 to n, but I can omit n/2...n. Correct ? So now I have n/2 data points. How is the relation between the frequency range of these data points to the signal data ? E.g. what frequency is n/2 (0 is 0 hz I guess) ?
An FFT by itself has no frequency range. It could be anything.
The frequency range of an FFT result depends on the sample rate frequency at which the input data points were evenly sampled. The FFT results are then data points in the frequency domain spaced at the sample rate frequency divided by the FFT length, from 0 or DC up to half the sample rate.
The output of the generic FFT normally used in programming is 0-22khz for a 44.1 sample and 0-24khz for a 48khz input.
Actually, the raw output of the FFT is reflected over zero, so -22 to + 22, and most programs use the 0-22 half only... https://i.stack.imgur.com/GeaJq.png

How can filter data to remove noise in matlab?

I have 2 arrays of 800000 input and output data samples of a system. The system in a kind of oven that works among 0 and 10 volts. The sample time is 0.001s.
I have to identify the model of this system, but first of all, given that the data are clearly dirty, I would like to filter the noise.
How can I do it with the System Identification Toolbox of Matlab?
Moreover, how can I estimate the cutoff frequency to remove the noise?
Thank you in advance.
PS: given that this is a bit out of topic, please, post your answer here thank you.
The cutoff frequency is directly given by you sampling time or sampling frequency.
you sampling frequency is 1/(sampling time) and must at least 2 the factor of the highest frequency of interest:
http://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem
f_s = 1/T_s >= 2*f_cutOff
You can then simply to same frequency domain processing in the case you sampling frequency is realy high enough. The easiest way would to have a look at the frequency domain (with function fft() ). And check first where you have high noise components. Then filter out these components (zeroing) and then transform it back into time domain ( with function ifft() ).
Noise is modeled as a white Gaussian distribution in the simplest case. If you estimate the noise energy, you can make a dummy noise by calling
noise = A*randn(1,N);
Here, A is the amplitude and N is the sample count. then just take the fft of this signal and subtract it from the fft of input signal and take the inverse fft (ifft)

Channel vocoder using FFT - what to do about DC Component and Nyquist frequency?

I am trying to implement a channel vocoder using the iOS Accelerate vDSP FFT algorithms. I am having trouble figuring out how to treat the DC component and Nyquist frequency.
The modulator and carrier signals are both float arrays of length n. On each, I perform a forward FFT and am returned a frequency plot (call it bin[]) of length n/2.
As per the vDSP specifications, bin[1] contains the first frequency above 0Hz, bin[2] the second, etc... bin[0] contains the DC Component in the real part and the Nyquist frequency (which would normally be in bin[n/2]) in the imaginary part. vDSP essentially packs the frequency plot into as little space as possible (the imaginary part for bin[0] and bin[n/2] should always be zero before the packing).
I split the frequency plot for both carrier and modulator into k bands. My goal is to multiply each frequency in carrier.band[x] by the total magnitude of the frequencies in modulator.band[x]. Essentially, increasing the intensity of those frequencies in the carrier that are also present in the modulator.
So if n=8 and k=2, the second band for the modulator would contain contain bin[2] and bin[3]. Simple enough to find the total magnitude, simply sum the magnitudes of each bin (for example mag[2] = sqrt( bin[2].real*bin[2]*real + bin[2].imag*bin[2]*imag )).
That works great for all bands except the first one, because the first band contains the weird bin[0] with the DC component and Nyquist frequency.
How do I handle that first bin when calculating the total magnitude of a band? Do I just assume the magnitude for the first bin is JUST the DC component by itself? Do I discard the Nyquist frequency?
Thank you to anyone who can provide some guidance! I appreciate it.
I suggest you ignore 0 Hz and Nyquist since they contain no useful information in the case of an audio signal.