0

I have a signal of wave song and I have a problem with amplitudes.

%graph 1 time domain
song2 = song(1:size(song));
fs = 44100;
dt = 1/fs;
t = 0:dt:(length(song2)*dt)-dt;
figure(); 
plot(t,abs(song2)); xlabel('Seconds'); ylabel('Amplitude');

Then I put signal in FFT, because I want to get amplitude of detecting peaks(for example; 164Hz).

%graph 2 fft
L = length(song2); 
NFFT = 2^nextpow2(L);
f = fs/2*linspace(0,1,NFFT/2+1);
X = fft(song2,NFFT)/L; 
X = 2*abs(X(1:NFFT/2+1)); 
figure(); 
plot(f,X);  

The problem appear when I get the amplitude of the signal (for example; 0.0103) but if I compare with the amplitude of the (time domain) is not the same.

My question is How in the time domain(graph 1) I detect amplitude of the of a frequency(for example; 164 with amplitude 0.0103)?

EDIT:

Hm, I will rather ask in this way. I detect frequency in frequency domain spectrum as the graph link For example Let us take the the first signal (82hz)(amplitude:0.0075) And my question if is posible to detect position of this first signal in time-domain as the graph in link

Any help would be helpful.

Agni
  • 125
  • 2
  • 15
Cvak
  • 3
  • 1
  • 4

2 Answers2

0

Have you tried the code with a sinusoidal input?

Make a sinusoid of length 512 (any reasonable length) with amplitude 1 and frequency equal to 164 Hz.

When you run the program, I'm sure you'll see the gain at the frequency bin corresponding to 164 Hz close to one, as long as your frequency resolution isn't too bad (meaning you haven't used too few FFT points).

If the above works, then your code should work for a song too. How you're judging/verifying time-domain amplitude in the case of a multi-tonal time domain signal like music is something I don't know.

Akshay Rao
  • 352
  • 1
  • 7
  • Hi. Tnx for answer. I get a bin from frequency domain, but I was wondering how to detecting this bin in the time-domain. Please look at my upper question(I add graphs). – Cvak Nov 06 '14 at 13:01
  • You cannot "detect" a bin in the time-domain. You should spend some time understanding what frequency representation of a time-domain signal is. – Akshay Rao Nov 06 '14 at 13:53
  • A sinusoid can be x(t) = **A**cos(2π**f**t + **ϕ**) A time domain signal can be decomposed into many sinusoids of different values of **A**, **f** and **ϕ**. A peak in an fourier transform graph tells you that one of the constituent signals of the time domain input signal has the frequency corresponding to that bin and has an amplitude corresponding to the height of the peak. So, a peak in frequency domain corresponds to a wave in time domain. So, you cannot detect a sinusoid by trying to find peaks in a time domain signal. – Akshay Rao Nov 06 '14 at 14:02
0

If I understand your question correctly, you can find what you want by taking the inner product of the time domain signal with a complex sinusoid at the frequency of interest. For example, using the information from your post we would something like the following:

% graph 1 time domain
song2 = song(1:size(song));
fs = 44100;
dt = 1/fs;
t = 0:dt:(length(song2)*dt)-dt;
x_164 = exp(-1j * 2*pi * 164 * t);
f_164 = x_164(:).' * song2(:);       % Spectral content of the signal at 164(Hz).

If you think about what a DFT is, you'll see it's just the above process but with the frequencies chosen such that they from an orthogonal basis. However, you can use the same process to estimate the spectral content at any frequency you want.

AnonSubmitter85
  • 933
  • 7
  • 14
  • Hm, I will rather ask in this way. I detect frequency in frequency domain spectrum as the graph (link) http://kmetija-tonkli.si/tmp/freqbeans.png For example Let us take the the first signal (82hz)(amplitude:0.0075) And my question if is posible to detect position of this first signal in time-domain(as the graph in link) http://kmetija-tonkli.si/tmp/timedomain.png – Cvak Nov 06 '14 at 10:11
  • The position in time is tough to get from the traditional FT. In general, you sacrifice position information for frequency information when you take the FT. In a perfect noise-free world you could estimate the duration of the signal from the width of it frequency peak and then its location from the amount of linear phase it has. However, in practical terms that's rarely if ever doable. To do what you want to do, you need to start looking at time-frequency transforms, which will try to provide a balance between location and frequency. The simplest one is the Short-Time Fourier Transform. – AnonSubmitter85 Nov 06 '14 at 17:30