In: Electrical Engineering
Activity description
A program must be carried out in MATLAB or OCTAVE that acquires and analyzes (continuously or online) the voice signal that is acquired from the sound card of the PC (microphone input) or a signal that is acquired with an acquisition card of data (ex. NI DAQCard).
The program must continuously perform the functions: signal acquisition, spectral analysis of the acquired signal, graphs in the time domain and graphs in the frequency domain (magnitude and phase spectrum).
The program should display the following graphs:
1) Original signal in the time domain
2) Original signal in the frequency domain (magnitude and phase)
Program 1: Initially do not acquire the signal from the PC sound card, instead create a synthetic signal in the MATLAB workspace, for example a signal composed of the sum of two or more sinusoids of different amplitude, frequency and phase . The signal must be visualized in time (oscillations) and the frequency analysis (magnitude spectrum) must show the presence of the original frequencies. It is important to assume a certain sampling frequency and a duration of the synthetic signal.
Program 2: After this works, start with a static version of the voice signal analyzer (ie the input signal is only a defined time window, for example three seconds), i.e. program 2 is an improved version of program version 1 where instead of a synthetic signal the signal that is acquired with the sound card is used in a time range of for example 3s. Note that this frequency is acquired at a certain sampling frequency. Finally, make the necessary adaptations and changes to the version 1 program so that it works online or continuously.
Questions to answer:
1) What is the analysis in the frequency domain of a signal? What
differences exist with respect to time domain
2) What is the FFT?
3) What type of signals (continuous or discrete) are being used in
the program? Explain your answer.
4) Explain what the frequency spectrum of a signal is (remember
that the frequency spectrum is two graphs).
5) According to the project, generally what type of signals do we
find in nature (continuous or discrete) and what type of signals do
computer systems use (continuous or discrete)?
%% Program 1
clear all;
close all;
clc;
Fs=5e3;
Ts=1/Fs;
t=0:Ts:1;
x=2*sin(100*2*pi*t)+cos(250*2*pi*t)+0.1*sin(500*2*pi*t);
plot(t,x)
xlim([0 0.05])
title('Synthetic Signal')
X=fft(x);
N=length(X);
dF = Fs/N;
Freq = -Fs/2:dF:Fs/2-dF;
figure();
subplot(2,1,1)
plot(Freq,20*log10(abs(X)/N));
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)')
title('Magnitude Plot');
subplot(2,1,2)
plot(Freq,180/(2*pi)*angle(X))
xlabel('Frequency (Hz)');
ylabel('Phase (degree)')
title('Phase Plot');
Output:
%% Program 2
clear all;
close all;
clc;
recorder = audiorecorder;
disp('Start speaking.')
recordblocking(recorder, 5);
disp('End of Recording.');
x = getaudiodata(recorder);
plot(x);
Fs=recorder.SampleRate;
X=fft(x);
N=length(X);
dF = Fs/N;
Freq = -Fs/2:dF:Fs/2-dF;
figure();
subplot(2,1,1)
plot(Freq,20*log10(abs(X)/N));
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)')
title('Magnitude Plot');
subplot(2,1,2)
plot(Freq,180/(2*pi)*angle(X))
xlabel('Frequency (Hz)');
ylabel('Phase (degree)')
title('Phase Plot');
Output:
NOTE: Output of the second program is dependent of each recording testcase.