Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function x = iSTFT(X, W, L)
- % Wejście:
- % X - krótkoczasowa transforata Fouriera sygnału x
- % W - okno syntezujące
- % L - liczba próbek nachodzących na siebie
- % Wyjście:
- % x - rekonstrukcja sygnału z STFT
- # Lenght of the signal in samples
- x=zeros(1,L);
- # Lenght of the window in samples
- Wlen = size(X)(1);
- Wsiz=size(X)(2);
- for k=1:Wsiz;
- y=X(:,1);
- y=y.';
- y=ifft(y);
- z=y(1:length(W));
- length(z);
- z=z.*W;
- x(end-L+1:end)=x(end-L+1:end)+z(1:L);
- x=[x,z(L+1:end)];
- end
- x=[x,zeros(1,100)];
- end
- -------------------------------
- function swin = optimal_synth_window(window, L)
- % Wejście
- % window - sygnał okna analizujace sygnał
- % L - ilość wspólnych próbek między dwoma kolejnymi oknami
- % Wyjście:
- % swin - optymalne okno syntezujace
- %Wlen=length(window);
- % for n=1:Wlen;
- % swin(n)=window(n)/sum(window(n).^2);
- % end
- swin=1./window;
- swin=[swin(1:length(window)-L), zeros(1,L)];
- end
- ---------------------------------------
- fs = 1e3;
- dt = 1/fs;
- t = 0 : dt : 1;
- y = sin(2*pi*50*t);% + sin(2*pi*40*t);
- y = fm_1tone(t, 250, 100, 5);
- FrameLen = 64;
- aW = hamming(FrameLen)';
- L = 16;
- nperseg = 256;
- sW = optimal_synth_window(aW, L);
- %sW = ones(1, FrameLen);
- Y = STFT(y, aW, L, nperseg);
- yy = iSTFT(Y, sW, L)(1:length(y));
- reconstruction_error = abs( y - yy ).^2;
- subplot(4,1,1)
- plot(y, 'k')
- xlim([0 length(y)]);
- title('Sygnal')
- subplot(4,1,2)
- plot(real(yy), 'r')
- xlim([0 length(y)]);
- ylim([-1 1]);
- title('Sygnal zrekonstuowany')
- subplot(4,1,3);
- plot(dB(reconstruction_error))
- xlim([0 length(y)]);
- title('Blad rekonstukcji')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement