2
$\begingroup$

I have tried to read MATLAB documentation for the fourier command, but there isn't any information on whether this command is applicable to discrete time. For example, if I record any audio signal into MATLAB using the process and commands mentioned here.

Will this recorded object recObj be considered as a continuous-time signal or discrete-time signal? How can we get its frequency domain representation? Using the fourier command?

$\endgroup$
1
  • $\begingroup$ Are you sure you are not looking for the fft() function of the Signal Processing Toolbox? $\endgroup$ Nov 3, 2022 at 20:43

2 Answers 2

4
$\begingroup$

I had never seen this fourier command before. From what I gather, it returns the expression for the Fourier transform of the input to the command, specified as a symbolic expression. Think of it as giving you the actual expression for the Fourier Transform you would get by computing it with pen and paper.

Will this recorded object recObj be considered as continuous time signal or discrete time signal?

To be precise, this recObj object is an object of type audiorecorder. The function getaudiodata() applied to this object gives you access to the sampled data, i.e. discrete data.

How can we get its frequency domain representation? Using 'fourier' command?

No. You would use the DFT (Discrete Fourier transform), available through the fft function for example, if your signal is stationary. If your signal is non-stationary (speech or music for example), you would want to have a time-frequency representation of your data, to see how the frequency content changes over time. For this, you could use the STFT (Short Time Fourier transform), available through the spectrogram function


Let's go through the example you're using, and I'll add some precisions for you:

% Define sampling and recording parameters:
Fs = 44100; % sampling frequency
nBits = 16; % number of bits used to represent each sample of the discrete data
nChannels = 1; 
ID = -1; % default audio input device 

% Initialize an audiorecorder object
recObj = audiorecorder(Fs,nBits,nChannels,ID);

% Record: speak or sing, the data is continuous when it reaches the microphone on your device, and goes through an Analog to Digital converter that samples it. The data stored is now discrete.
disp('Start speaking.')
recordblocking(recObj,5);

disp('End of Recording.');

For illustration purposes, this is what I get when recording the phrase:

$$ \textit{I hope this answer helps you}$$

Let's first look at the frequency content, using fft:

% get the discrete data out of recObj
x = getaudiodata(recObj);

% Get the frequency content
N = length(x);
X = fft(x,N); X = X(1:N/2);
psd = 2*abs(X).^2/(Fs*N); % Power spectral density, don't worry about the scaling too much for now.

% Plot the frequency content
figure(1)
freqVec = (0:N/2-1)*Fs/N;
plot(freqVec, 10*log10(psd));
xlabel('Frequency (Hz)');
ylabel('Power (dB/Hz)');
grid on

enter image description here

Not much to see right? That's because what you recorded probably has frequencies that vary over time. Let's go to a time-frequency representation, using spectrogram:

% Get the time-frequency content
winLength = 4096;
[s,t,f] = spectrogram(x, winLength, winLength/4, winLength, Fs);

% Plot
figure(2)
surf(f,t,10*log10(abs(s).^2),'edgecolor','none');
axis tight; view(0,90);
xlabel('Time (s)')
ylabel('Frequency (Hz)')

enter image description here

Try it out, and let us know if anything is unclear!

$\endgroup$
2
  • $\begingroup$ Thanks for your courteous & detailed response. If comfortable, can you please also try to expalin , how to understand/interpret this spectrogram?as it has only different colors.(forexample can you please explain what is signal frequency at time 2 seconds? where we have patches of both blue & yellow $\endgroup$
    – DSP_CS
    Nov 3, 2022 at 8:47
  • $\begingroup$ Think of each "column" as the frequency content at a specific time instant (to be precise, at a specific time frame). The colors represent how much power at each frequency is present in that time frame. Yellow is more power, blue is less. You can see the power values by toggling the icon that looks like a little graded set of colors on top of your plotting window (2nd to the left of the mouse icon). At 2s, you can see there is more power in the higher frequencies (500:12000Hz), indicating a fricative (the "s" sound from "thiS"). You can see that same pattern at 2.4s (anSwer) and 3.2s (helpS) $\endgroup$
    – Jdip
    Nov 3, 2022 at 9:00
4
$\begingroup$

Fourier is part of the Symbolic Math toolbox, so you use it to compute the closed form transform of a symbolic function.

With any real discrete data, you need to perform a DFT (usually with fft), with all the caveats that apply.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.