How to deal with this error??

A model of the surface EMG signal is created by filtering a white gaussian noise, using a shaping filter H(f). this filter has low cut-off freq=60hz and high cut-off freq=120hz. this is my code but i don't know how to deal with Undefined function 'designfilt' for input arguments of type 'char'.
clear all;
subplot(322);
load nnoise.m;
plot(nnoise,'k');
% design shaping filter
bpFilt = designfilt('bandpassfir',...
'CutoffFrequency1',60,'CutoffFrequency2',120, ...
'SampleRate',2000);
subplot(323);
W = filter(bpFilt,nnoise);
plot(W,'k');title ('EMG');

2 Comments

Do you have the Signal Processing toolbox? If not then you will not have this function.
So what is the solution? how can i get it

Sign in to comment.

 Accepted Answer

The designfilt function was introduced in the R2014a version of the Signal Processing Toolbox.
If you have an earlier version of the Signal Processing Toolbox, this filter will work, since all the functions were introduced prior to R2006a:
Fs = 2000;
notch_frq = [50 60 120 130];
mags = [0 1 0];
devs = [0.05 0.01 0.05];
[n,Wn,beta,ftype] = kaiserord(notch_frq,mags,devs,Fs);
n = n + rem(n,2);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'scale');
figure(1)
freqz(hh, 1, 2^17, Fs)
Use the filtfilt function to do the actual filtering of your signal.
See the documentation on the various functions to understand how to use them.

13 Comments

