design filter , Hello everyone, I'm trying to run a script I've written that deals with signal modulation and frequency filtering. unfortunately, the software is crashing at runtime while its deal with the "bode", what can i do?

3 views (last 30 days)
Hello everyone, I'm trying to run a script I've written that deals with signal modulation and frequency filtering. unfortunately, the software is crashing at runtime while its deal with the "bode", what can i do?
clc
close all
clear all
m=1;
am=1.8;
fa=20; %400Hz
ta=1/fa;
t=0:ta/999:6*ta;
ym=am*sin(2*pi*fa*t);
figure(1)
subplot(3,1,1);
plot(t,ym)
title('Modulating signal')
ac=am/m;
fc=400000; %400KHz
% tc=1/fc;
% yc=ac*sin(2*pi*fc*t);
yc= am+ac*square(2*pi*fc*t);
subplot(3,1,2);
plot(t,yc);
grid on;
title('Carrier signal')
y=ac+(1+m*sin(2*pi*fa*t)).*square(2*pi*fc*t);
subplot(3,1,3);
plot(t,y);
title('am signal');
grid on
nfft=length(y);
nfft2=2^nextpow2(nfft);
ff=fft(y,nfft2);
figure(2)
plot(abs(ff))
Fs = length(nfft2);
xdft = fftshift(fft(y));
df = Fs/length(y);
freq = -Fs/2:df:Fs/2-df;
plot(freq,abs(xdft))
Fstop = 350;
Fpass = 400;
Astop = 65;
Apass = 0.5;
Fs = 1e3;
d = designfilt('highpassiir','StopbandFrequency',Fstop ,...
'PassbandFrequency',Fpass,'StopbandAttenuation',Astop, ...
'PassbandRipple',Apass,'SampleRate',Fs,'DesignMethod','butter');
figure(3)
fvtool(d);
[a,b]=tf(d);
filter=tf(a,b);
yfilter=y*filter;
figure(4)
bode(y);

Accepted Answer

Star Strider
Star Strider on 18 Nov 2019
The bode function is part of the Control System Toolbox (and friends). It takes a system object as an argument. Also, multiplying system objects is the same as connecting them in series, so ‘yfilter’ will not do what you want. If you want the Bode plot of a filter, use the freqz (or freqs) functions, instead. If you want to filter a signal with a Signal Processing Toolbox filter, use the filtfilt function to do the actual filtering.
Please do not name your variables filter or anything else that could overshadow a MATLAB function name.
Your code otherwise appears to be good, and produces a double-sideband-transmitted-carrier AM signal.
  2 Comments
Guni Basilian
Guni Basilian on 18 Nov 2019
thanks a lot! this is vwry helpfull. how can i menege to compain this freqz func in my function? do i need to multiply it like transfer function?
Star Strider
Star Strider on 18 Nov 2019
As always, my pleasure!
The freqz funciton will plot the Bode plot of your filter. Please do not multiply it by anything. If you want to use your filter to filter your signal, use the filtfilt function with it.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!