Signals
Outline Announcements: Binary Files Signals, signals, signals Homework III: due Today by 5, by e-mail for P.4: n can be anything you want HW IV available soon. Binary Files Signals, signals, signals
Binary Basics All computer files are “binary”, that is composed of 0’s and1’s When the computer reads ASCII files, it takes chunks of 8 bits (1 byte) and looks up the character To save pi to 16 digits takes 18 bytes in ASCII If you save the 1’s and 0’s that correspond to the double precision value of pi, that takes only 8 bytes
Problem with Binary Files You can’t just look at them You must know exactly how they were created integers vs. floating point single precision vs. double precision signed vs. unsigned
Reading Binary files fid=fopen(fname,’r’);%’r’ = read binary A=fread(fid,N,precision) N=number of data points, use Inf to read everything precision is how the file was created “uint64” is an unsiqned integer saved in 64 bits “double” is a double
Free advice (you get what you pay for) The only reasons to use binary files are someone gives you one you enjoy frustration and pain you’re too poor (or cheap) to buy a new hard drive
Writing .mat files outside Matlab .mat files are a great format for storing data easy to use with Matlab multiple variables / file compact It is possible to save data to .mat files from C/C++ programs using Matlab C/C++ library For more info: See Lecture 09 notes Take CIS404!
Signals Signals are time series Examples: Sound (pressure vs. time) Earthquake (displacement vs. time) S&P 500 ($/share vs. time) Signals are usually continuous, but we sample them at discrete times regular vs. irregular sampling Sampling frequency
Signal Basics A phi 1/f Simplest signal: s(t)=A*sin(2*pi/f*(t-phi)) A=amplitude f=frequency phi=phase A,f,phi summarize signal A phi 1/f
Fourier Analysis f=(k-1)/N Real signals are more complicated Fourier proved that any function can be represented as sum of sines & cosines of various frequencies: f=(k-1)/N
Fourier Analysis f=8 s1(t) s2(t) f=1/2 0.5*s1(t) +s2(t)
Signals in MATLAB In MATLAB, a signal is a vector of numbers s Matlab’s signal processing functions assume s was sampled regularly s is complete (no missing data, nans, -999’s etc.) You must know sampling frequency f
Fourier Analysis Fourier transform (fft) Finds amplitudes over a range of frequencies amp=fft(s); If s is n-by-1, amp will be n-by-1 and complex First half of amp contains info: a=real([amp(1),2*amp(2:n/2)])/n; %cos coefs. b=imag([0, -2*amp(2:n/2)])/n; %sin coefs. f= (0:(n/2-1))/n/(t(2)-t(1)); %frequencies F=2*pi*t(:)*f; s2=cos(F)*a(:)+sin(F)*b(:); %original signal
Fourier Analysis What’s the point? fft transforms from time-domain to frequency domain Energy at frequency j = sqrt(a(j).^2+b(j).^2) Plot energy vs. f Peaks are important f’s Could remove energy at some frequencies
Signal Processing Toolbox Matlab’s Signal Processing Toolbox contains lots of functions for working with digital signals transforms beyond fft filter design, implementation spectral analysis Check on-line help for more info Need to understand theory better than I do!