Anton LeKang
ECE 3512: Signals – Continuous and Discrete
Department of Electrical and Computer Engineering, Temple University, Philadelphia, PA 1912
I.
PROBLEM STATEMENT
The objective of this lab is to get a basic understanding of processes and reading data in MATLAB. This will be
achieved by plotting the known closing value of Google stock and an audio file. The plots will be done in MATLAB
and observations on the plots can be made based on the line of the curve. Furthermore, statistical data can be
computed using simple commands such as min, max, mean, and variance. Looking at the graphs, and statics will
help make a conclusion for data. Variance will play a key role in the project.
II.
APPROACH AND RESULTS
Part 1: Google Stock
The first part of this lab looks at the high value of the google stock. Figure 1 below shows the value of the stock
starting at day one in 2004 to the current date. The price the stock has gone up drastically over the span of ten years.
The table below shows the min, max, mean, median and variance of the google stock. A good value to use to predict
the value of the stock would be the slope. The mean would be to low, and the max would be to high.
Google Stocks
Min Value($)
49.95
Max Value($)
609.47
Mean
286.896
Median
264.89
Variance
1.62E+04
Table 1
Figure 1
Part 2: Audio File
The second part of this computer assignment looks at the values of the audio file. Figure 2 below shows the
amplitude of the audio through entire index of the file. This file is extremely different from the google figure
because a linear line would not fit with the sample. Also as seen in table 2 the values of the min, max, mean,
median, and variance are significantly different than from table 3.
Min Value
Max Value
Mean
Median
Variance
Audio File
-14993
10104
-0.3891
83
4.13E+06
Table 2
Figure 2
Part 3: Data with different values for frame and window
The third part of this computer assignment looks at the data samples from above but used different value for the
fame and window. When the frame is adjusted, that represents where each part of the data is taken from. So if the
fame is 8, after every 8 points a data point would be taken. The window looks at the number data points taken at the
specific data point from the frame. So if the frame is 8 and window is 10, the data would be taken at point 8-5 to 8+5
for a total of 10 data points. Figure 3-6 show the google data sampled at different frames and windows. Figure 6-9
show the audio file sampled at different frames and windows.
Figure 3
Figure 4
Figure 5
Figure 6
Figure 7
Figure 8
Figure 9
Google Stock Prices
N Value M Value Mean
8
2
1.83E+04
8
8
1.84E+04
8
14
1.83E+04
8
30
1.84E+04
30
2
1.86E+04
30
8
1.86E+04
30
14
1.86E+04
30
30
1.86E+04
Variance
1.51E+07
1.51E+07
1.50E+07
1.48E+07
7.20E+06
7.22E+06
7.23E+06
7.37E+06
Audio File
N Value M Value
Mean
160
40
1.676E+03
160
80
1.677E+03
160
160
1.676E+03
240
40
1.683E+03
240
80
1.683E+03
240
160
1.686E+03
Variance
1.329E+06
1.328E+06
1.330E+06
1.305E+06
1.306E+06
1.311E+06
As seen in the figures above the smoothness of the line changes with different window and frame values. The
roughest line is when the window value is at its highest and the frame is at its lowest. This is seen in the first plot of
figure 6 and 9. When the line is the roughest the variance is the largest. The smoothest line is when the value of the
window (M) is the smallest and the value of the frame(N) is the largest, this is seen in the second plot of figure 3 and
7. When the line is the smoothest, this is also when the variance is the smallest. These plots can be compared o the
basic plots of the google stock and audio file. When the line is smooth, that mostly correlates with figure 1, the
google stock. When the line is bumpy, that correlates with figure 2, the audio file.
III.
Part 1:
MATLAB CODE
mean(Close1)
min(Close1)
max(Close1)
nanvar(Close1)
median(Close1)
figure(1)
plot(Close1)
%slope gives best value of overall close number
title('Google High Stock Value vs Time');
xlabel('Time since open for sale');
ylabel('Price of Stock');
fp = fopen('rec_01_speech.raw','r');
% load the data:
% It is 16-bit sampled data, so we must load it as short integers.
%
sig = fread(fp,inf,'int16');
% close the file:
% It is never a good idea to leave open files since they consume operating
% system resources and can get corrupted occassionally.
%
fclose(fp);
mean(sig)
min(sig)
max(sig)
nanvar(sig)
median(sig)
figure(2)
plot(sig)
title('Audio File');
xlabel('Index');
ylabel('Aplitude');
This code shows both the Google stock and the audio file loaded into Matlab. Then simple instructions are used to
fine the mean, min, max, variance, and median. Also each group of data is plotted in a different figure.
Part 2:
function rms=rec02_v05
% close open sessions
%
close all;
% define two key parameters:
% M: frame duration in samples - how often we compute an output
% N: window duration in samples - how much data we use in each computation
%
M = [ 40, 80, 160];
N = [ 160, 240];
% open the file:
% We assume the data is in a file "rec_01_speech.raw". This should be
% parameterized, but we hardcode it here to keep things simple.
%
fp = fopen('rec_01_speech.raw','r');
% load the data:
% It is 16-bit sampled data, so we must load it as short integers.
%
sig = fread(fp,inf,'int16');
% close the file:
% It is never a good idea to leave open files since they consume operating
% system resources and can get corrupted occassionally.
%
fclose(fp);
% create a matrix to store the output
%
rms = zeros(length(M), length(N), length(sig));
mn = zeros(length(M), length(N));
vr = zeros(length(M), length(N));
% loop over the a set of frame/window combinations.
%
for m = 1:length(M)
% set up a plotting window and label it
%
h1 = figure('name', 'rms plot', 'numbertitle', 'off');
for n = 1:length(N)
% call a function to compute the rms vector
%
rms(m,n,:) = compute_rms(sig, M(m), N(n));
mn(m, n) = mean(rms(m, n, :))
vr(m, n) = nanvar(rms(m, n, :))
% label the plot:
% include information about the parameters for each plot
%
figure(h1);
str = sprintf('frame duration: %d
window duration = %d', M(m),
N(n));
subplot( 1+length(N), 1, n );
% plot the rms contour
%
plot(squeeze(rms(m,n,:)));
% label the axes
%
title(str);
xlabel('time');
ylabel('rms');
end
% plot the signal:
% this is the last plot on the page
%
figure(h1);
subplot( 1+length(N),1,n+1);
plot(sig);
% label the axes
%
title('Input Signal');
xlabel('time');
ylabel('amplitude');
end
rms_out = squeeze(rms)';
% exit gracefully
%
end
% function: compute_rms
%
% arguments:
% sig_a: the input signal (input)
% fdur_a: the frame duration in samples (input)
% wdur_a: the window duration in samples (input)
%
% return:
% rms: a vector of rms values (output)
%
% Note that this function returns the rms counter as a sampled data
% signal that is the same length as the input signal. This is wasteful
% of memory, but makes it easy to produce a time-aligned plot.
%
% This algorithm computes the sum of squares for wdur_a samples.
%
function rms_full = compute_rms(sig_a, fdur_a, wdur_a)
% declare local variables
%
sig_wbuf = zeros(1, wdur_a);
num_samples = length(sig_a);
num_frames = 1+round(num_samples / fdur_a);
rms_full = zeros(length(sig_a),1);
% loop over the entire signal
%
for i = 1:num_frames
% generate the pointers for
% the center tells us where
% indicate the reach of our
%
n_center = (i - 1) * fdur_a
n_left = n_center - (wdur_a
n_right = n_left + wdur_a -
how we will move through the data signal.
our frame is located and the ptr and right
window around that frame
+ (fdur_a / 2);
/ 2);
1;
% when the pointers exceed the index of the input data we won't be
% adding enough samples to fill the full window. to solve this zero
% stuffing will occur to ensure the buffer is always full of the same
% number of samples
%
if( (n_left < 0) || (n_right > num_samples) )
sig_wbuf = zeros(1, wdur_a);
end
% transfer the data to this buffer:
% note that this is really expensive computationally
%
for j = 1:wdur_a
index = n_left + (j - 1);
if ((index > 0) && (index <= num_samples))
sig_wbuf(j) = sig_a(index);
end
end
% square the signal. divide it by the number of samples used and sum
% the result to build the value for that frame
%
rms = sqrt( (1 / wdur_a) * sum(sig_wbuf.^2));
for j = 1:fdur_a
index = n_center + (j - 1) - (fdur_a/2);
if ((index > 0) && (index <= num_samples))
rms_full(index) = rms;
end
end
end
end
This code computes the rms value for the data based on the specific M and N values. Those values are defined at the
top and then used with a loop to make the program run the desired length. Inside the loop, a function compute_rms,
variance, and mean is called on. The program then calculates the rms value, the variance, and the mean based on the
specific M and N values. The rms value is then plotted verses time to observe what happens when there are different
M and N values.
IV.
CONCLUSIONS
Guessing the change in stock prices is extremely difficult, but using statistical data can help point in a direction to go.
When looking at the Google stock prices the line was much smoother and not bumpy. When looking at the audio file,
the line was very rough and bounced all over this place. This is also seen with the variance value. The lower of the
two variance values was the Google graph as seen in table 1. This directly correlates to both of the files when a
specific sample was looked at. When the sample window and frame created the smoothest graph this also had the
smallest variance. Alternately, when the sample window and frame created the roughest graph the value of the
variance was the highest.
© Copyright 2026 Paperzz