0% found this document useful (0 votes)
91 views

Matlab Assignment (COMPLETE)

This document contains an analysis of voltage measurements taken at different sampling frequencies. It includes: 1) Details on how the sampling frequency determines the time interval between samples. 2) Tables of sampled voltage values at sampling frequencies of 2000Hz, 500Hz, 1000Hz, and 4000Hz. 3) MATLAB code to generate graphs of voltage over time and frequency spectra from the sampled data. 4) Tables comparing actual frequency/amplitude values to those measured from the spectra, calculating percentage differences. 5) A discussion of the multi-component signal analyzed and how it relates to the given equation.

Uploaded by

Mdnor Rahim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views

Matlab Assignment (COMPLETE)

This document contains an analysis of voltage measurements taken at different sampling frequencies. It includes: 1) Details on how the sampling frequency determines the time interval between samples. 2) Tables of sampled voltage values at sampling frequencies of 2000Hz, 500Hz, 1000Hz, and 4000Hz. 3) MATLAB code to generate graphs of voltage over time and frequency spectra from the sampled data. 4) Tables comparing actual frequency/amplitude values to those measured from the spectra, calculating percentage differences. 5) A discussion of the multi-component signal analyzed and how it relates to the given equation.

Uploaded by

Mdnor Rahim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

EMC 201 MEASUREMENT AND INSTRUMENTATION

SEM 1 2015/2016

NAME

: MUHAMAD NURHAFIZ BIN RAHIM ( 111551)

SCHOOL

: MECHANICAL ENGINEERING

LECTURER

: DR NORZALILAH MOHAMAD NOR

EXPLANATION OF HOW THE DATA IS EXTRATED

For sampling frequency of 2000Hz,


t = 1/fs
= 1/2000
= 0.5ms
For sampling frequency of 500Hz,
t = 1/fs
= 1/500
= 2ms
For sampling frequency of 1000Hz,
t = 1/fs
= 1/1000
= 1ms
For sampling frequency of 4000Hz,
t = 1/fs
= 1/4000
= 0.25ms
Therefore, the image is overlayed with vertical lines with the interval of 0.5ms, 2ms, 1ms and
0.25ms for the sampling frequencies of 2000Hz, 500Hz, 1000Hz and 4000Hz respectively. Then
the corresponding voltages are taken and shown in the tables respectively.

Voltage, V(V)

(A) Sampling Frequency of 2000 Hz

Time, t(ms)
Sampled Data for Sampling Frequency of 2000 Hz

Matlab Code
%Purpose: i)To
using fft function
%
ii)To
components and

No.
1
2
3
4
5
6
7
8
9
10
11
12
13
No.
14
15
16
17
18
19
20
21
22
23
24
25

Time(ms)
(ms)
Time
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
5.5
6

Voltage(V)
5.5
7
-2
-10
-6
7.1
6
2.5
-2
-4.5
-4.5
-1.5
4

6.5
7
7.5
8
8.5
9
9.5
10
10.5
11
11.5
12

7.4
3
-8
-10
2
7.5
4.5
0.5
-3
-4.8
-2.5
3

obtain the frequency spectrum


in Matlab
determine the frequency
their corresponding amplitudes

close all; %clear all the data


fid = fopen('EMC_2000Hz.txt', 'r'); %open the file from the text
A = fscanf(fid, '%g %g', [2 inf]); % read the data from the 2 columns of the text file
B=A'; % transfer the data from the text file
t=B(:,1); % 1 refer to the data at column 1
v=B(:,2); %2 refer to the data at column 2
plot(t,v);
xlabel('Time(ms)');
ylabel('Voltage(V)');
title('Graph of Voltage(V) versus Time(ms)at Sampling Frequency 2000Hz');
f_sampling=2000; %sampling frequency is equal to 2000Hz
y=fft(v); %voltage undergoes fast fourier transform
N=length(y); %N is the numbers of sampling data
amplitude=abs(y)*2/N; %calculate the actual amplitude
f=(1:N)/N; %normalize the scale
frequency=f*f_sampling; %calculate the actual frequency
figure, plot(frequency,amplitude) %plot a graph of actual amplitude versus actual frequency
xlabel('Frequency(Hz)');
ylabel('Amplitude');
title('Frequency Spectrum for Sampling Frequency 2000Hz');
Figure 1:Graph of Voltage(v) versus Time (ms)

Figure 2: Frequency Spectrum

(B)

Sampling

Frequency of 500 Hz

Voltage, V(V)

Time, t(ms)

Sampled Data for Sampling Frequency of 500Hz


No.
1
2
3
4
5
6
7

Time (ms)
0
2
4
6
8
10
12

Voltage(V)
5.5
-5
-2
4
-10
0.5
3

Matlab Code
%Purpose: i)To obtain the frequency spectrum using fft function in Matlab
%
ii)To determine the frequency components and their corresponding amplitudes
close all; %clear all the data
fid = fopen('EMC_500Hz.txt', 'r'); %open the file from the text
A = fscanf(fid, '%g %g', [2 inf]); % read the data from the 2 columns of the text file
B=A'; % transfer the data from the text file
t=B(:,1); % 1 refer to the data at column 1
v=B(:,2); %2 refer to the data at column 2
plot(t,v);
xlabel('Time(ms)');
ylabel('Voltage(V)');
title('Graph of Voltage(V) versus Time(ms)at Sampling Frequency 500Hz');
f_sampling=500; %sampling frequency is equal to 500Hz
y=fft(v); %voltage undergoes fast fourier transform
N=length(y); %N is the numbers of sampling data
amplitude=abs(y)*2/N; %calculate the actual amplitude
f=(1:N)/N; %normalize the scale
frequency=f*f_sampling; %calculate the actual frequency
figure, plot(frequency,amplitude) %plot a graph of actual amplitude versus actual frequency
xlabel('Frequency(Hz)');
ylabel('Amplitude');
title('Frequency Spectrum for Sampling Frequency 500Hz');

Figure 3 :
Frequency Spectrum

Graph of Voltage(V) Versus Time(ms)

(C) Sampling Frequency of 1000Hz

Figure 4:

Voltage, V(V)

Time, t(ms)

Sampled Data for Sampling Frequency of 1000Hz


No.
1
2
3
4
5
6
7
8
9
10
11
12
13

Time (ms)
0
1
2
3
4
5
6
7
8
9
10
11
12

Voltage(V)
5.5
-2
-5
6
-2
-4.5
4
3
-10
7.5
0.5
-4.8
3

Matlab Code
%Purpose: i)To obtain the frequency spectrum using fft function in Matlab
%
ii)To determine the frequency components and their corresponding amplitudes
close all; %clear all the data
fid = fopen('EMC_1000Hz.txt', 'r'); %open the file from the text
A = fscanf(fid, '%g %g', [2 inf]); % read the data from the 2 columns of the text file
B=A'; % transfer the data from the text file
t=B(:,1); % 1 refer to the data at column 1
v=B(:,2); %2 refer to the data at column 2
plot(t,v);
xlabel('Time(ms)');
ylabel('Voltage(V)');
title('Graph of Voltage(V) versus Time(ms)at Sampling Frequency 1000Hz');
f_sampling=1000; %sampling frequency is equal to 1000Hz
y=fft(v); %voltage undergoes fast fourier transform
N=length(y); %N is the numbers of sampling data
amplitude=abs(y)*2/N; %calculate the actual amplitude
f=(1:N)/N; %normalize the scale
frequency=f*f_sampling; %calculate the actual frequency
figure, plot(frequency,amplitude) %plot a graph of actual amplitude versus actual frequency
xlabel('Frequency(Hz)');
ylabel('Amplitude');
title('Frequency Spectrum for Sampling Frequency 1000Hz');

Figure 5: Graph
Spectrum

Of Voltage(V) Versus Time(s)

Figure

6: Frequency

Voltage, V(V)

(D) Sampling Frequency of 4000Hz

Time, t(ms)
Sampled Data for Sampling Frequency of 4000Hz
Voltage(V
No. Time Time
(ms) (ms) Voltage(V)
1
0.00
5.50)
2
0.25
7.00
3
0.50
7.00
4
0.75
5.00
5
1.00
-1.00
6
1.25
-7.00
7
1.50
-10.50
8
1.75
-10.50
9
2.00
-5.00
10
2.25
2.00
11
2.50
6.00
12
2.75
7.20
13
3.00
6.00
14
3.25
4.50
15
3.50
2.50
16
3.75
0.00
17
4.00
-2.00
18
4.25
-3.50
19
4.50
-4.50
20
4.75
-5.00
21
5.00
-4.50
22
5.25
-3.50
23
5.50
-1.50
24
5.75
0.50
25
6.00
4.00
No.

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

