TheWhiteFang

dsp2 lab codes

Feb 2nd, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.55 KB | None | 0 0
  1. path1='C:\Users\Ghostphreak\Desktop\lab2_note_on_frequency_spectrum_estimation'; % change to the path where you put your code
  2. cd(path1)
  3. close all, clear all;
  4. [o_n,fs,b]= wavread('3n.wav'); % replace with your id, mine was 1112700303 hence the 3n % o_n vector that contain the stored audio signal ' noisy version'
  5. [o_c,fs,b]=wavread('3o.wav'); % clean signal
  6.  
  7. %b=fir1(132,0.4);
  8. %a=1;
  9. %freqz(b,1,512,8012);
  10.  
  11. %estimate the frequency content
  12. N = length(o_n);
  13. X_n=fft(o_n,N); % perform N point DFT to obtain N fourier transform samples
  14. X_c=fft(o_c,N); % Do fft on clean signal
  15. %% Plot with discrete frequency 0-2pi
  16. w = ( 0:(N-1) )/N * 2*pi ; % discrete time frequency vector [0 ,...2pi]
  17. fvec = w*fs/(2*pi); % f = w*fsampling/(2*pi)frequency vector in hertz
  18. %% Plot only from 0 to half sampling frequency (Hertz)
  19. halfN = round(length(fvec)/2);
  20. fv = fvec(1:halfN);
  21. magX = abs(X_n);
  22. magX_noisy = abs(X_c);
  23. X_n_half = magX(1:halfN);
  24. X_c_half = magX_noisy(1:halfN);
  25. figure,plot(fv,abs(X_n_half),'b-');
  26. xlabel('Frequency in hertz 0-> half of fsampling (Hertz) , fsampling = 8000Hz');
  27. ylabel(' magnitude of fourier transform coefficients');
  28. % Plot the clean, superimposed
  29. hold on
  30. plot(fv,abs(X_c_half),'r-') % red is clean
  31. title('Spectrum analysis of clean and noisy signal')
  32. legend('noisy','clean')
  33.  
  34. %hamming %added codes
  35. %credits to bro chakrawarthi
  36. Na= 132; %class order
  37. wc = 0.424; %cutoff freq
  38. h=fir1(Na,wc, hamming (Na+1));
  39. freqz(h,1,512,fs);
  40. s=filter(h,1,o_n);
  41. s_s=fft(s,N);
  42. magS=abs(s_s);
  43. s_s_half=magS(1:halfN);
  44. figure,plot(fv,abs(s_s_half),'b-');%}
Add Comment
Please, Sign In to add comment