Subscripted assignment dimension mismatch // Overlap Save Method
显示 更早的评论
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 个评论
Guillaume
2014-12-8
Rather than letting us figure it out, can you post what the problem is. If an error message is displayed when you run your code, show us the whole error message (everything in red), particularly the bit that shows the line where the error occurs.
MatlabGirl
2014-12-8
MatlabGirl
2014-12-8
MatlabGirl
2014-12-8
编辑:MatlabGirl
2014-12-8
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 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Digital Filter Design 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!