6.25
6.50
6.75
7.00
7.25
7.50
7.75
8.00
8.25
8.50
8.75
9.00
9.25
9.50
9.75
10.00
10.25
10.50
10.75
11.00
11.25
11.50
11.75
12.00

6.00
7.20
6.50
3.00
-2.00
-8.00
-10.00
-10.00
-3.00
4.00
7.00
7.20
6.50
5.00
3.00
0.50
-1.50
-3.00
-4.30
-4.80
-4.00
-2.50
-0.50
2.50

Matlab Code
%Purpose: i) To obtain the frequency spectrum using fft function in Matlab
%
ii) To determine the frequency components and their corresponding amplitudes
close all; %clear all the data
fid = fopen('EMC_4000Hz.txt', 'r'); %open the file from the text
A = fscanf(fid, '%g %g', [2 inf]); % read the data from the 2 columns of the text file
B=A'; % transfer the data from the text file
t=B(:,1); % 1 refer to the data at column 1
v=B(:,2); %2 refer to the data at column 2
plot(t,v);
xlabel('Time(ms)');
ylabel('Voltage(V)');
title('Graph of Voltage(V) versus Time(ms)at Sampling Frequency 4000Hz');
f_sampling=4000; %sampling frequency is equal to 4000Hz
y=fft(v); %voltage undergoes fast fourier transform
N=length(y); %N is the numbers of sampling data

amplitude=abs(y)*2/N; %calculate the actual amplitude


f=(1:N)/N; %normalize the scale
frequency=f*f_sampling; %calculate the actual frequency
figure, plot(frequency,amplitude) %plot a graph of actual amplitude versus actual frequency
xlabel('Frequency(Hz)');
ylabel('Amplitude');
title('Frequency Spectrum for Sampling Frequency 4000Hz');

Figure 7:Graph
Spectrum

Of Voltage(V) Versus Time(s)

Figure

8: Frequency

EXTRACTED FREQUENCY SPECTRA

(A) For Sampling

(B) For Sampling

Frequency
(Hz)
80

Amplitude(V)

160

0.2954

240

0.11

320

0.05577

400

6.937

480
Frequency(Hz)
560
71.43
640
142.9
214.3 720
800

Frequency of 2000 Hz

0.096

Frequency of 500 Hz

0.1358
Amplitude
(V)
2.863
1.143
0.3391
2.951
1.207
5.147
0.1137

880

0.2598

960

0.3495

1040

0.4646

285.7

(C) For Sampling Frequency of 1000 Hz

4.106

(D) For Sampling Frequency of 4000Hz


No.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

Frequency(Hz)
81.63
163.26
244.89
326.52
408.15
489.78
571.41
Frequency(Hz)
653.04
76.92734.67
153.8 816.3
897.93
230.8979.56
307.71061.19
384.61142.82
1224.45
461.51306.08
538.51387.71
1469.34
1550.97
1632.6
1714.23
1795.86
1877.49
1959.12
2040.75

Amplitude(V)
0.1429
0.3559
0.4042
0.3004
6.8
0.4382
2.994
Amplitude(V)
0.2237
1.084
0.1846
0.1719
0.65
0.4266
0.6799
0.1114
0.208
0.6554
6.370.07
0.1841
2.086
0.03028
2.233
0.1573
0.09163
0.07481
0.1103
0.06876
0.1076
0.1083
0.1018
0.05263

COMPARISONS BETWEEN ACTUAL AND MEASURED DATA


(A) For Sampling Frequency of 2000Hz
Percentage of
Frequency, f (Hz)
Difference
Actual
Measured
No.
st
(%)
Frequency
Frequency
1
322.6
400.0
24.0
2nd
483.9
560.0
15.7
3rd
645.2
720.0
11.6

Amplitude, (V)
Actual
Measured
Amplitude
Amplitude
6.7
6.937
2.9
2.863
0.9
1.207

(B) For Sampling Frequency of 500 Hz


No.

Frequency, f (Hz)

Amplitude, (V)

Percentage of
Difference (%)
3.54
1.28
34.11

Measured
Amplitude
5.147
4.106
-

Percentage of
Difference
23.18 (%)
41.59
-

(C) For Sampling Frequency of 1000 Hz


Percentage of
Frequency, f (Hz)
Difference
Actual
Measured
No.
st
(%)
Frequency
Frequency
1
322.6
384.6
19.22
2nd
483.9
461.5
4.63
3rd
645.2
538.5
16.54

