380-Matlab2

pdf

School

University of British Columbia *

*We aren’t endorsed by this school

Course

380

Subject

Electrical Engineering

Date

Apr 3, 2024

Type

pdf

Pages

2

Uploaded by UltraNeutronRam3

Report
ENSC-380 MATLAB Assignment 2 Part I (Filter Design for a Noisy Sinusoidal Signal ) 1. In this question, we will observe how an analog Lowpass filter is effective in removing noise from a sinusoidal signal using MATLAB. Let’s define the sinusoidal signal 𝑥(𝑡) = sin(2𝜋 × 10𝑡) and the additive noise 𝑛(𝑡) as a normally distributed random number ( 𝑛(𝑡) = 0.5 ∗ 𝒓𝒂𝒏𝒅𝒏(𝑡) in MATLAB). So, the definition for the noisy signal is 𝑥 𝑛 (𝑡) = 𝑥(𝑡) + 𝑛(𝑡) . Let’s define 𝑥 𝑓 (𝑡) as the output of a lowpass filter when the input is 𝑥 𝑛 (𝑡). Perform the following tasks and include the results and your code in your report: a) Generate 𝑥(𝑡) , 𝑛(𝑡) and 𝑥 𝑛 (𝑡) (Assume that 𝑡 = 0 : 0 .001 : 1 ). b) Create a lowpass filter for filtering out the noise from the noisy signal 𝑥 𝑛 (𝑡) (you can use lowpass(x, wpass) function in the MATLAB, where x is the input sginal and wpass is a normalized passband frequency. You should manipulate wpass to get a desirable result, i.e. to remove the noise as much as possible). c) Plot 𝑥(𝑡) , 𝑥 𝑛 (𝑡) and 𝑥 𝑓 (𝑡) on the same figure. d) Plot frequency spectrum (FT) of 𝑥(𝑡) , 𝑥 𝑛 (𝑡) and 𝑥 𝑓 (𝑡) (for instance, you can use abs( fft(x)) command to find the Fourier Transform of signal x ) e) Explain how the lowpass filter was able to remove noise 𝑛(𝑡) from signal 𝑥 𝑛 (𝑡) . Part II (Filter design for Image and Audio ) 2. In this question, you will see the effect of Highpass and Lowpass filters on a particular image , ‘ Image.bmp ’, in MATLAB. The code for this part is provided to you in the file Question_2 .m” . The normalized pass band frequencies for the Lowpass and Highpass filters are named x1 and x2 in the code, respectively. Perform the following and include the results into your report: a) Explain how a lowpass filter and a highpass filter affect an image (in general). b) Run the script two times, first with x1 =0.05 and x2 =0.05, and second for x1 =0.5 , x2 =0.5. c) For each case, include the original and filtered images in your report and explain the differences between the results and the reasons for it. 3. In this question you will learn how to remove noise from an audio file in MATLAB. Use audioread for reading the audiofile Test.mp3 to MATLAB and audioinfo to extract the required data from the audio file. Perform the following tasks and include the results and your code in your report: a) Using the partial code given under “Hints” below read the audio file and extract the required data ( i.e. 𝑥(𝑡) and Fs ) and create the time vector 𝑡 . b) Using MATLAB commands, i) play the sound for signal data 𝑥(𝑡) , ii) plot 𝑥(𝑡) and iii) plot the magnitude of the Fourier Transform of 𝑥(𝑡) (You can use abs(fft) ). c) Add the random noise 𝑛(𝑡) = 0.05 × 𝒓𝒂𝒏𝒅𝒏(𝒕) to the signal, similar to what you did in Q1 ( 𝑥 𝑛 (𝑡) = 𝑥(𝑡) + 𝑛(𝑡) ). d) Using MATLAB commands, i) generate an audio file from 𝑥 𝑛 (𝑡), and play the sound, ii) plot 𝑥 𝑛 (𝑡) and iii) plot the magnitude of the Fourier Transform of 𝑥 𝑛 (𝑡) . e) Using MATLAB ’s “lowpass” command, remove the noise from 𝑥 𝑛 (𝑡) . Call the output of the filter 𝑥 𝑓 (𝑡) . Note that it is not possible to remove all of this noise from the signal but by adjusting the wpass parameter of the filter you should try to remove the noise as much as possible. Then, i) generate an audio file from recovered signal 𝑥 𝑓 (𝑡), and play the sound, ii) plot 𝑥 𝑓 (𝑡) and iii) plot the magnitude of the Fourier Transform of 𝑥 𝑓 (𝑡) .
f) By looking at the Fourier Transform of three signals, explain how the lowpass filter was able to remove the noise from the signal? Hints: 1- Use the following code to read an audio signal and prepare the vector containing it: [x,Fs] = audioread ('Test.mp3'); info = audioinfo ('Test.mp3'); t = 0:seconds(1/Fs):seconds(info.Duration); t=t(1:size(x,1)); 2- The sound(x, Fs) command can be used to play a sound, where x is the input and Fs is the sample rate (the same Fs obtained above). 3- Make use of MATLAB’s “help” feature to learn more about commands What to submit? Submit ONLY one PDF file including your codes, results, and your explanations. Include the relevant code after each question. Please write your answers clearly and in details.
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