BMEN 3311 Lab3 F2022 Answer

docx

School

University of North Texas *

*We aren’t endorsed by this school

Course

3311

Subject

Electrical Engineering

Date

Jan 9, 2024

Type

docx

Pages

3

Uploaded by BrigadierDiscovery640

Report
BMEN 3311 Lab 3 Names: Student ID: 1. A squarewave with period of 2pi can be created using Matlab function square(2*pi*f*t). (1) Generate a 5Hz discreate squarewave for a time period of 1second, with a sampling frequency of 1000Hz. Adjust the squarewave’s amplitude to [0 1]. (2) Generate a decline signal from maximum 1 decline to 0, with the same time vector as in (1). (3) Perform the convolution of the data in (1) and (2). Generate a plot to show all three data in one figure. Notice the number of data will increase after convolution, as becomes to 2n-1 clear; close all ; clc; %% (1) Fs = 1000; Ttotal = 1; % s timeStep = 1/Fs; % s time = 0:timeStep:Ttotal; f = 5; % Hz squareWave = square(2*pi*f*time); squareWave = (squareWave +1)./2; %% (2) Ln = linspace(1,0,Fs+1); %% (3) Con = conv(squareWave,Ln); timeCon = linspace(0,1,2*length(time)-1); figure; subplot(3,1,1); plot(time,squareWave); xlabel( 'time (s)' ); ylabel( 'amplitude' ); subplot(3,1,2); plot(time,Ln); xlabel( 'time (s)' ); ylabel( 'amplitude' ); subplot(3,1,3); plot(timeCon,Con); xlabel( 'time (s)' ); ylabel( 'amplitude' );
2. Given the following signal. x ( t ) = 7 cos ( 2 п 700 t )+ 3cos ( 2 п 450 t ) + cos ( 2 п 60 t ) Create a subplot with the first plot being the signal graphed vs. time. The second subplot is the frequency plot of the signal. Verify plot with TA. Assume the following: a. The sampling frequency is 6 KHz b. You can use any number of samples c. Use a non-complex Fourier Series to generate the frequency plot (do not use DFT function). Label all axis and graphs appropriately. d. There should be no spectral leakage in the frequency plot. (This is related to the fundamental frequency and frequencies of the signal) clear; close all ; clc; %% generate a signal - ini fs = 6000; % Hz ts = 1/fs; % sec N = 6000; % total points of the data T = N/fs; % total time (in sec) of the data T = N * ts; f1= 1/T; % fundamental frequency t = 0:ts:T; % time vector of the signal y = 7*cos(2*pi*700*t)+3*cos(2*pi*450*t)+cos(2*pi*60*t); %% method1: amp-phase Fourier series. for n = 1:1000 % using n < 3000 is OK f(n) = n*f1; a(n) = (2/N)*sum(y.*(cos(2*pi*f1*n*t))); b(n) = (2/N)*sum(y.*(sin(2*pi*f1*n*t))); A(n) = sqrt(a(n).^2 + b(n).^2); end %% method2: exp of Fourier series for n = 1:1000 C(n) = (1/T)*sum(y.*1/exp(j*2*pi*n*f1*t)); Cm(n) = sqrt(real(C(n))^2 + imag(C(n))^2); AmC(n) = 2*Cm(n); end figure; subplot(311) plot(t,y); xlabel( 'time(s)' ); ylabel( 'amplitude' ); subplot(312) plot(f,A); xlabel( 'frequency(Hz)' ); ylabel( 'amplitude' ); subplot(313) plot(f,AmC); xlabel( 'frequency(Hz)' ); ylabel( 'amplitude' );
3. The file avf.csv contains 3 minutes of a noisy ECG signal. The first column of data is the time intervals a sample was taken, and the second column of data is the magnitude of the ECG in mV. Perform the following using the ECG data: a. Plot 3 seconds worth of the ECG and label the plot appropriately. b. Perform a DFT (with the DFT function) and create a separate plot of the power spectrum. Label the plot appropriately. Have TA verify both plots Based on the frequency plot, where is the largest noise source located? clear; close all ; clc; M = csvread( 'avf.csv' ); Fs = 1/(M(2,1)-M(1,1)); % sampling frequency in Hz N = 3*Fs+1; % because start at 0. T = N/Fs; data = M(1:N,2); time = M(1:N,1); subplot(2,1,1); plot(time,data); xlabel( 'time(s)' ); ylabel( 'amplitude (mV)' );title( 'ECG first 3 second' ); f= Fs*(0:(N/2))/N; Y = fft(data); P2 = abs(Y/N); P1 = P2(1:N/2+1 P1(2:end-1) = 2*P1(2:end-1); subplot(2,1,2); plot(f,P1); xlabel( 'frequency (Hz)' ); ylabel( 'amplitude' );title( 'powerspectrum' );
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help