Question: Replicate this code from Python to Matlab, I'm using version 2022b. Please make it work import numpy as np import matplotlib.pyplot as plt from scipy

Replicate this code from Python to Matlab, I'm using version 2022b. Please make it work

import numpy as np import matplotlib.pyplot as plt from scipy import signal from scipy.io import wavfile

# The cutoff frequency 1 "f_c1" is normalized with respect to the Nyquist frequency "f_s/2 = 6kHz" f_c1 = 0.33 print("Cutoff Frequency 1 f_c1 = ", f_c1) # The cutoff frequency 2 "f_c2" is normalized with respect to the Nyquist frequency "f_s/2 = 6kHz" f_c2 = 0.83 print("Cutoff Frequency 2 f_c2 = ", f_c2) # Vector containing the cut interval f = [f_c1, f_c2] # The filter is designed with the "butter" function for a BP filter in its IIR version b_1p, a_1p = signal.butter(5, f, 'bandpass')

# Open the provided wav file with the "wavfile.read" function # Returns the sample rate and audio information samplerate, data = wavfile.read("ref_Audio_12ksps.wav") # The audio file data is plotted #plt.plot(data)

# Apply the filter to the data stream of the audio file filteredData = signal.filtfilt(b_1p, a_1p, data) # The audio data obtained after applying the filter on it is graphed #plt.plot(filtedData) #plt.show()

# Calculate the frequency response of the filter with the function freqz w, rh = signal.freqz(b_1p, a_1p, 68) w_pi = w/np.pi * 6 # Plot of the filter applied to the audio data plt.plot(w_pi, np.abs(rh)) plt.show()

# Apply a fourier transform to the input signal (before the filter) fft_input=np.fft.fft(data) # Fourier transform is applied to the output signal (after the filter) fft_output=np.fft.fft(filtedData) # The frequency response of the input signal is plotted plt.plot(np.abs(fft_input)) plt.show() # The frequency response of the output signal is plotted plt.plot(np.abs(fft_out)) plt.show()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!