Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. function x = iSTFT(X, W, L)
  2. % Wejście:
  3. % X - krótkoczasowa transforata Fouriera sygnału x
  4. % W - okno syntezujące
  5. % L - liczba próbek nachodzących na siebie
  6. % Wyjście:
  7. % x - rekonstrukcja sygnału z STFT
  8.  
  9. # Lenght of the signal in samples
  10.  
  11.  
  12. x=zeros(1,L);
  13.  
  14.  
  15. # Lenght of the window in samples
  16. Wlen = size(X)(1);
  17. Wsiz=size(X)(2);
  18.  
  19. for k=1:Wsiz;
  20. y=X(:,1);
  21. y=y.';
  22. y=ifft(y);
  23. z=y(1:length(W));
  24. length(z);
  25. z=z.*W;
  26. x(end-L+1:end)=x(end-L+1:end)+z(1:L);
  27. x=[x,z(L+1:end)];
  28. end
  29. x=[x,zeros(1,100)];
  30.  
  31. end
  32.  
  33. -------------------------------
  34. function swin = optimal_synth_window(window, L)
  35. % Wejście
  36. % window - sygnał okna analizujace sygnał
  37. % L - ilość wspólnych próbek między dwoma kolejnymi oknami
  38. % Wyjście:
  39. % swin - optymalne okno syntezujace
  40.  
  41. %Wlen=length(window);
  42. % for n=1:Wlen;
  43. % swin(n)=window(n)/sum(window(n).^2);
  44.  
  45. % end
  46.  
  47. swin=1./window;
  48. swin=[swin(1:length(window)-L), zeros(1,L)];
  49.  
  50.  
  51. end
  52. ---------------------------------------
  53. fs = 1e3;
  54. dt = 1/fs;
  55.  
  56. t = 0 : dt : 1;
  57. y = sin(2*pi*50*t);% + sin(2*pi*40*t);
  58.  
  59. y = fm_1tone(t, 250, 100, 5);
  60.  
  61. FrameLen = 64;
  62. aW = hamming(FrameLen)';
  63.  
  64. L = 16;
  65. nperseg = 256;
  66.  
  67.  
  68. sW = optimal_synth_window(aW, L);
  69.  
  70. %sW = ones(1, FrameLen);
  71. Y = STFT(y, aW, L, nperseg);
  72. yy = iSTFT(Y, sW, L)(1:length(y));
  73.  
  74. reconstruction_error = abs( y - yy ).^2;
  75.  
  76. subplot(4,1,1)
  77. plot(y, 'k')
  78. xlim([0 length(y)]);
  79. title('Sygnal')
  80.  
  81. subplot(4,1,2)
  82. plot(real(yy), 'r')
  83. xlim([0 length(y)]);
  84. ylim([-1 1]);
  85. title('Sygnal zrekonstuowany')
  86.  
  87. subplot(4,1,3);
  88. plot(dB(reconstruction_error))
  89. xlim([0 length(y)]);
  90. title('Blad rekonstukcji')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement