how to save spectrogram of signal as image ? i have given my code.

Illustration
murrugesan - 2021-12-10T11:39:32+00:00
Question: how to save spectrogram of signal as image ? i have given my code.

x=train_data(91,:,1); N = 1000; fs=250; t=(1:N)/fs; Fn=fs/2; Wp = [8 30]/Fn; % Passband Frequency (Normalised) Ws = [7.8 31]/Fn; % Stopband Frequency (Normalised) Rp = 1; % Passband Ripple (dB) Rs = 150; % Stopband Ripple (dB) [n,Ws] = cheb2ord(Wp,Ws,Rp,Rs); % Filter Order [z,p,k] = cheby2(n,Rs,Ws); % Filter Design [sosbp,gbp] = zp2sos(z,p,k); % Filter Signal filtered_signal = filtfilt(sosbp, gbp,x); Z1=filtered_signal; figure spectrogram(Z1,128,120,128,fs,'yaxis') title('SPECTROGRAM of MOTOR IMAGERY EEG SIGNAL CHANNEL C3')  

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

x=train_data(91,:,1); 
N=1000;
fs=250; 
t=(1:N)/fs; 
Fn=fs/2; 
Wp=[8 30]/Fn; % Passband Frequency (Normalised) 
Ws=[7.8 31]/Fn; %Stopband Frequency (Normalised) 
Rp=1; % Passband Ripple (dB) 
Rs=150; % Stopband Ripple (dB) 
[n,Ws]=cheb2ord(Wp,Ws,Rp,Rs); % Filter Order 
[z,p,k]=cheby2(n,Rs,Ws); % Filter Design 
[sosbp,gbp]=zp2sos(z,p,k); 
%Filter Signal 
filtered_signal=filtfilt(sosbp, gbp,x); 
Z1=filtered_signal; 
figure spectrogram(Z1,128,120,128,fs,'yaxis') 
title('SPECTROGRAM of MOTOR IMAGERY EEG SIGNAL CHANNEL C3');
saveas(gcf,'filename.webp'); %Use to display save as image

 


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!