Amplitude, (V)
Actual
Measured
Amplitude
Amplitude
6.7
6.37
2.9
2.086
0.9
2.233

Percentage of
Difference (%)
4.93
28.07
148.11

(D) For Sampling Frequency of 4000 Hz


Percentage of
Frequency, f (Hz)
Difference
Actual
Measured
No.
st
(%)
Frequency
Frequency
1
322.6
408.2
26.53
nd
2
483.9
571.4
18.08
3rd
645.2
734.7
13.87

Amplitude, (V)
Actual
Measured
Amplitude
Amplitude
6.7
6.8
2.9
2.994
0.9
1.084

Percentage of
Difference (%)
1.49
3.24
20.44

st

1
2nd
3rd

Actual
Frequency
322.6
483.9
645.2

Measured
Frequency
214.3
285.7
-

Percentage of
Difference
33.57
40.96
-

Actual
Amplitude
6.7
2.9
0.9

DISCUSSIONS:
The answer given in (page 774) is V(t) = 6.7cos (2026.8t) + 2.9sin (3040.3) - 0.9
cos(4053.7t). Since w = 2f, the answer can also be written as V(t) = 6.7cos (2322.6t) + 2.9sin
(2483.9t) - 0.9cos (2645.2t). From this equation, the amplitudes are 6.7V, 2.9V and 0.9V with
signal frequencies = 322.6Hz, 483.9Hz and 645.2Hz respectively.
For sampling frequency of 2000 Hz, the Nyquist frequency is 1000Hz. 3 of the signal
frequencies(322.6Hz,483.9Hz,645.2Hz) are smaller than the Nyquist frequency(1000Hz)
.Therefore, no aliasing occurs and the percentage of differences for the frequency and amplitudes
obtained are less than 35%.
For sampling frequency of 500 Hz, the Nyquist frequency is 250 Hz. 3 of the signal
frequencies (322.6Hz, 483.9Hz, and 645.2Hz) are greater than the Nyquist frequency which is
250 Hz. Hence, aliasing occurs for the 3 amplitude obtained. Besides, the third harmonic
frequency cannot be detected because the sampled frequency deviates greatly from the Nyquist
frequency.
For sampling frequency of 1000Hz, the Nyquist frequency is 500 Hz. The highest signal
frequency (645.2Hz) is greater than the Nyquist frequency whereas the others 2 signal

frequencies arent. Therefore, the first and second amplitude obtained contain small percentage
error of 4.93% and 28.07% whereas the third signal has large percentage error of 148.11%.
Therefore, aliasing occurs for the 645.2Hz signal frequency.
For sampling frequency of 4000 Hz, the Nyquist frequency is 2000Hz. 3 of the signal
frequencies detected are less than this Nyquist frequency. Hence, the percentage error for the
frequency and the amplitude obtained are small which range from 13% to 27% and 1% to 25%
respectively. Therefore, no aliasing occur.
Nyquist frequency state that signals with frequency lower than fNyq = fs/2 are accurately
sampled. Signals with frequencies greater than or equal to fNyq are not accurately sampled and
appears as lower frequencies in the discrete sample.
If the frequency used is lower than the Nyquist rate. It will exhibit aliasing. Aliasing is the
presence of unwanted components in the reconstructed signal and it occurs whenever the Nyquist
frequency falls below the signal frequency.
Therefore to get more accurate result, it is necessarily to sample at twice the maximum
frequency of the signal. The sampling theorem state that a signal can be exactly reproduces if it
is sample at a frequency, F where F is greater than twice the maximum frequency in the signal.
By comparing figure 1, 3, 5 and 7 with the trace from the oscilloscope, it is found that
sampling frequency of 2000Hz and 4000 Hz can plot a quite similar graph to the original trace
from the oscilloscope whereas sampling frequencies of 500Hz and 1000 Hz acts otherwise. This
is because aliasing occur in both 500Hz and 1000 Hz sampling frequencies.
CONCLUSION:
From the above calculation using Matlab, it is concluded that aliasing will occur if the
highest signal frequency is greater than the Nyquist frequency.
For this trace from an oscilloscope (Voltage against Time), the sampling frequency
should be more than 2X 645.2Hz (highest signal frequency) to avoid aliasing. The sampling
frequencies of 2000Hz and 4000 Hz are appropriate whereas sampling frequencies of 500Hz and
1000 Hz is not suitable as aliasing occurs.

You might also like