thank you sir. i'm trying but also i have this message Error using filtfilt Not enough input arguments.
subplot(322);
load nnoise.m;
plot(nnoise,'k');
% using shaping filter
Fs = 2000;
notch_frq = [50 60 120 130];
mags = [0 1 0];
devs = [0.05 0.01 0.05];
[n,Wn,beta,ftype] = kaiserord(notch_frq,mags,devs,Fs);
n = n + rem(n,2);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'scale');
subplot(324);
W = filtfilt(hh,nnoise);
plot(W,'k');title ('EMG');
My pleasure.
The ‘hh’ returned by the fir1 function is the numerator of the filter transfer function. You need to supply the denominator, that for FIR filters is always equal to 1.
This will work:
W = filtfilt(hh, 1, nnoise);
thank you sir for your patience with me. for my case the shaping filter has a transfer function H(f). where fl= low cut-off freq and fh= high cut-off freq.
H(f)=(fh^4)*(f^2)/((f^2)+(fl^2))*((f^2)+(fh^2))^2;
so can i use W = filtfilt(hh, 1, nnoise);
also, when they ask to set the initial snr from -5 to 55 in step of 5db this formula is it correct snrin=(-5:5:55) how can i integrate the db
My code designs the filter you specified in your designfilt call. It simply uses lower-level functions.
Your ‘H(f)’ appears to design a continuous infinite impulse response (or IIR) filter. It looks like a Butterworth design, although I would have to know more. You would need to use the bilinear transform to convert a continuous filter to a discrete filter. (There are others, but the bilinear transform is the most reliable.)
I do not understand the additional requirements with respect to the SNR. If you want the filter to have that shape, you need to use the firls or firpm functions.
1. white gaussian noise is passed through shaping filter H(f)where H(f)=(fh^4)(f^2)/((f^2)+(fl^2))*((f^2)+(fh^2))^2*, fh and fl change the shape of the spectral function (the goal is create an emg model).
2. the new filtred signal (W)is multiplied by a factor A(this factor is in function of e, f and snr-in) this snr-in is from -5 to 55 in steps of 5db the formula of snr_in in my code is it correct?? because when i type snr-in=55 instead snr-in=(-5:5:55) i get acceptable result
3.noisy ecg = ecg + A*W (ecg is sampled at 360hz from physionet MIT db)
%ecg and noisy ecg clc;
clear all;
load m105a.m;
ecg=m105a;
subplot(3,2,1);
plot(ecg); title ('ECG');
xlabel('samples'); ylabel('magnitude');
subplot(322);
load nnoise.m;
plot(nnoise,'k');
% using shaping filter
Fs = 2000;
notch_frq = [50 60 120 130];
mags = [0 1 0];
devs = [0.05 0.01 0.05];
[n,Wn,beta,ftype] = kaiserord(notch_frq,mags,devs,Fs);
n = n + rem(n,2);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'scale');
subplot(323);
W = filtfilt(hh,1,nnoise);
plot(W,'k');title ('EMG');
% noisy ecg
snrin_db=(-5:5:55); %initial snr in db
N=length(ecg);
n=(0:N-1);
e = sum( ecg(1+n).^2 );
f = sum( W(1+n).^2 );
A=sqrt(e./(10.^(snrin_db/10))*f); %the factor A in function of e and f
subplot(324);
ecgnoisy = repmat(ecg(:), 1, length(A)) + repmat(W(:), 1, length(A)) .* repmat(A, numel(W), 1);
plot(ecgnoisy,'k');title('Noisy signal');
First, since ‘ecg is sampled at 360hz’ your sampling frequency for all your signal processing must be 360 Hz.
Second, your ‘H(f)’ filter does not appear to be coded correctly. In any event, I cannot get a magnitude plot for it that is remotely close to what you want it to do. The FIR filter I designed works correctly.
Third, I have no idea how to interpret 2. in your Comment. This is apparently taken from the ‘Methods’ section of a paper, and has no context for me. I cannot determine if the SNR calculation is correct.
If you get an acceptable result for one value of ‘snrin_db’*, you most likely need to use a loop to calculate all of them:
snrin_db=(-5:5:55); %initial snr in db
N=length(ecg);
n=(0:N-1);
e = sum( ecg(1+n).^2 );
f = sum( W(1+n).^2 );
for k1 = 1:length(snrin_db)
A = sqrt(e./(10.^(snrin_db(k1)/10))*f); %the factor A in function of e and f
subplot(324);
ecgnoisy{k1} = repmat(ecg(:), 1, length(A)) + repmat(W(:), 1, length(A)) .* repmat(A, numel(W), 1);
end
I created ‘ecgnoisy’ as a cell array because I do not know its dimensions. The loop should produce a cell array element for each value of ‘snrin_db’.
I cannot run your code, so this is a guess. You may have to experiment to get the result you want.
thank you so much
My pleasure.
good afternoon. i' m trying with this code ?how to deal with this error .i want linear filtering.(sorry i'm beginner) Error using filter Not enough input arguments.
the numerator order=1 and the denominator order=3
% using shaping filter fs=360; [numd,dend] = bilinear([568489.21 0],[1 5217.410 749444.9503 214315384.4],fs); subplot(323); W=filter([numd,dend],nnoise); plot(W,'k');title ('EMG');
% using shaping filter
fs=360;
[numd,dend] = bilinear([568489.21 0],[1 5217.410 749444.9503 214315384.4],fs);
subplot(323);
W=filter([numd,dend],nnoise);
plot(W,'k');title ('EMG');
If you want to plot the transfer function:
fs=360;
[numd,dend] = bilinear([568489.21 0],[1 5217.410 749444.9503 214315384.4],fs);
figure(1)
freqz(numd, dend, 2^17, fs)
I would use filtfilt rather than filter. It has a maximally-flat phase response, so there is no phase distortion, and it also handles the initial conditions on its own.
Call it as:
W = filtfilt(numd,dend,nnoise);
Do not use ‘[numd,dend]’ as a filter argument to any filter function. That concatenates the numerator and denominator polynomials into one vector, resulting the the ‘Not enough input arguments.’ error you are currently getting.
Mr. Strider I would like to thank you very much. you alerted me to important informations. I hope that everyone will benefit from these discussions, especially beginners.
2^17 is from where?
As always, it is my pleasure to help.
The ‘2^17’ is the length of the Fast Fourier Transform that freqz uses to compute the transfer function. I apologise for not explaining that earlier.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!