Subscripted assignment dimension mismatch // Overlap Save Method

조회 수: 4 (최근 30일)
MatlabGirl
MatlabGirl 2014년 12월 8일
댓글: Guillaume 2014년 12월 8일
I don't know why this happens
The code works fine for L = 5 only however I need to be able to vary L without issues
here is my code
clc;
clear all;
close all;
2nd order filter
filter_2 = firceqrip(2,0.6,[0.05 0.03]);
% impulse response in time & freq domains (order 2)
[h_2 t_2]= impz(filter_2);
% We are given 4 different frequencies
freqs = [0.08, 0.2, 0.32, 0.4];
periods = 1./ freqs;
% Let the max value of t be 4 times the largest period
t_max = 4 * periods(1);
% Let us have 50 samples over the interval [0, t_max].
t = linspace(0, t_max, 50);
% The synthesized signal
signal = sin(2*pi*0.08*t) + sin(2*pi*0.2*t) + sin(2*pi*0.32*t) + sin(2*pi*0.4*t);
x = signal;
h = h_2;
L=5;
% % Code to plot X(n)
% subplot (2,2,1);
% stem(x);
% stem(x,'blue');
% xlabel ('n');
% ylabel ('Amplitude');
% title('X(n)');
%
% %Code to plot H(n)
% subplot (2,2,2);
% stem(h);
% stem(h,'black');
% xlabel ('n');
% ylabel ('Amplitude');
% title(' H(n)');
% Code to perform Convolution using Overlap Save Method
M=length(h);
lx=length(x);
r=rem(lx,L);
x1=[x zeros(1,L-r)];
nr=(length(x1))/L;
h1=[h' zeros(1,L-1)];
for k=1:nr
Ma(k,:)=x1(((k-1)*L+1):k*L)
if k==1
Ma1(k,:)=[zeros(1,M-1) Ma(k,:)];
else
Ma1(k,:)=[Ma(k-1,(L-M+2):L) Ma(k,:)];
end
Ma2(k,:)=ifft(fft(Ma1(k,:)).*fft(h1));
end
Ma3=Ma2(:,M:(L+M-1));
y1=Ma3';
y=y1(:)'
% Representation of the Convoled Signal
figure
subplot (313);
plot(y,'red');
xlabel ('n');
ylabel ('Amplitude');
title ('Convolved Signal, using 4 samples');
your help is appreicated
  댓글 수: 5
MatlabGirl
MatlabGirl 2014년 12월 8일
편집: MatlabGirl 2014년 12월 8일
It happens only if L is not equal to 5 Which is weird
Guillaume
Guillaume 2014년 12월 8일
I'll repeat what I asked: show us the whole error message (everything in red), particularly the bit that shows the line where the error occurs.
What are the values of M, L, lx, r when the error occurs?
None of the variable names in your code mean anything, so it's near impossible to follow what's going on. The only variable with a meaningful name, signal, gets immediately renamed to x unfortunately.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Digital Filter Design에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by