ht2383_matlab_HW9_report

pdf

School

New York University *

*We aren’t endorsed by this school

Course

6113

Subject

Electrical Engineering

Date

Feb 20, 2024

Type

pdf

Pages

12

Uploaded by BarristerBoulderNarwhal28

Report
I create a MATLAB file call problem.m I put my code in there. In the 'mtlab.wav' , I heard a clean sound with short fast pronounced ‘matlab’. In the 'mtlab_noisy.wav' I heard a short pronounced ‘matlab’ with a shrill whistle. [Y_clean, Fs_clean] = audioread( 'mtlab.wav' ); [Y_noisy, Fs_noisy] = audioread( 'mtlab_noisy.wav' ); soundsc(Y_clean, Fs_clean); soundsc(Y_noisy, Fs_noisy); As following impulse plot, we can clearly find that noise located at -1 to -0.8 and 0.8 to 1. fx = fft(Y_clean,7418); fy = fft(Y_noisy,7418); n = [-1:1/3709:1]; n = n(1:end-1);
R = 512; window = hamming(R); N = 512; L = 25; overlap = R - L; fs = Fs_clean; figure subplot(2,1,1) plot(n,abs(fftshift(fx))) title( 'original signal' ) subplot(2,1,2) plot(n,abs(fftshift(fy))) title( 'signal with noise' ) From the spectrogram you can tell noisy one has noticeable noise around 3kHz and above. Clean vs noisy:
figure; subplot(2, 1, 1); spectrogram(Y_clean, window, overlap, N, fs, 'yaxis' ); title( 'Clean Signal Spectrogram' ); subplot(2, 1, 2); spectrogram(Y_noisy, window, overlap, N, fs, 'yaxis' ); title( 'Noisy Signal Spectrogram' ); Option A: W as constant:
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
I set w=10 and w=50 for weight function turned to emphasize noise removal and allow a transition bank, and the following are the impulse and spectrogram result. W=10: W=50:
Option B: I set short as 10, long as 40: h_short = firpm(10, [0 fp fs 0.5]*2, [1 1 0 0], W1); h_long = firpm(40, [0 fp fs 0.5]*2, [1 1 0 0], W1); the following are the impulse response and spectrogram of different length under the same weighting function:
From the spectrogram we can tell short one still has some noise remaining, but longer one is cleaner. Option C: The following is the n=100 Impulse Response for Weight Function and spectrogram for Weight Function:
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
From the plot we can observe that when n=100 it basically filters out 80% of the spectrogram, which is not the ideal result we want. The following is the n=20 Impulse Response for Weight Function and spectrogram for Weight Function: From the plot we can observe that when n=20, the result of the filter is still not very well. In summary, after comparing all 3 options personally I prefer option b with long filter length, for me it sound better and the process is quite straight forward. For option a and c the effect the filter doesn’t perfectly filter out the noise very well. Code: [Y_clean, Fs_clean] = audioread( 'mtlab.wav' ); [Y_noisy, Fs_noisy] = audioread( 'mtlab_noisy.wav' ); soundsc(Y_clean, Fs_clean); soundsc(Y_noisy, Fs_noisy);
fx = fft(Y_clean,7418); fy = fft(Y_noisy,7418); n = [-1:1/3709:1]; n = n(1:end-1); R = 512; window = hamming(R); N = 512; L = 25; overlap = R - L; fs = Fs_clean; figure subplot(2,1,1) plot(n,abs(fftshift(fx))) title( 'original signal' ) subplot(2,1,2) plot(n,abs(fftshift(fy))) title( 'signal with noise' ) figure; subplot(2, 1, 1); spectrogram(Y_clean, window, overlap, N, fs, 'yaxis' ); title( 'Clean Signal Spectrogram' ); subplot(2, 1, 2); spectrogram(Y_noisy, window, overlap, N, fs, 'yaxis' ); title( 'Noisy Signal Spectrogram' ); % Option A - Fixed Filter Length with Different Weights fp = 0.4044; fs = 0.4244; W_constant = [1 1]; % Constant weight over entire frequency range h_constant = firpm(25, [0 fp fs 0.5]*2, [1 1 0 0], W_constant); % Option A - Weight Function for Noise Removal and Transition Bank
W_emphasized1 = [1 10]; W_emphasized2 = [1 50]; h_emphasized1 = firpm(25, [0 fp fs 0.5]*2, [1 1 0 0], W_emphasized1); h_emphasized2 = firpm(25, [0 fp fs 0.5]*2, [1 1 0 0], W_emphasized2); % Visualize the results figure; % Impulse Response for Constant Weight subplot(2, 1, 1); stem(0:length(h_constant)-1, h_constant, 'filled' ); title( 'Filter with Constant Weight - Impulse Response' ); % Spectrogram for Constant Weight subplot(2, 1, 2); spectrogram(filter(h_constant, 1, Y_noisy), window, overlap, N, fs, 'yaxis' ); title( 'Noisy Signal Spectrogram (Constant Weight)' ); figure; % Impulse Response for Weight Function subplot(2, 1, 1); stem(0:length(h_emphasized1)-1, h_emphasized1, 'filled' ); title( 'Filter with Emphasized Noise Removal w=10 - Impulse Response' ); % Spectrogram for Weight Function subplot(2, 1, 2); spectrogram(filter(h_emphasized1, 1, Y_noisy), window, overlap, N, fs, 'yaxis' ); title( 'Noisy Signal Spectrogram (Emphasized Noise Removal)' ); figure; % Impulse Response for Weight Function subplot(2, 1, 1); stem(0:length(h_emphasized2)-1, h_emphasized2, 'filled' ); title( 'Filter with Emphasized Noise Removal w=50 - Impulse Response' );
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
% Spectrogram for Weight Function subplot(2, 1, 2); spectrogram(filter(h_emphasized2, 1, Y_noisy), window, overlap, N, fs, 'yaxis' ); title( 'Noisy Signal Spectrogram (Emphasized Noise Removal)' ); % Option B - Different Filter Lengths with the Same Weight h_short = firpm(10, [0 fp fs 0.5]*2, [1 1 0 0], W1); h_long = firpm(40, [0 fp fs 0.5]*2, [1 1 0 0], W1); % Generate spectrograms for short and long filter lengths [B_short, f_short, t_short] = specgram(filter(h_short, 1, Y2), N, fs, window, overlap); [B_long, f_long, t_long] = specgram(filter(h_long, 1, Y2), N, fs, window, overlap); % Plot impulse responses figure; subplot(2, 1, 1); stem(0:length(h_short)-1, h_short, 'filled' ); title( 'Impulse Response - Short Filter Length' ); subplot(2, 1, 2); stem(0:length(h_long)-1, h_long, 'filled' ); title( 'Impulse Response - Long Filter Length' ); % Plot spectrograms figure; subplot(2, 1, 1); imagesc(t_short, f_short, log10(abs(B_short))); axis xy ; xlabel( 'Time' ); ylabel( 'Frequency' ); title( 'Spectrogram - Short Filter Length' );
subplot(2, 1, 2); imagesc(t_long, f_long, log10(abs(B_long))); axis xy ; xlabel( 'Time' ); ylabel( 'Frequency' ); title( 'Spectrogram - Long Filter Length' ); % Option C - Use firls to Determine Filter Coefficients dev = 0.01; % Maximum deviation (1% of passband gain) % Use firpmord to determine desired filter length and weighting function [n, fo, ao, w] = firpmord([fp fs], [1 0], [dev dev*10], Fs_noisy); % Reduce the filter order (you may adjust this value) n = 20; % n=100; % Design the filter using firls b = firls(n, fo, ao, w); figure; % Impulse Response for Weight Function subplot(2, 1, 1); impz(b); title( 'Filter Designed with firls - Impulse Response' ); % Spectrogram for Weight Function subplot(2, 1, 2); [B_c, f_c, t_c] = specgram(filter(b, 1, Y_noisy), N, fs, window, overlap); imagesc(t_c, f_c, log10(abs(B_c))); axis xy ; xlabel( 'Time' ); ylabel( 'Frequency' ); title( 'Spectrogram - firls Designed Filter' );
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