Laboratory Report

.pdf

School

Concordia University *

*We aren’t endorsed by this school

Course

342

Subject

Electrical Engineering

Date

Jan 9, 2024

Type

pdf

Pages

17

Uploaded by mannybenka

Report
Laboratory Report ELEC 342 Laboratory experiment #4 Functions in MATLAB and the Sampling Theorem By Anas Senouci (40132281) Laboratory made on March 14 th , 2022 Lab section: MJ-X Lab instructor: Mohebbi, Ali Due date: March 21, 2022
OBJECTIVES This lab will go over some more MATLAB programming functions, such as floor, global and polar to study the effect of sampling rate on the Fourier transform of a signal THEORY The theory behind this lab was mainly to learn how to examine the outcomes of the sample rate on a signal after doing the Fourier Transform to apply the sampling theorem in MATLAB. We learnt how to write a function, store it as an M-file, and utilise it in other scripts as part of this experiment. TASKS, RESULTS AND DISCUSSION Questions 1: The first question aims to look at the effects of a few different sampling rates on the Fourier transform of a sampled signal in this inquiry. When the script is launched, the user is prompted to provide the sample data, which includes the step size and number of periods. For part a) of the question, the user enters five different values of sampling rate to examine how they influence the graph after defining the step size and number of periods. For part a) of the question, the number of period input is 4, the step-size input is 0.01 and the five sampling rates are 2, 4, 9, 12 and 34. As for the b) part, instead of changing the sampling rate, it is kept constant, and the window size is input by the user five times. The step size input is 0.01, the sampling rate is 4 and the window sizes are respectively 2, 4, 9, 12 and 34. The Appendix I and II contains the codes and results for parts a) and b). It is observable that the magnitude of the Fourier transform is proportional to the sampling rate. On the other side, when changing the window size, the magnitude of the Fourier transform stays constant but there is a lot more periods that can be observed in one single graph. Questions 2: Question 2 is all about understanding the built-in function polar of MATLAB used to find the polar plots. The main goal is to redo question 1 but using polar coordinates to show polar plots instead of rectangular plots. The following input signal is used x[n] = 0.5*sin(2*pi/N * n) + 0.33* sin(4*pi/N*n) for the question. For that part, the number of period input is 4, the step-size
input is 0.01 and the five sampling rates are 2, 4, 9, 12 and 34. It is possible to see the figures with the polar plot of the signals in Appendix III. We can see that a polar cycle is made of four vertices ranging from half the magnitude of the rectangular graph in question 1-a). By increasing the sampling rate, the magnitude increases and the phase decreases. Questions 3: The last question purpose is to learn about how an LTI system can be used to compress or recover a distorted signal. To get the difference between a distorted and a normal signal, we need to use the following function for this question: Two files, Original.wav and Distorted.wav provide a signal and its distorted version. Then, the MATLAB function audioread is used to upload the file to the program. The function sound can be used to play the signal and the function audiowrite is used to write an audio signal into a new file. In summary, the goal is to load the given audio files, use the MSE function to compare both versions, design a system to recover the original signal from the distorted one and compare the original version to the recovered one. We notice with the help of Figure 16 and 17 in Appendix IV that the distorted signal has a greater amplitude in general with higher peaks in the absolute. The domain chosen for the design of the recovered.wav file is the time domain to be able to use the LMS (least mean squared) algorithm. Regarding part d) of the question, the answer is yes, the system improves the MSE since the error goes from 1.7 at the most to around 0.77. By listening to the distorted version and the recovered version, you can hear the difference very well, the system certainly improves the sound quality.
APPENDIX I %Question 1-a: clear all ; clc; n=input( 'Input the number of periods: ' ); step_size=input( 'Input the step size of the frequency interval: ' ); global w; w=-n*pi:step_size:n*pi; for i=1:5 sampling_rate=input( 'Input sampling rate in terms of nyquist rate: ' ); N=floor(sampling_rate*2); n = 0:1:2*(N-1); x=sin((2*pi/N)*n); subplot(2,1,1); stem(n,x); xlabel( 'n' ); ylabel( 'x[n]' ); title( 'The Discrete Signal' ); x_fft = fft(x,n); magnitude = abs(x_fft); subplot(2,1,2); plot(w,magnitude); xlabel( 'w' ); ylabel( 'Magnitude of x[w]' ); title( 'Fourier transform of x[n]' ); end function fft = fft(x,n) global w; for i=1:length(w) sum=0; for q=1:length(x) sum = sum + x(q)*exp(-j*w(i)*n(q)); end F(i)=sum; end fft = F; end
Figure 1. Q1 - a) Sampling rate = 2 Figure 2. Q1 - a) Sampling rate = 4
Figure 3. Q1 - a) Sampling rate = 9 Figure 4. Q1 - a) Sampling rate = 12
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