selecting window of length 256 for every 200 samples out of 108000 samples and find DWT coefficients for each separate windowed samples.
5 views (last 30 days)
Show older comments
Hi! i am supposed to slide a window of length 256 on every 200 samples sequentially and then find DWT coefficients for each window. Like if i consider my window on 1-10th elements and calculate approximate and detail coefficients, then next i should consider 11-20th elements and perform the same till the last. here is my code i have done so far. but not getting properly how i am trying to get. Please, help?
clc;
data= importdata('215_5.txt');
x = data(:, 1);
y = data(:, 2);
plot(x, y, 'b-', 'LineWidth', 2);
N= length(y);
FreqS=360; %sampling frequency
nyqfreq=FreqS/2; %nyquist frequency
fft_signal= abs(fft(y));
figure(1); %plot single sided magnitude spectrum
x1=0:1/(N/2-1):1;
y1=fft_signal(1:N/2);
p1=line(x1,y1);
grid on;
ax1=gca; %current axis
axis([0 1 0 1]);
xlabel('Normalised frequency[\pi rads/sample]');
ylabel('magnitude');
fc=70;
fs=1000;
[b, a]= butter(4,fc/(fs/2));
H= freqz(b,a,N/2);
hold on;
x2=linspace(0,nyqfreq,100);
y2=abs(H);
ax1_pos = ax1.Position;
ax2 = axes('Position',ax1_pos,'XAxisLocation','top','YAxisLocation','right','Color','none');
ax2.XLabel.String = 'Frequency [Hz]';
title('Magnitude spectrum of signal and frequency response of filter');
x_filtered = filter(b,a,y);
hold off;
[Xa,Ya]= alignsignals(y,x_filtered);
%%wavelet decomposition
T=256; %window size
m=numel(x_filtered);
for j= 1:200;
for i=0:m-T;
z=j(1+i:T+i);
[c,l]= wavedec(z,5,'db6');
approx= appcoef(c,l,'db6');
[cD1,cD2,cD3,cD4,cD5]= detcoef(c,l,[1,2,3,4,5]);
end
end
%%plot coefficients
subplot(6,1,1)
plot(approx)
title('Approximation Coefficients')
subplot(6,1,2)
plot(cD5)
title('level 5 detail coefficients')
subplot(6,1,3)
plot(cD4)
title('level 4 detail coefficients')
subplot(6,1,4)
plot(cD3)
title('level 3 detail coefficients')
subplot(6,1,5)
plot(cD2)
title('level 2 detail coefficients')
subplot(6,1,6)
plot(cD1)
title('level 1 detail coefficients')
0 Comments
Answers (0)
See Also
Categories
Find more on Discrete Multiresolution Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!