User Tools

Site Tools


ecen_380_assignments

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
ecen_380_assignments [2015/10/16 10:02]
petersen
ecen_380_assignments [2016/05/16 10:02] (current)
a_west [Chapter 1: LTI Systems]
Line 1: Line 1:
-===== ECEn 380 MATLAB Assignments =====+====== ECEn 380 MATLAB Assignments =====
 + 
 +Welcome to the 380 section for the ECEn MATLAB wiki. For a brief refresher on MATLAB, [[ matlab_guide | look here.]] 
 + 
 +The syntax for the problem numbers is such: 
 +<​code>​ 
 +[Language][Class].[Book authors][Chapter].[Section].[Problem] 
 +</​code>​ 
 + 
 +Thus for help on problem "​MT380.UY6.8.1",​ for example, you can refer to section 6-8 in the textbook (page 279).
  
 <ifauth, @admin> <ifauth, @admin>
Line 6: Line 15:
  
 ^ Chapter ^  Assignments ​                                            ​^ ​ Course Topic                   ^ MATLAB Topic                                                                                                                                                                  ^          ^ Chapter ^  Assignments ​                                            ​^ ​ Course Topic                   ^ MATLAB Topic                                                                                                                                                                  ^         
-| Ch 1    | [[ecen_380_assignments#​MT380.UY1 ​MT380.UY1 ​]]           ​| ​Signals ​                                                                                                                                                                                                      ​+| Ch 1    | [[ecen_380_assignments#​Chapter 1: Signals ​Signals ​]]           ||| 
-| :::     | [[ecen_380_assignments#​MT380.UY1.2.1 ​| MT380.UY1.2.1 ]]   | Signal Transformations ​         | [[matlab_guide#​Array Operations| Array Operations]],​[[matlab_guide#​Graph Function| plot]] ,​[[matlab_guide#​Annotation| Graph Annotation]] ,​[[matlab_guide#​Figures| Figures]] ​  |  +| :::     | [[ecen_380_assignments#​Signal Transformations ​| MT380.UY1.2.1 ]]   | Signal Transformations ​         | [[matlab_guide#​Array Operations| Array Operations]],​[[matlab_guide#​Graph Function| plot]] ,​[[matlab_guide#​Annotation| Graph Annotation]] ,​[[matlab_guide#​Figures| Figures]] ​  |  
-| :::     | [[ecen_380_assignments#​MT380.UY1.5.1 ​| MT380.UY1.5.1 ]]   | Signal Power and Energy ​        ​| ​                                                                                                                                                               sum (used to evaluate numerical integrals) ​          | +| :::     | [[ecen_380_assignments#​Signal Power and Energy ​| MT380.UY1.5.1 ]]   | Signal Power and Energy ​        ​| ​                                                                                                                                                               sum (used to evaluate numerical integrals) ​          | 
-| Ch 2    | [[ecen_380_assignments#​MT380.UY2 ​MT380.UY2 ​]]           ​| ​LTI Systems ​                                                                                                                                                                                                  ​|+| Ch 2    | [[ecen_380_assignments#​Chapter 2: LTI Systems ​Linear Time-Invariant (LTI) Systems ​]]           |||
 | :::     | [[ecen_380_assignments#​MT380.UY2.3.0 | MT380.UY2.3.0 ]]   | Convolution ​ Aid                |                                                                                                                                                                               ​| ​ | :::     | [[ecen_380_assignments#​MT380.UY2.3.0 | MT380.UY2.3.0 ]]   | Convolution ​ Aid                |                                                                                                                                                                               ​| ​
 | :::     | [[ecen_380_assignments#​MT380.UY2.3.1 | MT380.UY2.3.1 ]]   | Convolution with function files |  [[matlab_guide#​Function Files| Function Files]], [[matlab_guide#​For-loop| For-loop]] ​                                                                                        ​| ​ | :::     | [[ecen_380_assignments#​MT380.UY2.3.1 | MT380.UY2.3.1 ]]   | Convolution with function files |  [[matlab_guide#​Function Files| Function Files]], [[matlab_guide#​For-loop| For-loop]] ​                                                                                        ​| ​
Line 16: Line 25:
 | :::     | [[ecen_380_assignments#​MT380.UY2.8.1 | MT380.UY2.8.1 ]]   | Imp.Resp. of 2nd Ord LCCDEs ​    ​| ​   [[matlab_guide#​Roots| Roots]] ​                                                                                                                                             |  | :::     | [[ecen_380_assignments#​MT380.UY2.8.1 | MT380.UY2.8.1 ]]   | Imp.Resp. of 2nd Ord LCCDEs ​    ​| ​   [[matlab_guide#​Roots| Roots]] ​                                                                                                                                             | 
 | :::     | [[ecen_380_assignments#​MT380.UY2.9.1 | MT380.UY2.9.1 ]]   | Car Suspension ​                 |    Review ​            ​ | | :::     | [[ecen_380_assignments#​MT380.UY2.9.1 | MT380.UY2.9.1 ]]   | Car Suspension ​                 |    Review ​            ​ |
-| Ch 3    | [[ecen_380_assignments#​MT380.UY3 ​MT380.UY3 ​]]           ​| ​Laplace Transform ​                                                                                                                                                                                            ​|+| Ch 3    | [[ecen_380_assignments#​Chapter 3: Laplace Transform ​Laplace Transform ​]]           |||
 | :::     | [[ecen_380_assignments#​MT380.UY3.2.1 ​ | MT380.UY3.2.1 ]]  | Poles and Zeros                 ​| ​   [[matlab_guide#​Mesh| Mesh]] ​                                    ​  ​   | | :::     | [[ecen_380_assignments#​MT380.UY3.2.1 ​ | MT380.UY3.2.1 ]]  | Poles and Zeros                 ​| ​   [[matlab_guide#​Mesh| Mesh]] ​                                    ​  ​   |
-| Ch 4    | [[ecen_380_assignments#​MT380.UY4 ​MT380.UY4 ​]]           ​| ​App. of the L-Transform ​                                                                                                                                                                                      ​|+| Ch 4    | [[ecen_380_assignments#​Chapter 4: Applications of the Laplace Transform ​Applications of the Laplace Transform ​]]           |||
 | :::     | [[ecen_380_assignments#​MT380.UY4.5.1 ​ | MT380.UY4.5.1 ]]  | Op-Amp Circuits ​                ​| ​  ​Review ​                                                                                                                                                                     | | :::     | [[ecen_380_assignments#​MT380.UY4.5.1 ​ | MT380.UY4.5.1 ]]  | Op-Amp Circuits ​                ​| ​  ​Review ​                                                                                                                                                                     |
-| Ch 5    | [[ecen_380_assignments#​MT380.UY5 ​MT380.UY5 ​]]           ​| ​Fourier Analysis Techniques ​                                                                                                                                                                                  ​|+| Ch 5    | [[ecen_380_assignments#​Chapter 5: Fourier Analysis Techniques ​Fourier Analysis Techniques ​]]           |||
 | :::     | [[ecen_380_assignments#​MT380.UY5.4.1 | MT380.UY5.4.1 ]]   | Fourier Series Coefficients ​    ​| ​  ​[[matlab_guide#​For-loop| For-loop]] ​                                                                                                                                        | | :::     | [[ecen_380_assignments#​MT380.UY5.4.1 | MT380.UY5.4.1 ]]   | Fourier Series Coefficients ​    ​| ​  ​[[matlab_guide#​For-loop| For-loop]] ​                                                                                                                                        |
 | :::     | [[ecen_380_assignments#​MT380.UY5.12.1 | MT380.UY5.12.1 ]] | Circuit Analysis with Fourier ​  ​| ​  ​Review ​                                                                                                                                                                     | | :::     | [[ecen_380_assignments#​MT380.UY5.12.1 | MT380.UY5.12.1 ]] | Circuit Analysis with Fourier ​  ​| ​  ​Review ​                                                                                                                                                                     |
-| Ch 6    | [[ecen_380_assignments#​MT380.UY6 ​MT380.UY6 ​]]           ​| ​Apps of the Fourier Trans. ​     ​                                                                                                                                                                              ​|+| Ch 6    | [[ecen_380_assignments#​Chapter 6: Applications of the Fourier Transform ​Applications of the Fourier Transform ​]]           |||
 | :::     | [[ecen_380_assignments#​MT380.UY6.8.1 | MT380.UY6.8.1 ]]   | Butterworth Filters ​            ​| ​ Review ​                                                                                                                                                                      | | :::     | [[ecen_380_assignments#​MT380.UY6.8.1 | MT380.UY6.8.1 ]]   | Butterworth Filters ​            ​| ​ Review ​                                                                                                                                                                      |
 |    :::  | [[ecen_380_assignments#​MT380.UY6.12.1 | MT380.UY6.12.1 ]] | Sampling Theorem ​               |  [[matlab_guide#​fopen| fopen]],​[[matlab_guide#​fscanf| fscanf]],​[[matlab_guide#​fclose| fclose]], [[matlab_guide#​interp| Interpolate]],​[[matlab_guide#​sound| sound]] ​           | |    :::  | [[ecen_380_assignments#​MT380.UY6.12.1 | MT380.UY6.12.1 ]] | Sampling Theorem ​               |  [[matlab_guide#​fopen| fopen]],​[[matlab_guide#​fscanf| fscanf]],​[[matlab_guide#​fclose| fclose]], [[matlab_guide#​interp| Interpolate]],​[[matlab_guide#​sound| sound]] ​           |
-| Ch 7    | [[ecen_380_assignments#​MT380.UY7 | MT380.UY7 ]]           | Discrete-Time Signals and Syst  ​                                                                                                                                                                              ​|+| Ch 7    | [[ecen_380_assignments#​Chapter 7: Discrete-Time Signals and Systems ​| Discrete-Time Signals and Systems ]]           |||
 | :::     | [[ecen_380_assignments#​MT380.UY7.2.1 | MT380.UY7.2.1 ]]   | D-Time Signal Functions ​        ​| ​  ​rat ​                                                                                                                                                                        | | :::     | [[ecen_380_assignments#​MT380.UY7.2.1 | MT380.UY7.2.1 ]]   | D-Time Signal Functions ​        ​| ​  ​rat ​                                                                                                                                                                        |
 | :::     | [[ecen_380_assignments#​MT380.UY7.13.1 | MT380.UY7.13.1 ]] | D-Time Fourier Series ​          ​| ​ Review ​                                                                                                                                                                      | | :::     | [[ecen_380_assignments#​MT380.UY7.13.1 | MT380.UY7.13.1 ]] | D-Time Fourier Series ​          ​| ​ Review ​                                                                                                                                                                      |
 +| :::     | [[ecen_380_assignments#​MT380.UY7.15.1 | MT380.UY7.15.1 ]] | Discrete Fourier Transform ​     |  Review ​                                                                                                                                                                            ​| ​                
 +| Extras ​ | [[ecen_380_assignments#​Music Harmonics | Music Harmonics ]] | FFT,Fourier Series Coeff        | FFT Plot
  
  
 +====== Chapter 1: Signals ======
  
-===== Signal ​Transformation ​=====+===== Signal ​Transformations ​=====
  
 ==== MT380.UY1.2.1 ====  ==== MT380.UY1.2.1 ==== 
  
-== Discription ​==+== Description ​==
  
-<​file>​+<​file ​| MT380.UY1.2.1.txt ​>
  ​Signal Transformations  ​Signal Transformations
  
Line 110: Line 122:
 == Solution == == Solution ==
  
-{{:​380matlab:​ch1:​ul_1_2_signaltransformations.m|}}+{{:​380matlab:solutions:​ch1:​ul_1_2_signaltransformations.m|}}
  
 </​ifauth>​ </​ifauth>​
Line 179: Line 191:
 == Solution == == Solution ==
  
-{{:​380matlab:​ch1:​uy_1_5_1_poweravg.m|}}+{{:​380matlab:solutions:​ch1:​uy_1_5_1_poweravg.m|}}
  
 </​ifauth>​ </​ifauth>​
  
 +====== Chapter 2: LTI Systems ======
  
 ===== Convolution Aid ===== ===== Convolution Aid =====
Line 335: Line 348:
 == Solution == == Solution ==
  
-{{:​380matlab:​ch2:​h_t.m|}} \\  +{{:​380matlab:solutions:​ch2:​h_t.m|}} \\  
-{{:​380matlab:​ch2:​x_t.m|}} \\  +{{:​380matlab:solutions:​ch2:​x_t.m|}} \\  
-{{:​380matlab:​ch2:​mt380_uy2_3_1_convolutionff.m|}} ​ \\+{{:​380matlab:solutions:​ch2:​mt380_uy2_3_1_convolutionff.m|}} ​ \\
  
 </​ifauth>​ </​ifauth>​
Line 501: Line 514:
 == Solution == == Solution ==
  
-{{:​380matlab:​ch2:​convolution.m|}}+{{:​380matlab:solutions:​ch2:​convolution.m|}}
  
 </​ifauth>​ </​ifauth>​
Line 561: Line 574:
 == Solution == == Solution ==
  
-{{:​380matlab:​ch2:​uy2_5_1_convolutionproperties.m|}}+{{:​380matlab:solutions:​ch2:​uy2_5_1_convolutionproperties.m|}}
  
 </​ifauth>​ </​ifauth>​
Line 662: Line 675:
  
 == Solution == == Solution ==
-{{:​380matlab:​ch2:​uy2_8_1_impresp2ndorder.m|}}+{{:​380matlab:solutions:​ch2:​uy2_8_1_impresp2ndorder.m|}}
  
 </​ifauth>​ </​ifauth>​
Line 696: Line 709:
  
 == Solution == == Solution ==
-{{:​380matlab:​ch2:​uy2_9_1_eulermethod2ndorder.m|}}+{{:​380matlab:solutions:​ch2:​uy2_9_1_eulermethod2ndorder.m|}}
  
 </​ifauth>​ </​ifauth>​
 +
 +====== Chapter 3: Laplace Transform ======
  
 ===== Laplace Transform Aid ===== ===== Laplace Transform Aid =====
Line 794: Line 809:
 == Solution == == Solution ==
  
-{{:​380matlab:​ch3:​uy3_1_1_sdomaingraph.m|}}+{{:​380matlab:solutions:​ch3:​uy3_1_1_sdomaingraph.m|}}
  
 </​ifauth>​ </​ifauth>​
 +
 +====== Chapter 4: Applications of the Laplace Transform ======
  
 ===== Op-Amp Circuits ===== ===== Op-Amp Circuits =====
Line 837: Line 854:
 == Solution == == Solution ==
  
-{{:​380matlab:​ch4:​uy4_5_1_op_ampcircuit.m|}}+{{:​380matlab:solutions:​ch4:​uy4_5_1_op_ampcircuit.m|}}
  
 </​ifauth>​ </​ifauth>​
 +
 +====== Chapter 5: Fourier Analysis Techniques ======
  
 ===== Fourier Series Coefficients ===== ===== Fourier Series Coefficients =====
Line 1010: Line 1029:
  
 == Solution == == Solution ==
-{{:​380matlab:​ch5:​uy5_4_1_fourierseriescoefficients.m|}}+{{:​380matlab:solutions:​ch5:​uy5_4_1_fourierseriescoefficients.m|}}
  
 </​ifauth>​ </​ifauth>​
Line 1040: Line 1059:
  
 == Solution == == Solution ==
-{{:​380matlab:​ch5:​uy5_12_1_circuitanalysisfouriertransform.m|}} +{{:​380matlab:solutions:​ch5:​uy5_12_1_circuitanalysisfouriertransform.m|}} 
-{{:​380matlab:​ch5:​h_t.m|}} +{{:​380matlab:solutions:​ch5:​h_t.m|}} 
-{{:​380matlab:​ch5:​x_t.m|}}+{{:​380matlab:solutions:​ch5:​x_t.m|}}
  
 </​ifauth>​ </​ifauth>​
  
 +====== Chapter 6: Applications of the Fourier Transform ======
  
 ===== Butterworth Filters ===== ===== Butterworth Filters =====
Line 1053: Line 1073:
  ​UY6_3_1_Active Filters  ​UY6_3_1_Active Filters
  
- ​Objective: ​model a second order butterworth filter ​using an approximated + ​Objective: ​Model a second order butterworth filter ​and test it by passing 
- impulse response in order to see its effectiveness in filtering ​signals+ ​signals ​at various frequencies through the filter. Since this is 
 + a design problem, and you have already covered butterworth filters in 
 + lab, less code will be given.
  
  ​functions:​ review roots  ​functions:​ review roots
  
  ​Exercise:​ This exercise will be broken down into several parts  ​Exercise:​ This exercise will be broken down into several parts
- part 1) in this first part you will create a low pass filter ​based on a + 
-       ​second order butterworth ​filter. ​Create it in a function file that + part 1) Creating the impulse response of the low pass filter 
-       takes in two parameters (corner frequency in Hz and time interval/step). + 
-       ex. functionName(fc , time_interval). The function ​file will return +         You will model a second order lowpass ​filter ​using the butterworth  
-       ​the impulse response h(tin an array. Make the time length of the +         ​designThe filter will be created ​in a separate ​function file 
-       impulse response at least 10*tauusually 5 tau is sufficient but +         because you will use this filter ​in another MATLAB exercise. The function 
-       let's be extra precise. ​ +         will take two arguments: the corner frequency in Hz and the 
-       a) look at table 6-3 on page 285 in your book. This will help you +         time-step (which we'll call "​dt"​used in creating the signals. 
-          ​find ​the coefficients ​for your transfer function. Look at example +         The function will 
-          ​6-10 in the book if you need more help. When designing this +         return an array that represents ​the impulse response ​of the 2nd 
-          ​transfer function, ​H(jw), make sure you have a dc gain of 1+         order lowpass filter. It is crucial that the dt used in 
-       blook at section ​2-7.in your book to remember how to turn a +         ​creating the filter is the same dt used to create the signal that 
-          transfer function into a second order differential equation. +         it is filtering. Below is the function declaration that is placed 
-       c) review ​section 2-to transform ​your second order differential +         in the function file that creates the filter. 
-          equation into an impulse responseh(t). + 
-       If done correctlyyou only need to pass the function file fc and +             ​function [h] = h_t(fc,dt) 
-       ​the time_interval ​and the function file will return an array + 
-       representing ​h(t). +         ​Inside ​the function file you will need to convert ​the passed 
- part 2) Now that you have constructed your filter ​it'​s ​time to test it.  +         in frequency in Hertz into radians per second: 
-       ​acreate ​a low pass filter ​with an fc of 400 Hz using part 1 of + 
-          ​the assignmentUse an appropriate ​time interval. time_interval +             wc = 2*pi*fc
-          <<​ tauand time_interval << ​1/largest(f)look at part b for + 
-          ​largest 4+         Section ​6-in your text book shows how to create the frequency 
-       bcreate three different signals of the form x = 5*cos(2*pi*f*t) +         ​response,​ H(jw), for a second order butterworth lowpass filter 
-          the three signals ​will have different frequencies:​ f1 100f2 +         using the specified frequencyFor aid, refer to Table 6-3 (page 285) 
-          400f3 4000 Hz. When creating these signalsuse the same +         to obtain ​the pole locations and coefficients ​a1 and a2 that you 
-          time_interval in part abut have the time array last for 1 s. +         will use to design ​your butterworth filter. Look at example 6-10 
-       cConvolve each signal with h(tto simulate filtering. ​ +         in your book if you need more help. The frequency response should 
-          y = x(t)*h(t), * denotes convolution. ​ +         look like the equation below. ​ (Remember that you can get the 
-       d) plot h(t), and the three filtered ​signals.+         ​frequency response from H(sby substituting s = jw.) 
 + 
 +             H(jw= wc^2/(s^2 + a1*wc*s + a2*wc^2) ​        (1) 
 + 
 +         The frequency response needs to be changed into its time equivalent  
 +         ​impulse response h(t)This will be done in two steps. In the first  
 +         step the transfer function ​needs to be changed ​into a second order  
 +         differential equation. ​If you have forgotten how to do this, refer 
 +         to section 2-7.3. The second order differential equation should 
 +         be of the form below. 
 + 
 +         ​d^2y/​dt^2 + a1*dy/dt + a2*y(t) = b2*x(t) ​          (2) 
 +           - note, the coefficients a1 and a2 are not the same a1 and a2 
 +             ​coefficients in equation (1). 
 + 
 +         The second step is to transform ​the second order differential 
 +         ​equation into the impulse response h(t). Refer back to section 
 +         2-8. First calculate the poles (p1and p2) as shown in equation 
 +         2.126 (pg 65) in your book. 
 + 
 +         p = roots([1 a1 a2]); 
 +           - note, a1 and a2 refer to the coefficients from equation (2). 
 + 
 +         ​Second,​ form the time array that will be used. The time array 
 +         will start from t =0s, increment by dt, and end at t = 10*tau. 
 +         Tau is the time constant obtained from the roots. The roots have  
 +         the basic form p = -sigma +/- j*wd where sigma represents the real 
 +         ​part ​and wd represents ​the complex part. Sigma is related to your 
 +         time constant, tau. 
 + 
 +           tau = 1/​sigma ​                                (3) 
 + 
 +         So figure out what your sigma is, and insert in your Matlab code: 
 + 
 +           tau = INSERT CODE HERE;   this is the code 
 + 
 +         Once tau is obtained, the time array can be created. 
 + 
 +              time parameters 
 +             ​time_beg = 0; 
 +             ​time_end = 10*tau 
 +             t = time_beg:​dt:​time_end - dt;  time array 
 + 
 +         The reason why we are using tau is because the impulse response 
 +         in non-finite. ​ However, its limit as t -> inf+ is 0. 
 + 
 +           lim h(t) = 0 
 +           t -> inf+ 
 + 
 +         After about 5*tau the value of h(t) (or h(5*tau)) is almost zero 
 +         since the impulse response ​will decay exponentially. We are going 
 +         to t = 10*tau just to make sure that the behavior response is 
 +         ​completely captured. Also, since h(t) is causal, the time array 
 +         can start at t =0. 
 + 
 +         Now that we have the coefficients,​ roots, and the time array, 
 +         h(t) can be constructed using equation 2.136 in your book (pg 
 +         ​66). 
 + 
 +         To make things simple, below is a compilation of the above code 
 +         that you will put in your function file that creates the low pass 
 +         ​filter impulse response. 
 + 
 + 
 +             ​function [h] = h_t(fc,​dt) 
 +             wc = 2*pi*fc; ​ the corner frequency in rads/s 
 +              a1_bwf and a2_bwf are coefficients obtained from table 6-3 in the book (pg 285). 
 +             ​a1_bwf = INSERT VALUE;  
 +             ​a2_bwf = INSERT VALUE; 
 +              a1 and a2 are coefficients associated with the 2nd order 
 +              differential equation. 
 +             a1 = INSERT CODE; 
 +             a2 = INSERT CODE; 
 +             r = roots([1, a1, a2]);  obtain the roots of the polynomial.  
 +              b2 is a coefficient according to equation 2.121 in the book it represents b2 
 +             b2 = wc^2; 
 + 
 +              Now let's set up the impulse response 
 +             tau = INSERT CODE; 
 +  
 +              time parameters 
 +             ​time_beg = 0; 
 +             ​time_end = 10*tau;  
 +             t = time_beg:​dt:​time_end - dt;  time array 
 +  
 +              impulse response 
 +              notice that the equation is simplifies because b1 = 0 
 +             h = INSERT CODE; 
 + 
 + 
 + 
 + part 2) Now that you have constructed your filter, let's test it. 
 +         Copy the code below in separate script and run the script. 
 +         The script will call your function file h_t.m to create ​the 
 +         ​lowpass ​filter ​and then pass three signals ​of amplitude 5 and 
 +         ​frequencies:​ 100,400,4000 Hz. The script will then plot the filtered 
 +         ​signals. 
 + 
 +             fc = 400;  corner frequency of filter(Hz) 
 +  
 +  
 +  
 +              ​time parameters 
 +             time_beg = 0; 
 +             ​time_end_x = 0.1; 
 +             dt = 1/100000; ​ time step 
 +             tx = time_beg:​dt:​time_end_x - dt;  time array for signals 
 +  
 +  
 +              impulse response of low pass filter 
 +             h = h_t(fc,dt); 
 +             th = time_beg:​dt:​length(h)*dt-dt; ​ time array for filter 
 +  
 +              frequencies for the two signals 
 +             f1 = 100; 
 +             f2 = 400; 
 +             f3 = 4000; 
 +  
 +              signals to be filtered 
 +             x1 = 5*cos(2*pi*f1*tx); 
 +             x2 = 5*cos(2*pi*f2*tx)
 +             ​x3 ​= 5*cos(2*pi*f3*tx); 
 +  
 +              filtered ​signals 
 +             ​y1 ​conv(x1,h)*dt; 
 +             y2 conv(x2,h)*dt; 
 +             ​y3 ​conv(x3,h)*dt; 
 +  
 +             time array for 
 +             ty = time_beg:​dt:​length(y1)*dt-dt;​ 
 +  
 +  
 +             ​figure(1); 
 +  
 +              plots the impulse response 
 +             ​subplot(2,​2,​1)
 +             ​plot(th,​h); 
 +             ​xlabel('time (s)'); 
 +             ylabel('​amplitude'​)
 +             ​title('​impulse response ​h(t)'); 
 +  
 +              plots the filtered signal with Hz = 100 
 +             ​subplot(2,​2,​2) 
 +             plot(ty,y1)
 +             ​xlabel('​time (s)'​);​ 
 +             ​ylabel('​amplitude'​);​ 
 +             ​title('​filtered signal with Hz = 100'​);​ 
 +  
 +              plots the filtered signal with Hz = 400 
 +             ​subplot(2,2,3) 
 +             ​plot(ty,​y2);​ 
 +             ​xlabel('​time (s)'​);​ 
 +             ​ylabel('​amplitude'​);​ 
 +             ​title('​filtered signal with Hz = 400'​);​ 
 +  
 +              plots the filtered ​signal with Hz = 4000 
 +             ​subplot(2,​2,​4) 
 +             ​plot(ty,​y3);​ 
 +             ​xlabel('​time (s)'​);​ 
 +             ​ylabel('​amplitude'​);​ 
 +             ​title('​filtered signal with Hz = 4000'​);​ 
  part 3) You will now analyse the plots to verify that your filter is  part 3) You will now analyse the plots to verify that your filter is
          ​working.          ​working.
-       ​a) ​you designed your filter with an fc of 400 Hz and a dc gain of+       ​a) ​You designed your filter with an fc of 400 Hz and a dc gain of
           1. Verify that the filtered signal with f1 = 100 Hz still has a max           1. Verify that the filtered signal with f1 = 100 Hz still has a max
           amplitude of 5.            amplitude of 5. 
Line 1097: Line 1280:
           signal has the same frequency as the corner frequency what should           signal has the same frequency as the corner frequency what should
           its amplitude approximately be?            its amplitude approximately be? 
-       d) Looking at the last signal with f3 = 4000 Hz ignore the first +       d) Looking at the last signal with f3 = 4000 Hzignore the first 
-          part of the filtered signal ​that has an amplitude ​twice the value +          part of the filtered signal ​(the transient response) which has 
-          that the rest of the signal ​has, remember that this is just an +          ​an amplitude ​larger than the rest of the signal. 
-          ​approximation. ​f3 is ten times the frequency of f2, and you are+          f3 is ten times the frequency of f2, and you are
           using a second order filter. How much smaller should the           using a second order filter. How much smaller should the
-          amplitude of the signal with a freq(f3) ​be compared ​to the +          amplitude of the signal with frequency 4000 Hz be compare ​to the 
-          signal(f2)?+          signal ​with frequency 400 Hz? 
 + 
 </​file>​ </​file>​
 +
 +== Solution Image ==
 +
 +{{:​380matlab:​ch6:​uy6_3_1si_butterworthfilterssolutionimage.jpg?​400|}}
  
 <ifauth @admin,​@380ta>​ <ifauth @admin,​@380ta>​
  
 == Solution == == Solution ==
-{{:​380matlab:​ch6:​uy6_8_1_butterworthfilter.m|}} \\ +{{:​380matlab:solutions:​ch6:​uy6_8_1_butterworthfilter.m|}} \\ 
 The function file below creates the impulse response of a second order lowpass filter. \\  The function file below creates the impulse response of a second order lowpass filter. \\ 
-{{:​380matlab:​ch6:​h_t.m|}} ​ \\ +{{:​380matlab:solutions:​ch6:​h_t.m|}} ​ \\ 
  
 </​ifauth>​ </​ifauth>​
Line 1249: Line 1438:
  
 == fft_plot function file == == fft_plot function file ==
-{{:​380matlab:​ch6:​fft_plot.m|}}+{{:​380matlab:solutions:​ch6:​fft_plot.m|}}
  
 == Original Music File == == Original Music File ==
-{{:​380matlab:​ch6:​pianofinal_5s.wav|}}+{{:​380matlab:solutions:​ch6:​pianofinal_5s.wav|}}
  
 == Music Files After Sampling == == Music Files After Sampling ==
 This file was sampled at 1050 samples/​sec,​ then filtered again with fc of 500 Hz.  \\    This file was sampled at 1050 samples/​sec,​ then filtered again with fc of 500 Hz.  \\   
 You should be able to hear a low buz that is not in the original file \\  ​ You should be able to hear a low buz that is not in the original file \\  ​
-{{:​380matlab:​ch6:​pianos1nff.wav|}}+{{:​380matlab:solutions:​ch6:​pianos1nff.wav|}}
  
 This file was first filtered with fc of 500 Hz, sampled at 1050 samples/​sec,​ then filtered again with fc of 500 Hz.  \\  ​ This file was first filtered with fc of 500 Hz, sampled at 1050 samples/​sec,​ then filtered again with fc of 500 Hz.  \\  ​
 This file should sound similar to the original just quieter due to filtering \\  ​ This file should sound similar to the original just quieter due to filtering \\  ​
-{{:​380matlab:​ch6:​pianos1ff.wav|}}+{{:​380matlab:solutions:​ch6:​pianos1ff.wav|}}
  
 This file was first filtered with fc of 500 Hz, sampled at 500 samples/​sec,​ then filtered again with fc of 250 Hz.\\ This file was first filtered with fc of 500 Hz, sampled at 500 samples/​sec,​ then filtered again with fc of 250 Hz.\\
 This file shows the effects of aliasing. \\      ​ This file shows the effects of aliasing. \\      ​
-{{:​380matlab:​ch6:​pianos8ff.wav|}}+{{:​380matlab:solutions:​ch6:​pianos8ff.wav|}}
  
 +
 +====== Chapter 7: Discrete-Time Signals and Systems ======
  
 ===== D-Time Signal Functions ===== ===== D-Time Signal Functions =====
Line 1319: Line 1510:
  
 == Solution == == Solution ==
-{{:​380matlab:​ch7:​mt380_uy7_2_1_discrete_time_signal_functions.m|}} +{{:​380matlab:solutions:​ch7:​mt380_uy7_2_1_discrete_time_signal_functions.m|}} 
-{{:​380matlab:​ch7:​fundamentalperiod.m|}}+{{:​380matlab:solutions:​ch7:​fundamentalperiod.m|}}
  
 </​ifauth>​ </​ifauth>​
Line 1359: Line 1550:
 == Solution == == Solution ==
  
-{{:​380matlab:​ch7:​mt380_uy7_13_1_discretetimefourierseries.m|}}+{{:​380matlab:solutions:​ch7:​mt380_uy7_13_1_discretetimefourierseries.m|}}
  
 </​ifauth>​ </​ifauth>​
 +
 +===== Discrete Fourier Transform =====
 +==== MT380.UY7.15.1 ====
 +
 +<​file>​
 + MT380 UY7 15 1 Discrete Fourier Transform
 +
 +Objective: The objective of the assignment is to create a function that
 +           can implement the Discrete Fourier Transform and plot it.  We
 +           have provided all of the code except for the actual
 +           ​implementation of the DFT, but please go through the code
 +           ​carefully and try to understand it.
 +
 + ​Commands:​ Review
 + ​Exercise:​ You are given a file that represents a non-periodic signal. In
 +           this exercise you will (1) window the signal, (2) apply the DFT 
 +           to the windowed signal, (3) and then plot the signals.
 +
 +           a) Begin by importing the signal file (file located below), ​
 +              and storing its contents to a
 +              variable. This variable will hold the data points of the
 +              non-periodic signal. ​
 +                 % this command will open the file. You will need to replace
 +                 % filename with the name of the file.
 +                ​
 +                 ​fileID = fopen('​filename.txt'​);​
 + 
 +                 % the variable signal will contain the data points that represents the
 +                 % signal. ​
 +                 % the variable num_of_samples contains the number of data points in the
 +                 % file.
 +                 ​[original_signal,​num_of_samples] = fscanf(fileID,'​%e'​);​
 +                 % transpose the signal
 +                 ​original_signal = original_signal';​
 + 
 +                 % Since you have what you need, you can close the file.
 +                 ​fclose(fileID);​
 +                 % Below is the sample rate at which the original signal ​
 +                 % was created, in samples/​second.
 +                   ​sample_rate = 1200;
 +
 +                 % plot the signal as a function of n(index)
 +                 ​figure(1);​
 +                 ​subplot(2,​2,​1);​
 +                 ​plot(original_signal);​
 +                 ​title('​original signal'​);​
 +
 +               ​Notice how the bulk of the information is around the center
 +               of the plot, and that there is little non-zero data at
 +               other locations. We will window the signal to isolate the
 +               bulk of the data. This limits the number of sampled values,
 +               and thus reducing the number of computations. ​
 +
 +                 %the two parameters below will index '​original signal'​ around the bulk of
 +                 %the information.
 +                 ​n_window_lower = 320;
 +                 ​n_window_upper = 2119;
 + 
 +                 % window the original signal
 +                 ​windowed_signal = original_signal(n_window_lower:​n_window_upper);​
 + 
 +               Plot the windowed_signal and notice the difference between
 +               the '​original_signal'​ and the '​windowed_signal'​.
 +
 +                 % plot the windowed_signal as a function of n
 +                 ​subplot(2,​2,​2);​
 +                 ​plot(windowed_signal);​
 +                 ​title('​windowed signal'​);​
 +
 +           b) Create a function file that will perform the DFT. A skeleton
 +              of the function file is provided below. I have created the
 +              function file to operate in two modes depending on how many
 +              parameters you pass into the function file. All you need to
 +              do is modify the code that is between the comment lines to
 +              actually implement the DFT summation equation.
 +
 +                                   ​Comment line
 +               ​%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 +
 +                 ​function [Xk, f] =  myDFT(signal,​sample_rate)
 + 
 +                 % Xk is an array of the DFT complex coefficients
 +                 % f is an array of the frequencies that correspond to Xk
 +                 % signal is a variable that contains the data points of your signal
 +                 % sample_rate is the rate at which the signal was samples/​created
 + 
 +                 % This function file supports two modes. The first mode is the generic DFT,
 +                 % and is triggered when only yhe signal is passed to the function. Ex
 +                 ​% ​      ​myDFT(windowed_signal)
 + 
 +                 % If both parameters are passed, then the function file will execute the
 +                 % second mode
 +
 +                 % Ex. myDFT(windowned_signal,​ sample_rate);​
 + 
 +                 % Checks to see how many parameters were passed in. If only one parameter
 +                 % is passed in, then the original DFT is calculated.
 +                 ​if(nargin < 2)
 +                     ​sample_rate = 1;
 +                 end
 + 
 +                 % The equation for the DFT is
 +                 % Xk = sum(x[n]*exp(-1j*k*omega_o*n),​ from n = 0 to n = No-1)
 + 
 + 
 +                 % No represents the number of sampled values
 +                 No = length(signal);​
 + 
 +                 % fundamental frequency ​
 +                 ​gamma_o = 2*pi/No;
 + 
 +                 % n is an array that indexes the data points
 +                 n = 1:​length(signal);​
 + 
 +                 % Xn are the DFT complex coefficients
 +                 Xk = zeros(1,​length(signal));​
 + 
 +                 % f is an array that will contain the frequencies (Hz) at which the DFT is
 +                 % applied
 +                 f = zeros(1,​length(signal));​
 + 
 +                 ​%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 +                 ​% ​ Student will only modify the code in between the comment lines
 +                 ​%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 +                 % iterates through the harmonics of gamma_o to find the DFT complex
 +                 % coefficients and the frequencies (Hz)
 +                 for k = 0:No-1;
 + 
 +                 ​Xk(k+1) = sum( %INSERT CODE HERE);
 +                 ​f(k+1) = k*gamma_o/​(2*pi)*sample_rate;​
 + 
 +                 end
 +                 ​%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 +                 % Do not modify the code below
 +                 ​%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 +                 % In the DFT, the values ranged from 0 to pi represent the positive
 +                 % frequencies while the values from pi to 2pi represent the negative
 +                 % frequencies Since the magnitude of the DFT is an even function we can
 +                 % get all of the necessary information from looking at the values of Xn
 +                 % that represent the frequencies from 0 to pi
 + 
 +                 ​if(nargin == 2)
 + 
 +                     Xk = 2*Xk(1:​round(length(Xk))/​2);​
 +                     ​f ​ = f(1:​round(length(f))/​2);​
 +                 end
 +
 +           c) Call the function to perform the DFT on your signal passing
 +              in only your signal to myDFT function. Call the function
 +              again, but pass in both the signal and the sample rate.
 +
 +                 % call function to perform the DFT
 +                 ​[Xn_mode1,​f_mode1] = myDFT(windowed_signal);​
 +                 ​[Xn_mode2,​f_mode2] = myDFT(windowed_signal,​sample_rate);​
 + 
 +                 % plot the DFT transform
 +                 ​subplot(2,​2,​3);​
 +                 ​plot(f_mode1,​abs(Xn_mode1));​
 +                 ​title('​DFT mode1 complex coefficients'​);​
 +                 ​xlabel('​frequency (hz)'​);​
 +                 ​ylabel('​DFT complex coefficients magnitude'​);​
 + 
 +                 ​subplot(2,​2,​4);​
 +                 ​plot(f_mode2,​abs(Xn_mode2));​
 +                 ​title('​DFT mode 2 complex coefficients'​);​
 +                 ​xlabel('​frequency (hz)'​);​
 +                 ​ylabel('​DFT complex coefficients magnitude'​);​
 +
 +           d) Question:
 +              1) Looking at the DFT mode2 plot (where you pass in the sample
 +                 rate, what frequencies are in the original signal. Hint: there are only four.
 +           ​Remember to submit your plots and code.
 +</​file>​
 +
 +== Signal File ==
 +
 +{{:​380matlab:​ch7:​mt380_uy7_15_1_s_discretefouriertransform_signal.txt|}}
 +
 +== Solution Image ==
 +
 +{{:​380matlab:​ch7:​mt380_uy7_15_1_si_discretefouriertransform_solutionimage.jpg?​400|}}
 +
 +<ifauth @admin,​@380ta>​
 +
 +== Signal Creation ==
 +
 +{{:​380matlab:​solutions:​ch7:​mt380_uy7_15_1_sc_discretefouriertransform_signalcreation.m|}}
 +
 +== Solution ==
 +
 +DFT Function File.
 +{{:​380matlab:​solutions:​ch7:​mt380_uy7_15_1_dft.m|}}
 +
 +Associated Script File
 +
 +{{:​380matlab:​solutions:​ch7:​mt380_uy7_15_1_discretefouriertransform.m|}}
 +
 +</​ifauth>​
 +
 +====== Extras ======
 +===== Music Harmonics =====
 +<​file>​
 +   This MATLAB assignment explores the relationship between music and 
 +the frequency domain using the FFT. The file provided gives you a sample
 +of a cello playing the note D3. An FFT of note D3 is taken in order to 
 +approximate Discrete Fourier Transform coefficients. These coefficients are 
 +used to approximate other notes pertaining to a Cello.
 +    All you need to do is download the file and explore what is provided to you.
 +Note, all the code is provided to you; however, you are encouraged to modify it and
 +play around. Be creative.
 +    As of now, you do not need to turn in anything in order to receive credit for this 
 +assignment.
 +</​file>​
 +
 +== File ==
 +{{:​380matlab:​funapplications:​music_harmonics.zip|}}
ecen_380_assignments.1445011353.txt.gz · Last modified: 2015/10/16 10:02 by petersen