Contents

Lab 4th March 2009

% programmer: Aaron Klapheck
% Date: 4-Mar-09
The_Date = Date, clear, clc
The_Date =

04-Mar-2009

Signal Sampled at 200 Hz in Time Domain

f_s = 200;
f_nyquist = f_s/2;  % By definition
t = 0:.005:2;

x = [18.8440746006299,32.5217073563391,14.0845578219600,67.3713078787912,38.7573152259516,46.4051997090201,48.6358434254759,14.7587532157410,34.6147394438688,32.3124369564006,-0.523976144493897,30.7851849531145,30.4397462483498,10.1875412450886,30.0072250305000,29.4915880274921,53.0824202499390,53.8780157293685,22.7550180093642,50.7228252177921,47.6746766218001,19.3715327937193,32.8185623997922,5.33324164276201,4.27014151460965,19.7436847808281,4.77090854125654,42.7324036773531,22.5396632865396,54.4350000979276,60.2202347282757,13.7944552716891,15.5537486950891,21.6653585538707,6.30033104170894,3.64527737082208,-11.9211468993166,9.63237543311297,15.3481632721713,21.8570504671195,23.3441181883364,38.5554865188891,12.4480303846556,32.9835638634685,27.2974393855672,36.3871851074470,32.4718550918046,30.9650944035237,30.2517756286350,34.7324651486371,-5.44400855357583,0.0363668102424271,-4.54847700013347,5.32601228093711,36.9264053146506,8.34804998013356,23.3275334954696,38.3474485268664,30.4844482955261,13.1314583475321,22.7475636437743,4.70849180850047,11.8779446272085,11.0477340764868,-0.542570859337832,1.53330225542715,7.96114813993138,30.4686421257737,16.4128836524117,30.9689797966567,55.4685491824841,33.9932229107100,0.548672451139622,3.93194164654643,-29.3765626313488,4.76177051014148,-25.5200812749947,-20.3632615850510,19.8782333298125,-3.49554778643113,5.24955790551320,14.7711017278598,14.2514269656918,56.2252741736388,16.4899442531001,20.2758937968615,46.9123146969251,-10.1175502327550,15.5294674781331,28.3452506848044,-19.5471365832393,-8.15517996722276,10.2501603373484,17.8487025606063,29.6824295863362,30.4446758194977,13.8099598525714,45.3354610682157,11.2056397328174,28.1439347185244,6.22879321419589,21.3611052106577,27.6417300476248,14.3839390557404,26.1318870532701,8.24354234034378,32.7839423692161,38.4325601102557,47.3668632271798,43.2026027940773,64.1230355513293,17.0742418522054,30.4278871519756,36.5771889392084,24.6508726162447,31.9581654601909,24.2880330665163,5.32331290011751,26.6961763497527,27.7597751434723,10.9051931648686,60.8376627048870,31.7940713909051,38.1169231181003,59.7983718359901,25.7286847359769,36.0781944446727,29.5960263248757,14.7120389987093,18.2120717268088,0.582201876831467,17.4045656977178,12.1524257689546,18.8834530002380,24.0478239795233,13.1493867774920,20.0497958689006,37.2494281392075,36.2378916320497,27.7657833375557,35.4924713078952,21.0441811613501,39.1721218738030,20.3446039266877,6.85645424052572,17.9294057347267,14.4791749914748,29.1574595993525,46.8705230532277,41.1878288422561,47.2799304511444,14.3305842386236,31.2593830271670,12.0357954930575,-4.57147830051914,2.75697193077863,-2.10937482112403,8.66986103578529,19.7293128967169,18.1248987532167,3.51345310358926,30.5031509188281,0.873937512768501,49.7258274522131,36.3462450654610,35.7321123270716,51.4294003286996,23.8528292753670,2.04225954225979,-13.7240344548670,-12.8754322524298,-9.52473874865404,-13.3950192781315,-11.1605832574946,2.78662519787384,17.4368803754649,28.5195996581053,28.8431212648027,2.31096355554473,35.6343381952438,12.5923219580872,16.9771364778894,28.0565188461905,-11.5352130699011,4.85328781799880,8.24156620051567,8.27806338075396,38.8469878918402,35.3330153004809,6.79534137391544,52.0179077474361,0.0876801920603301,17.0496857665764,29.5619886244865,7.23212047079679,2.06573275557262,7.33562853582066,7.07637949634457,2.78883668616453,-11.1790534359997,9.00271528511610,30.3634892295323,18.3986832908691,65.7138283200769,24.5116359865187,36.3323740579372,30.5387955489513,33.2305408813522,6.22990667883545,21.0063644814592,20.8510316839536,12.4423939309922,-3.61491085690171,1.56442292532698,32.5476132097190,18.9724310648942,26.1868891804045,63.2401648550644,34.9843653145290,59.8091400295055,27.0294922682631,35.2724744464134,11.4477020883125,17.3011372613970,33.4637889162712,21.7837274306129,38.3500985032682,54.7233447802125,55.2243443935364,40.7725071726906,66.2138317277606,26.8993407771626,23.2768168403270,25.8220033024285,11.4826243827676,31.7512016786772,-0.648554752548662,-3.34863293030289,35.6657965672335,15.2287946319351,45.5253640561161,29.2412502314230,43.5678665682623,58.0327525608034,33.6114111706378,31.6571289124633,38.7915019541156,21.2878602882955,27.9841756971643,0.390727962229176,7.85768776505568,24.8674159893131,0.583427142232306,1.05727860505757,29.3315856827120,22.4783531930328,34.5770533993005,43.0898640637236,9.35615720362142,23.8406547919122,32.3759337771038,4.51779145162355,28.5348677075907,-13.2681645768272,8.62830353168272,17.9087635348597,21.1665435594061,8.94472775196971,23.3151754376407,19.7139542182486,19.0960749238070,30.9407556610296,30.8427523037397,12.2019224802984,0.947043219008794,-13.5969329881969,-5.15981703604524,-26.2366947244106,2.34140952091721,8.33912157350271,-1.66236841370291,18.5913273264315,15.9454786140902,31.4899098414442,43.4683407680403,40.9448669697569,18.9983637745334,-2.37797776639121,15.9539269767963,4.20469852570591,8.07034358407462,25.3858222605386,8.58689493769773,15.8744754047960,21.3230062113295,19.7225958812818,45.4820753516009,37.5375740481773,34.6988876999149,40.2126463864463,19.3615406724944,14.1623255608326,38.1502635693579,-7.20900780472887,9.74204118319975,45.2416481376289,10.8463943864314,44.8837389122855,53.2149519605393,53.3216710277144,57.0043837667124,15.1516250964184,13.5800995617332,36.5768186573134,10.0493128902827,37.0332223500295,18.3153111895781,8.52321585079940,24.3188368317613,3.95850884405056,47.9903158395986,47.0290203860356,16.6956454734562,64.5142204366319,50.7411004433161,21.8967561325124,65.9233106268069,18.5657538924871,13.7208531514991,9.80384920638368,-3.05252629890414,10.2869257271024,22.7846669151988,-2.86221496934759,28.3894502673100,16.8985133521169,51.4672914634554,42.0951915767261,35.6905792974750,42.5329182718098,37.2084900190865,-2.11132984478196,45.3515487455470,21.1693689802904,-2.85240321298851,24.2027093894422,6.58411405171648,41.3537048995648,22.8087891848926,31.9714361437547,49.1262528175959,27.8071867227326,21.9738501503459,4.10660810267468,-2.27589948351238,3.68350262122325,-19.3315909044222,-12.6032626450014,7.55580697663693,0.952318208178706,26.3383201573943,37.3947902881638,33.7059155269559,21.5384947099832,21.0543068706541,19.8310443666376,50.2396586035355,18.2752646575204,3.73664656640766,-0.400565485157323,-32.1467526557483,11.8022484872468,-1.89458184320862,-16.1958172412898,16.0363905776218,-5.71685494557578,28.6470249965602,21.8451776065506,26.4583827041781,3.02789336685158,23.6516711882018,3.73905079761969,13.8930466797594,0.224947660221329,12.0623933905835,-1.84616129285923,18.4689091266950,7.55648623734403,17.2701243127050,8.97048725989197,56.1739182049933,1.80887760800201,23.7162596327539,25.7917388065774,2.02793105035609,21.9591766516598,-20.2209845375656,4.05989891805452,14.2415998881149,11.4110899553959,8.49619585127249;];

len_x = length(x)
len_t = length(t)

plot(t, x), ...
    xlabel('time'), ylabel('sampled signal'), ...
    title('Signal Sampled at 200 Hz in Time Domain')
len_x =

   401


len_t =

   401

Frequency Content of Signal Sampled at 200 Hz.

% Decide which exponant of 2 to use to make the fft go faster.
% This involves changing the sample frequecy to a larger number.
% This change of the sample frequency will change the look of the fft plot
% but the peaks which tell us where the natural frequencies are present will
% not change depending on fft_freq. To test this out set fft_freq equal to
% 100 or any other similar value and view the graph before and after.
exp = log(f_s)./log(2);
fft_freq = 2^(ceil(exp));


x_fft = fft(x, fft_freq);
x_fft = abs(x_fft);     % Eliminate immaginary componant
x_fft = x_fft(1:(fft_freq/2)); % Plot from 0 to .5*f_s

frequency_vector = f_nyquist*linspace(0,1,(fft_freq/2));


plot(frequency_vector, x_fft), ...
    xlabel('Frequency'), ylabel('Frequency Content'), ...
    title('Frequency Content of Signal Sampled at 200 Hz')

Filtered Signal Sampled at 200 Hz in Time Domain

% The data is filted so when we sample the data at 100 Hz the higher
% frequencies don't get reflected back into the signal.

