I am trying to clean up the corruption and recover the original soundtrack but it turns out way less than my expectation
6 views (last 30 days)
Show older comments
% Step 1: Identify the system's impulse response h[n]
load ("finalproject") % Load the project data
% Padding the shorter signal to make it the same length as the longer one for FFT
length_difference = length(xtraining)-length(straining);
padded_straining = [straining;zeros(length_difference,1)];
% Compute the FFT of the padded training sequence and the xtraining sequence
X_straining = fft(padded_straining);
X_xtraining = fft(xtraining);
% Compute the frequency response of the system H(f)
H_f = X_xtraining ./ X_straining;
% Compute the impulse response of the system h[n] using inverse FFT
h_f = ifft(H_f);
% Select the first 9 elements of the impulse response for the FIR filter
hFILTER = h_f(1:9);
disp(hFILTER) % Display the impulse response
% Step 2: Recover the specific sequence from y[n]
% Pad the impulse response to the length of y for FFT
length_difference2 = length(y) - length(hFILTER);
padded_h = [hFILTER;zeros(length_difference2,1)];
% Compute the FFT of the corrupted signal y and the padded impulse response
Y_f = fft(y);
H_f = fft(padded_h);
% Compute the filtered signal in the frequency domain
S_f = Y_f ./ H_f;
% Convert the filtered signal back to time domain
s_plus_cos = ifft(S_f);
% Step 3: Detect the single tone frequency f
% Take FFT of the signal y
Y = fft(y);
% Compute the magnitude spectrum of Y
magnitude_spectrum = abs(Y);
% Find the index of the peak in the magnitude spectrum
[~, index_of_peak] = max(magnitude_spectrum);
% Compute the frequency resolution of the FFT
frequency_resolution = fs / length(y);
% Calculate the single tone frequency using its FFT index
single_tone_frequency = (index_of_peak - 1) * frequency_resolution;
% Display the single tone frequency
disp(single_tone_frequency);
% Assign the detected frequency to f
f = single_tone_frequency;
% Step 4: Design a "notch" filter to filter out the single tone sinusoid
% Create the coefficients for a second-order notch filter
hNOTCH = [1, -2*cos(2*pi*f/fs),1];
% Apply the notch filter to the signal
recovered_audio = conv(s_plus_cos,hNOTCH);
% Play the recovered audio
sound(recovered_audio,fs)
% This is the distorted version: sound(y,fs)
% The quality that the sound supposed to produce: sound(stest,fs)
0 Comments
Answers (0)
See Also
Categories
Find more on Filter Design in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!