New at Matlab: ERROR due to function saying invalid

14 visualizzazioni (ultimi 30 giorni)
Ray
Ray il 5 Dic 2016
Commentato: Steven Lord il 6 Dic 2016
So we are given an eeg signal. which i added to the matlab folder.
Instructions:to design a low-pass filter and to filter the EEG signal.This function will return an FIR filter with a length of n+1. The argument 'fc' is the normalized cutoff frequency with a value range from 0 to 1. 1 corresponds to half the sampling frequency (Fs/2). The sampling frequency, Fs, for the EEG signal, is 100 Hz. Once you designed the filter, compute the convolution of h and the EEG signal as the filtered signal and load the data
a). Let n = 30, design a low-pass filter with a cutoff frequency of 5 Hz. Use the Matlab built-in function freqz() to analyze the filter's frequency response. Plot the EEG signal before and after the filtering.
My code:
seperatley. Instructor gave us this code to use in class which i opened a new function and saved as lowpassfilter.m
function [ h ] = lowpassfilter( fc, n )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
wp = fc-0.05;
ws = fc+0.05;
f = [0 wp ws 1];
a =[1 1 0 0];
h = firpm(n, f, a);
end
in the command window:
function [h] = lowpassfilter('fc', 'n');
which gives me an error here
I still continued.
n=30;f = [0 wp ws 1];
a =[1 1 0 0];
h=lowpassfilter(n, f, a);
fs=100;
I am new to matlab this is the second time using it please help.

Risposte (1)

Steven Lord
Steven Lord il 5 Dic 2016
Don't use the function keyword when calling your function. You only use that keyword when defining a function and you can only define a function in a script file (if you're using release R2016b or later), a function file, or a class file. You cannot define a function like this in the Command Window at the MATLAB prompt (>>, K>>, EDU>>, etc.)
  2 Commenti
Rayhana Kabiri
Rayhana Kabiri il 5 Dic 2016
besides that am I on the right track.I am new at this and I have been reading matlab books to help me when do I exactly load eeg.mat in command mode is it after convolution
Steven Lord
Steven Lord il 6 Dic 2016
Look at the definition of the lowpassfilter function.
function [ h ] = lowpassfilter( fc, n )
This function is defined to return one output (the variable h calculated inside the function) and accept two input arguments. The data in the first argument with which you call lowpassfilter will be assigned to the variable fc inside the function and the data in the second input will be assigned to the variable n.
So there are at least two problems with how you're calling lowpassfilter.
n=30;
f = [0 wp ws 1];
a =[1 1 0 0];
h=lowpassfilter(n, f, a);
The first problem is that you're trying to call lowpassfilter with three input arguments but it's defined to accept at most two input arguments. That WILL cause an error.
The second problem is that you've defined lowpassfilter to accept input arguments fc and n but you're calling it with input arguments n and f. That suggests you've reversed the order, like you filled your car's gas tank with windshield-wiper fluid and your wiper fluid tank with gasoline. That's probably not going to work well.

Accedi per commentare.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by