COMPARE.M
上传用户:speoil
上传日期:2022-06-23
资源大小:224k
文件大小:2k
源码类别:

波变换

开发平台:

Matlab

  1. %function compare(w)
  2. wavread open8;
  3. first_signal = ans;
  4. vector1_length = length(first_signal);
  5. f=0;
  6. i=0;
  7. s= 0;
  8. count1 = 1;
  9. start=0;
  10. finish=0;
  11. while s < 1
  12.     if max(abs(first_signal(count1:count1+1000))) > .99
  13.         i=i+1;
  14.         start(i) = count1;
  15.         f=0;
  16.         while f < 1
  17.             if max(abs(first_signal(count1:count1+1000))) < .99
  18.                 finish(i) = count1;
  19.                 f = 1;
  20.             else
  21.                 count1 = count1 + 1000;
  22.                  if count1+1000 > vector1_length
  23.                      f = 1;
  24.                  end
  25.             end
  26.         end
  27.     end
  28.     
  29.     count1 = count1 + 1000;
  30.     if count1+1000 > vector1_length
  31.         s = 1;
  32.     end
  33.     
  34. end
  35. count_syllable = length(start);
  36. first_syll = first_signal(start(1):finish(1));
  37. second_syll = first_signal(start(2):finish(2));
  38. subplot(3,1,1)
  39. plot(first_signal)
  40. t1=[0:1/(length(first_syll)-1):1];
  41. subplot(3,1,2);
  42. plot(t1,first_syll)
  43. t2=[0:1/(length(second_syll)-1):1];
  44. subplot(3,1,3);
  45. plot(t2,second_syll)
  46. length_f = length(first_syll);
  47. length_s = length(second_syll);
  48. fft_first = abs(fft(first_syll));
  49. half_f = round(length_f/2);
  50. main_f = fft_first(half_f:length_f);
  51. fft_second = abs(fft(second_syll));
  52. half_s = round(length_s/2);
  53. main_s = fft_second(half_s:length_s);
  54. t1=[0:1/(length(main_f)-1):1];
  55. subplot(3,1,1)
  56. plot(t1,main_f)
  57. t2=[0:1/(length(main_s)-1):1];
  58. subplot(3,1,2)
  59. plot(t2,main_s)
  60. power_f_n = sum(main_f)/length(main_f);
  61. power_s_n = sum(main_s)/length(main_s);
  62. avg_power_f = (abs(power_f_n-power_f)/power_f)*100;
  63. avg_power_s = (abs(power_s_n-power_s)/power_s)*100;
  64. if avg_power_f < 30
  65.     if avg_power_s < 30
  66.         
  67.         disp('Your voice is a match')
  68.     else
  69.         disp('Your voice is not a match')
  70.     end
  71. else
  72.     disp('Your voice is not a match')
  73. end
  74.             
  75.