[B, A] = cheby1(10,.5,.4);

y = filter(B,A,x);

plot(t, y), ...
    xlabel('time'), ylabel('filtered signal'), ...
    title('Filtered Signal Sampled at 200 Hz in Time Domain')

Frequency Content of Filtered Signal Sampled at 200 Hz.

exp = log(f_s)./log(2);
fft_freq = 2^(ceil(exp));


y_fft = fft(y, fft_freq);
y_fft = abs(y_fft);     % Eliminate immaginary componant
y_fft = y_fft(1:(fft_freq/2)); % Plot from 0 to .5*f_s

frequency_vector = f_nyquist*linspace(0,1,(fft_freq/2));


plot(frequency_vector, y_fft), ...
    xlabel('Frequency'), ylabel('Frequency Content'), ...
    title('Frequency Content of Filtered Signal Sampled at 200 Hz')

Filtered Signal Re-sampled at 100 Hz in Time Domain

f_s = 100;
f_nyquist = f_s/2;  % By definition
t = .01:.01:2;

len_y = length(y)
len_t = length(t)

for k = 2:2:400
    z(k/2) = y(k);
end

len_z = length(z)

plot(t, z), ...
    xlabel('time'), ylabel('filtered signal'), ...
    title('Filtered Signal Re-sampled at 100 Hz in Time Domain')
len_y =

   401


len_t =

   200


len_z =

   200

Frequency Content of Filtered Signal Re-sampled at 100 Hz.

exp = log(f_s)./log(2);
fft_freq = 2^(ceil(exp));


z_fft = fft(z, fft_freq);
z_fft = abs(z_fft);     % Eliminate immaginary componant
z_fft = z_fft(1:(fft_freq/2)); % Plot from 0 to .5*f_s

frequency_vector = f_nyquist*linspace(0,1,(fft_freq/2));


plot(frequency_vector, z_fft), ...
    xlabel('Frequency'), ylabel('Frequency Content'), ...
    title('Frequency Content of Filtered Signal Re-sampled at 100 Hz')